suprimedev commited on
Commit
452f6ea
·
verified ·
1 Parent(s): 038e3a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pdf_to_text(pdf_file):
10
+ try:
11
+ # تبدیل صفحات PDF به تصاویر
12
+ images = convert_from_path(pdf_file.name)
13
+ full_text = ""
14
+ for img in images:
15
+ # OCR روی هر تصویر
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"خطا در پردازش PDF: {str(e)}"
21
+
22
+ # رابط Gradio
23
+ iface = gr.Interface(
24
+ fn=pdf_to_text,
25
+ inputs=gr.File(label="آپلود PDF"),
26
+ outputs=gr.Textbox(label="متن استخراج شده", lines=20),
27
+ title="Persian PDF OCR",
28
+ description="فایل PDF خود را آپلود کنید تا متن فارسی و انگلیسی آن استخراج شود."
29
+ )
30
+
31
+ iface.launch()