Update app.py
Browse files
app.py
CHANGED
@@ -33,13 +33,18 @@ def retrieve_passages(question, chunks, logs):
|
|
33 |
logs = log_message(f"[RAG] تم العثور على {len(passages)} مقطع مرتبط بالسؤال.", logs)
|
34 |
return passages, passages_text, logs
|
35 |
|
36 |
-
def
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
if not answer.strip():
|
39 |
logs = log_message("[RAG] ⚠️ لم يتم توليد إجابة. ربما النص طويل أو النموذج فشل.", logs)
|
40 |
else:
|
41 |
logs = log_message("[RAG] ✅ تم توليد الإجابة النهائية.", logs)
|
42 |
-
return
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
logs = gr.State("")
|
@@ -58,16 +63,18 @@ with gr.Blocks() as demo:
|
|
58 |
store_question_btn = gr.Button("📥 تخزين السؤال")
|
59 |
|
60 |
find_btn = gr.Button("🔍 بحث عن المقاطع المرتبطة")
|
61 |
-
|
|
|
62 |
|
63 |
passage_output = gr.Textbox(label="📄 المقاطع المرتبطة", lines=8)
|
64 |
summary_output = gr.Textbox(label="📌 الملخص المستخدم", lines=5)
|
65 |
answer_output = gr.Textbox(label="✅ الإجابة النهائية", lines=5)
|
66 |
logs_output = gr.Textbox(label="📜 سجل العمليات", lines=10, interactive=False)
|
67 |
|
68 |
-
upload_btn.click(upload_and_prepare, inputs=[files_input, logs], outputs=[chunks, logs_output, store_question_btn, find_btn,
|
69 |
store_question_btn.click(store_question, inputs=question_input, outputs=question_state)
|
70 |
find_btn.click(retrieve_passages, inputs=[question_state, chunks, logs], outputs=[retrieved_passages, passage_output, logs_output])
|
71 |
-
|
|
|
72 |
|
73 |
demo.launch()
|
|
|
33 |
logs = log_message(f"[RAG] تم العثور على {len(passages)} مقطع مرتبط بالسؤال.", logs)
|
34 |
return passages, passages_text, logs
|
35 |
|
36 |
+
def generate_summary_only(passages_text, logs):
|
37 |
+
summary = rag.summarize_text(passages_text)
|
38 |
+
logs = log_message("[RAG] تم توليد الملخص بنجاح.", logs)
|
39 |
+
return summary, logs
|
40 |
+
|
41 |
+
def generate_final_answer(question, summary_text, logs):
|
42 |
+
answer, _ = rag.generate_answer_from_passages(question, summary_text)
|
43 |
if not answer.strip():
|
44 |
logs = log_message("[RAG] ⚠️ لم يتم توليد إجابة. ربما النص طويل أو النموذج فشل.", logs)
|
45 |
else:
|
46 |
logs = log_message("[RAG] ✅ تم توليد الإجابة النهائية.", logs)
|
47 |
+
return answer, logs
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
logs = gr.State("")
|
|
|
63 |
store_question_btn = gr.Button("📥 تخزين السؤال")
|
64 |
|
65 |
find_btn = gr.Button("🔍 بحث عن المقاطع المرتبطة")
|
66 |
+
summarize_btn = gr.Button("📝 توليد الملخص")
|
67 |
+
answer_btn = gr.Button("✍️ توليد الإجابة النهائية")
|
68 |
|
69 |
passage_output = gr.Textbox(label="📄 المقاطع المرتبطة", lines=8)
|
70 |
summary_output = gr.Textbox(label="📌 الملخص المستخدم", lines=5)
|
71 |
answer_output = gr.Textbox(label="✅ الإجابة النهائية", lines=5)
|
72 |
logs_output = gr.Textbox(label="📜 سجل العمليات", lines=10, interactive=False)
|
73 |
|
74 |
+
upload_btn.click(upload_and_prepare, inputs=[files_input, logs], outputs=[chunks, logs_output, store_question_btn, find_btn, summarize_btn])
|
75 |
store_question_btn.click(store_question, inputs=question_input, outputs=question_state)
|
76 |
find_btn.click(retrieve_passages, inputs=[question_state, chunks, logs], outputs=[retrieved_passages, passage_output, logs_output])
|
77 |
+
summarize_btn.click(generate_summary_only, inputs=[passage_output, logs], outputs=[summary_output, logs_output])
|
78 |
+
answer_btn.click(generate_final_answer, inputs=[question_state, summary_output, logs], outputs=[answer_output, logs_output])
|
79 |
|
80 |
demo.launch()
|