First_orc_app / app.py
YI-X's picture
Update app.py
605e36e verified
Raw History Blame Contribute Delete
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()