Spaces:
Sleeping
Sleeping
Download app.py from YI-X/First_orc_app: direct link, hf CLI and curl.
- Browser
- Download file 756 Bytes
-
https://huggingface.co/spaces/YI-X/First_orc_app/resolve/main/app.py
- Command line
-
hf download hf://spaces/YI-X/First_orc_app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/YI-X/First_orc_app/resolve/main/app.py
756 Bytes
| import gradio as gr | |
| import pytesseract | |
| from PIL import Image | |
| def ocr_image(image): | |
| if image is None: | |
| return "请先上传一张图片。" | |
| try: | |
| text = pytesseract.image_to_string(image, lang="chi_sim+eng") | |
| text = text.strip() | |
| if not text: | |
| return "未识别到文字,请换一张更清晰的图片。" | |
| return text | |
| except Exception as e: | |
| return f"OCR 识别失败:{str(e)}" | |
| demo = gr.Interface( | |
| fn=ocr_image, | |
| inputs=gr.Image(type="pil", label="上传图片"), | |
| outputs=gr.Textbox(label="识别结果", lines=10), | |
| title="中文 OCR 识别器", | |
| description="上传图片,自动识别中文和英文文字。" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |