Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,29 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
with gr.Blocks() as demo:
|
| 4 |
+
with gr.Tab("Chat"):
|
| 5 |
+
chatbot = gr.Chatbot()
|
| 6 |
+
msg = gr.Textbox(label="Your message")
|
| 7 |
+
clear = gr.Button("Clear Chat")
|
| 8 |
+
|
| 9 |
+
def respond(message, history):
|
| 10 |
+
history = history + [(message, f"Echo: {message}")]
|
| 11 |
+
return "", history
|
| 12 |
+
|
| 13 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 14 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 15 |
+
|
| 16 |
+
with gr.Tab("History"):
|
| 17 |
+
history_box = gr.Textbox(label="Conversation History", lines=10)
|
| 18 |
+
|
| 19 |
+
def show_history(chat_history):
|
| 20 |
+
# Convert history to readable text
|
| 21 |
+
return "\n".join([f"User: {u}\nBot: {b}" for u, b in chat_history if u])
|
| 22 |
+
|
| 23 |
+
chatbot.change(show_history, chatbot, history_box)
|
| 24 |
+
|
| 25 |
+
with gr.Tab("Settings"):
|
| 26 |
+
theme_choice = gr.Radio(["Light", "Dark"], label="Theme")
|
| 27 |
+
lang_choice = gr.Dropdown(["English", "Spanish", "French"], label="Language")
|
| 28 |
+
|
| 29 |
+
demo.launch()
|