Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,12 +23,13 @@ def chatbot(messages):
|
|
23 |
)
|
24 |
|
25 |
response = chat_completion.choices[0].message.content
|
26 |
-
messages.append(
|
|
|
27 |
return messages
|
28 |
except Exception as e:
|
29 |
# Capture the specific error message for debugging
|
30 |
print(f"Error Details: {str(e)}") # Print error details in the console (logs)
|
31 |
-
messages.append(
|
32 |
return messages
|
33 |
|
34 |
# Function to reset the chat
|
@@ -47,7 +48,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
47 |
)
|
48 |
|
49 |
with gr.Row():
|
50 |
-
chatbot_ui = gr.Chatbot(label="Chat Interface"
|
51 |
|
52 |
with gr.Row():
|
53 |
user_input = gr.Textbox(
|
@@ -60,14 +61,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
60 |
clear_button = gr.Button("Clear Chat")
|
61 |
|
62 |
with gr.Row():
|
63 |
-
|
64 |
-
examples=["Hello!", "Tell me a joke.", "What's the weather like?"],
|
65 |
-
inputs=user_input,
|
66 |
-
)
|
67 |
-
|
68 |
-
# Link components to functions
|
69 |
-
send_button.click(chatbot, inputs=[chatbot_ui], outputs=chatbot_ui)
|
70 |
-
clear_button.click(reset_chat, inputs=[], outputs=chatbot_ui)
|
71 |
-
|
72 |
-
# Launch the Gradio app
|
73 |
-
iface.launch()
|
|
|
23 |
)
|
24 |
|
25 |
response = chat_completion.choices[0].message.content
|
26 |
+
messages.append({"role": "user", "content": user_input})
|
27 |
+
messages.append({"role": "assistant", "content": response}) # Appending bot response
|
28 |
return messages
|
29 |
except Exception as e:
|
30 |
# Capture the specific error message for debugging
|
31 |
print(f"Error Details: {str(e)}") # Print error details in the console (logs)
|
32 |
+
messages.append({"role": "system", "content": f"An error occurred: {str(e)}"}) # Show the error in chat
|
33 |
return messages
|
34 |
|
35 |
# Function to reset the chat
|
|
|
48 |
)
|
49 |
|
50 |
with gr.Row():
|
51 |
+
chatbot_ui = gr.Chatbot(label="Chat Interface", height=400)
|
52 |
|
53 |
with gr.Row():
|
54 |
user_input = gr.Textbox(
|
|
|
61 |
clear_button = gr.Button("Clear Chat")
|
62 |
|
63 |
with gr.Row():
|
64 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|