OCRscanFix / app.py
mohamed12ahmed's picture
Update app.py
6cca844 verified
import gradio as gr
import cv2
import os
from scan import DocScanner
OUTPUT_DIR = "output"
os.makedirs(OUTPUT_DIR, exist_ok=True)
# دالة الفحص
def scan_document(image, interactive=False):
scanner = DocScanner(interactive)
# نحفظ الصورة مؤقتًا
temp_path = "temp_input.jpg"
cv2.imwrite(temp_path, cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
# نفذ عملية المسح
scanner.scan(temp_path)
# نحصل على اسم الملف الناتج
output_path = os.path.join(OUTPUT_DIR, os.path.basename(temp_path))
# نقرأ النتيجة لو الملف اتولد
if os.path.exists(output_path):
scanned = cv2.imread(output_path)
scanned = cv2.cvtColor(scanned, cv2.COLOR_BGR2RGB)
return scanned
else:
return None
# واجهة Gradio
app = gr.Interface(
fn=scan_document,
inputs=[
gr.Image(label="📸 ارفع الصورة", type="numpy"),
gr.Checkbox(label="تفعيل الوضع التفاعلي (تعديل الزوايا يدويًا)", value=False)
],
outputs=gr.Image(label="📄 النتيجة بعد المسح"),
title="AI Document Scanner",
description="برنامج لمسح المستندات الورقية والمكتوبة بخط اليد (عربي/إنجليزي) باستخدام OpenCV + LSD + PyImageSearch",
examples=[["sample_images/desk.JPG", False]],
)
if __name__ == "__main__":
app.launch(server_name="0.0.0.0", server_port=7860)