Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,10 +16,16 @@ def process_raw_ocr(file_objs, img_input, current_text):
|
|
| 16 |
if file_objs:
|
| 17 |
for file in file_objs:
|
| 18 |
ext = os.path.splitext(file.name)[1].lower()
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
doc = fitz.open(file.name)
|
| 21 |
for page in doc:
|
| 22 |
-
#
|
| 23 |
pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
|
| 24 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 25 |
img.save("temp.png")
|
|
@@ -40,7 +46,7 @@ def process_raw_ocr(file_objs, img_input, current_text):
|
|
| 40 |
res = reader.readtext("temp_c.png", detail=0, paragraph=True)
|
| 41 |
text_output += "\n".join(res) + "\n"
|
| 42 |
|
| 43 |
-
# تنظيف الملفات
|
| 44 |
for f in ["temp.png", "temp_c.png"]:
|
| 45 |
if os.path.exists(f): os.remove(f)
|
| 46 |
|
|
@@ -58,10 +64,4 @@ with gr.Blocks() as demo:
|
|
| 58 |
|
| 59 |
btn.click(process_raw_ocr, inputs=[f_in, i_in, out], outputs=[out])
|
| 60 |
|
| 61 |
-
demo.launch()
|
| 62 |
-
الملف السابق كود gradio
|
| 63 |
-
easyocr
|
| 64 |
-
pymupdf
|
| 65 |
-
python-docx
|
| 66 |
-
numpy
|
| 67 |
-
pillow
|
|
|
|
| 16 |
if file_objs:
|
| 17 |
for file in file_objs:
|
| 18 |
ext = os.path.splitext(file.name)[1].lower()
|
| 19 |
+
|
| 20 |
+
# إضافة دعم الصور (JPG) فقط
|
| 21 |
+
if ext in [".jpg", ".jpeg", ".png"]:
|
| 22 |
+
res = reader.readtext(file.name, detail=0, paragraph=True)
|
| 23 |
+
text_output += "\n".join(res) + "\n"
|
| 24 |
+
|
| 25 |
+
elif ext == ".pdf":
|
| 26 |
doc = fitz.open(file.name)
|
| 27 |
for page in doc:
|
| 28 |
+
# الدقة الأصلية (Matrix 2)
|
| 29 |
pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
|
| 30 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 31 |
img.save("temp.png")
|
|
|
|
| 46 |
res = reader.readtext("temp_c.png", detail=0, paragraph=True)
|
| 47 |
text_output += "\n".join(res) + "\n"
|
| 48 |
|
| 49 |
+
# تنظيف الملفات المؤقتة
|
| 50 |
for f in ["temp.png", "temp_c.png"]:
|
| 51 |
if os.path.exists(f): os.remove(f)
|
| 52 |
|
|
|
|
| 64 |
|
| 65 |
btn.click(process_raw_ocr, inputs=[f_in, i_in, out], outputs=[out])
|
| 66 |
|
| 67 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|