Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,17 +64,25 @@ def generate_response(user_input, chat_history):
|
|
| 64 |
chat_history.append({"role": "assistant", "content": f"Error after {retry_attempts} attempts: {str(e)}"})
|
| 65 |
return chat_history
|
| 66 |
|
| 67 |
-
# Build the Gradio interface using Chatbot
|
| 68 |
with gr.Blocks() as iface:
|
| 69 |
chatbot = gr.Chatbot() # Create a Chatbot component
|
| 70 |
user_input = gr.Textbox(label="Talk to AI", placeholder="Enter your message here...", lines=2)
|
|
|
|
| 71 |
chat_history_state = gr.State([]) # State input for chat history
|
| 72 |
|
| 73 |
# Define the layout and components
|
| 74 |
-
|
| 75 |
fn=generate_response,
|
| 76 |
inputs=[user_input, chat_history_state],
|
| 77 |
outputs=chatbot
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
iface.launch()
|
|
|
|
| 64 |
chat_history.append({"role": "assistant", "content": f"Error after {retry_attempts} attempts: {str(e)}"})
|
| 65 |
return chat_history
|
| 66 |
|
| 67 |
+
# Build the Gradio interface using Chatbot and Button
|
| 68 |
with gr.Blocks() as iface:
|
| 69 |
chatbot = gr.Chatbot() # Create a Chatbot component
|
| 70 |
user_input = gr.Textbox(label="Talk to AI", placeholder="Enter your message here...", lines=2)
|
| 71 |
+
submit_button = gr.Button("Send") # Create a button to submit messages
|
| 72 |
chat_history_state = gr.State([]) # State input for chat history
|
| 73 |
|
| 74 |
# Define the layout and components
|
| 75 |
+
submit_button.click(
|
| 76 |
fn=generate_response,
|
| 77 |
inputs=[user_input, chat_history_state],
|
| 78 |
outputs=chatbot
|
| 79 |
)
|
| 80 |
|
| 81 |
+
# Optional: Add an event to clear the input after submission
|
| 82 |
+
user_input.submit(
|
| 83 |
+
fn=lambda x: "", # Clear input box
|
| 84 |
+
inputs=[user_input],
|
| 85 |
+
outputs=[user_input]
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
iface.launch()
|