Spaces:
Sleeping
Sleeping
Meshal Falah
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,6 +52,10 @@ def generate_response(user_input: str, context_summary: str = "") -> str:
|
|
| 52 |
|
| 53 |
# تعريف chat_history كمخزن داخلي
|
| 54 |
chat_history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def gradio_chat(user_input):
|
| 57 |
global chat_history # نُشير إلى المتغيّر الخارجي
|
|
@@ -87,12 +91,15 @@ with gr.Blocks() as demo:
|
|
| 87 |
|
| 88 |
chatbot = gr.Chatbot()
|
| 89 |
msg = gr.Textbox(placeholder="Type your message and press Enter...")
|
| 90 |
-
|
|
|
|
| 91 |
# عند الإرسال، تُنفذ الدالة وتُحدث الـchatbot
|
| 92 |
msg.submit(fn=gradio_chat, inputs=msg, outputs=chatbot, scroll_to_output=True)
|
| 93 |
-
|
| 94 |
# بعد الإرسال، يتم مسح الـTextbox تلقائيًا
|
| 95 |
msg.submit(lambda: "", None, msg)
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# تشغيل الواجهة
|
| 98 |
demo.launch()
|
|
|
|
| 52 |
|
| 53 |
# تعريف chat_history كمخزن داخلي
|
| 54 |
chat_history = []
|
| 55 |
+
def reset_chat():
|
| 56 |
+
global chat_history
|
| 57 |
+
chat_history.clear()
|
| 58 |
+
return []
|
| 59 |
|
| 60 |
def gradio_chat(user_input):
|
| 61 |
global chat_history # نُشير إلى المتغيّر الخارجي
|
|
|
|
| 91 |
|
| 92 |
chatbot = gr.Chatbot()
|
| 93 |
msg = gr.Textbox(placeholder="Type your message and press Enter...")
|
| 94 |
+
clear_btn = gr.Button("🔄 Reset Chat")
|
| 95 |
+
|
| 96 |
# عند الإرسال، تُنفذ الدالة وتُحدث الـchatbot
|
| 97 |
msg.submit(fn=gradio_chat, inputs=msg, outputs=chatbot, scroll_to_output=True)
|
|
|
|
| 98 |
# بعد الإرسال، يتم مسح الـTextbox تلقائيًا
|
| 99 |
msg.submit(lambda: "", None, msg)
|
| 100 |
+
|
| 101 |
+
# زر إعادة تعيين المحادثة
|
| 102 |
+
clear_btn.click(fn=reset_chat, inputs=None, outputs=chatbot)
|
| 103 |
|
| 104 |
# تشغيل الواجهة
|
| 105 |
demo.launch()
|