Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
import easyocr
|
3 |
-
from pdf2image import convert_from_path
|
4 |
from PIL import Image
|
5 |
|
6 |
# مدل OCR فارسی و انگلیسی
|
7 |
reader = easyocr.Reader(['fa', 'en'])
|
8 |
|
9 |
-
def
|
10 |
try:
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
text = reader.readtext(img, detail=0)
|
17 |
-
full_text += "\n".join(text) + "\n\n"
|
18 |
-
return full_text
|
19 |
except Exception as e:
|
20 |
-
return f"خطا در پردازش
|
21 |
|
22 |
# رابط Gradio
|
23 |
iface = gr.Interface(
|
24 |
-
fn=
|
25 |
-
inputs=gr.File(label="آپلود
|
26 |
outputs=gr.Textbox(label="متن استخراج شده", lines=20),
|
27 |
-
title="Persian
|
28 |
-
description="
|
29 |
)
|
30 |
|
31 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import easyocr
|
|
|
3 |
from PIL import Image
|
4 |
|
5 |
# مدل OCR فارسی و انگلیسی
|
6 |
reader = easyocr.Reader(['fa', 'en'])
|
7 |
|
8 |
+
def image_to_text(image_file):
|
9 |
try:
|
10 |
+
# باز کردن تصویر
|
11 |
+
img = Image.open(image_file.name)
|
12 |
+
# OCR روی تصویر
|
13 |
+
text = reader.readtext(img, detail=0)
|
14 |
+
return "\n".join(text)
|
|
|
|
|
|
|
15 |
except Exception as e:
|
16 |
+
return f"خطا در پردازش تصویر: {str(e)}"
|
17 |
|
18 |
# رابط Gradio
|
19 |
iface = gr.Interface(
|
20 |
+
fn=image_to_text,
|
21 |
+
inputs=gr.File(label="آپلود تصویر (JPG/PNG)"),
|
22 |
outputs=gr.Textbox(label="متن استخراج شده", lines=20),
|
23 |
+
title="Persian Image OCR",
|
24 |
+
description="یک تصویر فارسی یا انگلیسی آپلود کنید تا متن آن استخراج شود."
|
25 |
)
|
26 |
|
27 |
iface.launch()
|