Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,12 @@ import fitz # PyMuPDF
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
# تحميل
|
6 |
qa = pipeline("question-answering", model="aubmindlab/bert-base-arabertv2")
|
7 |
|
8 |
def answer_pdf(file, question):
|
9 |
-
|
|
|
10 |
text = ""
|
11 |
for page in doc:
|
12 |
text += page.get_text()
|
@@ -14,16 +15,18 @@ def answer_pdf(file, question):
|
|
14 |
if not question.strip():
|
15 |
return "يرجى كتابة سؤال لبدء التحليل."
|
16 |
|
17 |
-
|
|
|
18 |
return result["answer"]
|
19 |
|
|
|
20 |
gr.Interface(
|
21 |
fn=answer_pdf,
|
22 |
inputs=[
|
23 |
-
gr.File(label="ملف PDF"),
|
24 |
-
gr.Textbox(label="
|
25 |
],
|
26 |
-
outputs=gr.Textbox(label="الإجابة"),
|
27 |
-
title="
|
28 |
-
description="
|
29 |
-
).launch()
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# تحميل نموذج لغة عربية للإجابة على الأسئلة
|
6 |
qa = pipeline("question-answering", model="aubmindlab/bert-base-arabertv2")
|
7 |
|
8 |
def answer_pdf(file, question):
|
9 |
+
# فتح ملف PDF من المسار المؤقت
|
10 |
+
doc = fitz.open(file.name)
|
11 |
text = ""
|
12 |
for page in doc:
|
13 |
text += page.get_text()
|
|
|
15 |
if not question.strip():
|
16 |
return "يرجى كتابة سؤال لبدء التحليل."
|
17 |
|
18 |
+
# الإجابة على السؤال باستخدام النص المستخرج
|
19 |
+
result = qa(question=question, context=text[:4000]) # تقصير النص لتجنب تجاوز الحد
|
20 |
return result["answer"]
|
21 |
|
22 |
+
# واجهة المستخدم عبر Gradio
|
23 |
gr.Interface(
|
24 |
fn=answer_pdf,
|
25 |
inputs=[
|
26 |
+
gr.File(label="📄 ارفع ملف PDF"),
|
27 |
+
gr.Textbox(label="❓ سؤالك", placeholder="مثال: ما الأدوات التي تعالج الصور؟")
|
28 |
],
|
29 |
+
outputs=gr.Textbox(label="🤖 الإجابة"),
|
30 |
+
title="📚 قارئ ملفات PDF الذكي بالعربية",
|
31 |
+
description="استخدم هذه الأداة لتحليل ملفات PDF المكتوبة بالعربية وطرح أسئلتك عليها",
|
32 |
+
).launch(share=True)
|