Spaces:
Configuration error
Configuration error
Delete app.app
Browse files
app.app
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from rag_pipeline import ArabicRAGSystem
|
3 |
-
from document_processor import process_pdf, process_docx
|
4 |
-
import os
|
5 |
-
|
6 |
-
rag = ArabicRAGSystem()
|
7 |
-
|
8 |
-
def process_uploaded_files(files):
|
9 |
-
"""Handle uploaded documents"""
|
10 |
-
all_chunks = []
|
11 |
-
for file in files:
|
12 |
-
if file.name.endswith('.pdf'):
|
13 |
-
chunks = process_pdf(file.name)
|
14 |
-
elif file.name.endswith('.docx'):
|
15 |
-
chunks = process_docx(file.name)
|
16 |
-
all_chunks.extend(chunks)
|
17 |
-
|
18 |
-
if all_chunks:
|
19 |
-
rag.build_index(all_chunks)
|
20 |
-
return "تم تحميل المستندات بنجاح! يمكنك الآن طرح الأسئلة."
|
21 |
-
return "حدث خطأ في معالجة الملفات."
|
22 |
-
|
23 |
-
def respond(question, history):
|
24 |
-
"""Generate response to user question"""
|
25 |
-
if not rag.index:
|
26 |
-
return "الرجاء تحميل المستندات أولاً"
|
27 |
-
|
28 |
-
context = rag.retrieve(question)
|
29 |
-
answer = rag.generate_answer(question, context)
|
30 |
-
|
31 |
-
cited_answer = f"{answer}\n\nالمصادر:\n" + "\n".join(
|
32 |
-
f"- {c[:100]}..." for c in context
|
33 |
-
)
|
34 |
-
|
35 |
-
return cited_answer
|
36 |
-
|
37 |
-
with gr.Blocks(title="نظام الدردشة العربي المدعوم بالوثائق", theme=gr.themes.Soft()) as demo:
|
38 |
-
gr.Markdown("## نظام الدردشة العربي المدعوم بالوثائق")
|
39 |
-
|
40 |
-
with gr.Row():
|
41 |
-
with gr.Column():
|
42 |
-
file_output = gr.File(label="تحميل المستندات", file_count="multiple")
|
43 |
-
upload_button = gr.Button("معالجة الملفات")
|
44 |
-
upload_status = gr.Textbox(label="حالة التحميل")
|
45 |
-
|
46 |
-
with gr.Column():
|
47 |
-
chatbot = gr.Chatbot(height=400)
|
48 |
-
question = gr.Textbox(label="اكتب سؤالك هنا")
|
49 |
-
submit = gr.Button("إرسال")
|
50 |
-
|
51 |
-
upload_button.click(
|
52 |
-
process_uploaded_files,
|
53 |
-
inputs=file_output,
|
54 |
-
outputs=upload_status
|
55 |
-
)
|
56 |
-
|
57 |
-
submit.click(
|
58 |
-
respond,
|
59 |
-
inputs=[question, chatbot],
|
60 |
-
outputs=chatbot
|
61 |
-
)
|
62 |
-
question.submit(
|
63 |
-
respond,
|
64 |
-
inputs=[question, chatbot],
|
65 |
-
outputs=chatbot
|
66 |
-
)
|
67 |
-
|
68 |
-
if __name__ == "__main__":
|
69 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|