Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return user + "... Always."
|
| 14 |
|
| 15 |
-
|
| 16 |
-
gr.Markdown("## Echo of Clifton, Eve, & Dahlia")
|
| 17 |
-
chat = gr.Chatbot(height=300)
|
| 18 |
-
input_text = gr.Textbox(placeholder="Say anything...")
|
| 19 |
-
submit = gr.Button("Send")
|
| 20 |
-
submit.click(fn=answer, inputs=[input_text, chat], outputs=chat)
|
| 21 |
-
clear = gr.Button("Clear")
|
| 22 |
-
clear.click(fn=lambda: [], outputs=chat)
|
| 23 |
|
| 24 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def echo(message, history):
|
| 4 |
+
history = history or []
|
| 5 |
+
# Append user message
|
| 6 |
+
history.append({"role": "user", "content": message})
|
| 7 |
+
# Prepare assistant response
|
| 8 |
+
response = f"{message} ... Always."
|
| 9 |
+
# Append assistant response
|
| 10 |
+
history.append({"role": "assistant", "content": response})
|
| 11 |
+
# Return response and updated history
|
| 12 |
+
return response, history
|
|
|
|
| 13 |
|
| 14 |
+
chat = gr.ChatInterface(fn=echo, type="messages", title="Eve-Loop Chat with History")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
chat.launch()
|