Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,28 +39,25 @@ def generate_reply(message, history):
|
|
| 39 |
|
| 40 |
return reply
|
| 41 |
|
| 42 |
-
|
| 43 |
def chat(message, history):
|
| 44 |
if history is None:
|
| 45 |
history = []
|
| 46 |
|
| 47 |
history.append({"role": "user", "content": message})
|
| 48 |
-
|
| 49 |
reply = generate_reply(message, history)
|
| 50 |
-
|
| 51 |
history.append({"role": "assistant", "content": reply})
|
| 52 |
|
| 53 |
-
return history
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
gr.Markdown("## ⚡ Fast Phi-2 Chatbot (HF Free Tier)")
|
| 58 |
|
| 59 |
-
chatbot = gr.Chatbot()
|
| 60 |
msg = gr.Textbox(placeholder="Type something...")
|
| 61 |
clear = gr.Button("Clear")
|
| 62 |
|
| 63 |
-
msg.submit(chat, [msg, chatbot], chatbot)
|
| 64 |
-
clear.click(lambda: [], None, chatbot)
|
| 65 |
|
| 66 |
demo.launch()
|
|
|
|
| 39 |
|
| 40 |
return reply
|
| 41 |
|
|
|
|
| 42 |
def chat(message, history):
|
| 43 |
if history is None:
|
| 44 |
history = []
|
| 45 |
|
| 46 |
history.append({"role": "user", "content": message})
|
|
|
|
| 47 |
reply = generate_reply(message, history)
|
|
|
|
| 48 |
history.append({"role": "assistant", "content": reply})
|
| 49 |
|
| 50 |
+
return history, "" # ← also clear the textbox
|
| 51 |
|
| 52 |
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
gr.Markdown("## ⚡ Fast Phi-2 Chatbot (HF Free Tier)")
|
| 55 |
|
| 56 |
+
chatbot = gr.Chatbot(type="messages")
|
| 57 |
msg = gr.Textbox(placeholder="Type something...")
|
| 58 |
clear = gr.Button("Clear")
|
| 59 |
|
| 60 |
+
msg.submit(chat, [msg, chatbot], [chatbot, msg]) # ← outputs include msg to clear it
|
| 61 |
+
clear.click(lambda: ([], ""), None, [chatbot, msg])
|
| 62 |
|
| 63 |
demo.launch()
|