Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,6 +103,7 @@ def get_or_create_embeddings(
|
|
| 103 |
documents: List[Document],
|
| 104 |
save_path: str = "embeddings",
|
| 105 |
model_name: str = "intfloat/multilingual-e5-large"
|
|
|
|
| 106 |
) -> FAISS:
|
| 107 |
"""
|
| 108 |
Create new embeddings every time (skip loading saved ones)
|
|
@@ -169,17 +170,14 @@ def setup_chains(vectorstore: FAISS):
|
|
| 169 |
# 4. Question processing function
|
| 170 |
def process_question(question: str, rephrase_chain, qa_chain, chat_history: list) -> tuple:
|
| 171 |
"""معالجة السؤال وإرجاع الإجابة بالتنسيق الجديد"""
|
| 172 |
-
|
| 173 |
rewritten = rephrase_chain.invoke({"question": question})
|
| 174 |
fusha_question = rewritten.content.strip()
|
| 175 |
|
| 176 |
-
# الحصول على الإجابة
|
| 177 |
result = qa_chain.invoke(fusha_question)
|
| 178 |
answer = result["result"]
|
| 179 |
|
| 180 |
-
|
| 181 |
-
chat_history.append({"role": "user", "content": question}) # ← التنسيق الجديد
|
| 182 |
-
chat_history.append({"role": "assistant", "content": answer}) # ← التنسيق الجديد
|
| 183 |
|
| 184 |
return "", chat_history
|
| 185 |
# 5. Gradio interface
|
|
@@ -191,7 +189,7 @@ def create_gradio_interface(rephrase_chain: LLMChain, qa_chain: RetrievalQA) ->
|
|
| 191 |
gr.Markdown("## نظام المعلومات التأمينية الشاملة")
|
| 192 |
gr.Markdown("اسأل عن أي معلومات في وثائق التأمين")
|
| 193 |
|
| 194 |
-
chatbot = gr.Chatbot(label="المحادثة", height=500,
|
| 195 |
question_box = gr.Textbox(label="اكتب سؤالك هنا", placeholder="مثال: ما هي شروط تغيير وحدة الرعاية؟")
|
| 196 |
|
| 197 |
with gr.Row():
|
|
|
|
| 103 |
documents: List[Document],
|
| 104 |
save_path: str = "embeddings",
|
| 105 |
model_name: str = "intfloat/multilingual-e5-large"
|
| 106 |
+
|
| 107 |
) -> FAISS:
|
| 108 |
"""
|
| 109 |
Create new embeddings every time (skip loading saved ones)
|
|
|
|
| 170 |
# 4. Question processing function
|
| 171 |
def process_question(question: str, rephrase_chain, qa_chain, chat_history: list) -> tuple:
|
| 172 |
"""معالجة السؤال وإرجاع الإجابة بالتنسيق الجديد"""
|
| 173 |
+
|
| 174 |
rewritten = rephrase_chain.invoke({"question": question})
|
| 175 |
fusha_question = rewritten.content.strip()
|
| 176 |
|
|
|
|
| 177 |
result = qa_chain.invoke(fusha_question)
|
| 178 |
answer = result["result"]
|
| 179 |
|
| 180 |
+
chat_history.append((question, answer))
|
|
|
|
|
|
|
| 181 |
|
| 182 |
return "", chat_history
|
| 183 |
# 5. Gradio interface
|
|
|
|
| 189 |
gr.Markdown("## نظام المعلومات التأمينية الشاملة")
|
| 190 |
gr.Markdown("اسأل عن أي معلومات في وثائق التأمين")
|
| 191 |
|
| 192 |
+
chatbot = gr.Chatbot(label="المحادثة", height=500, type="tuples" )
|
| 193 |
question_box = gr.Textbox(label="اكتب سؤالك هنا", placeholder="مثال: ما هي شروط تغيير وحدة الرعاية؟")
|
| 194 |
|
| 195 |
with gr.Row():
|