Bhaskar2611 commited on
Commit
5f98408
·
verified ·
1 Parent(s): 00fbdf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -36,13 +36,35 @@ def respond(message, history: list[tuple[str, str]]):
36
  response += token
37
  yield response
38
 
39
- # Create the Gradio ChatInterface with Retry, Undo, and Clear buttons
40
- demo = gr.ChatInterface(
41
- fn=respond, # Function to handle chat responses
42
- retry_btn="Retry", # Add a Retry button
43
- undo_btn="Undo", # Add an Undo button
44
- clear_btn="Clear", # Add a Clear button
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__":