pdftotextz / app.py
suprimedev's picture
Update app.py
4d2d695 verified
raw
history blame contribute delete
828 Bytes
import gradio as gr
import easyocr
from PIL import Image
# مدل OCR فارسی و انگلیسی
reader = easyocr.Reader(['fa', 'en'])
def image_to_text(image_file):
try:
# باز کردن تصویر
img = Image.open(image_file.name)
# OCR روی تصویر
text = reader.readtext(img, detail=0)
return "\n".join(text)
except Exception as e:
return f"خطا در پردازش تصویر: {str(e)}"
# رابط Gradio
iface = gr.Interface(
fn=image_to_text,
inputs=gr.File(label="آپلود تصویر (JPG/PNG)"),
outputs=gr.Textbox(label="متن استخراج شده", lines=20),
title="Persian Image OCR",
description="یک تصویر فارسی یا انگلیسی آپلود کنید تا متن آن استخراج شود."
)
iface.launch()