Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,35 @@ def respond(message, history: list[tuple[str, str]]):
|
|
36 |
response += token
|
37 |
yield response
|
38 |
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Launch the Gradio app
|
48 |
if __name__ == "__main__":
|
|
|
36 |
response += token
|
37 |
yield response
|
38 |
|
39 |
+
# Custom button actions
|
40 |
+
def retry_last_message(history):
|
41 |
+
if history:
|
42 |
+
return history[:-1] # Remove the last assistant response
|
43 |
+
return history
|
44 |
+
|
45 |
+
def undo_last_interaction(history):
|
46 |
+
if history:
|
47 |
+
return history[:-1] # Remove the last user-assistant interaction
|
48 |
+
return history
|
49 |
+
|
50 |
+
def clear_chat(history):
|
51 |
+
return [] # Clear the entire chat history
|
52 |
+
|
53 |
+
# Create the Gradio ChatInterface with custom buttons
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
chatbot = gr.Chatbot(label="Chat with DeepSeek-R1")
|
56 |
+
msg = gr.Textbox(label="Your Message")
|
57 |
+
clear = gr.Button("Clear")
|
58 |
+
undo = gr.Button("Undo")
|
59 |
+
retry = gr.Button("Retry")
|
60 |
+
|
61 |
+
# Define button actions
|
62 |
+
clear.click(clear_chat, chatbot, chatbot)
|
63 |
+
undo.click(undo_last_interaction, chatbot, chatbot)
|
64 |
+
retry.click(retry_last_message, chatbot, chatbot)
|
65 |
+
|
66 |
+
# Handle user input and chatbot responses
|
67 |
+
msg.submit(respond, [msg, chatbot], chatbot)
|
68 |
|
69 |
# Launch the Gradio app
|
70 |
if __name__ == "__main__":
|