Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,10 +13,13 @@ system_instructions = (
|
|
13 |
)
|
14 |
|
15 |
# Function to handle the chatbot interaction
|
16 |
-
def chat(user_input, history):
|
17 |
global context
|
|
|
|
|
|
|
18 |
if user_input.lower() == "exit":
|
19 |
-
return history + [
|
20 |
|
21 |
# Construct the modified input including system instructions and context
|
22 |
modified_input = (
|
@@ -34,13 +37,19 @@ def chat(user_input, history):
|
|
34 |
# Update the context with the latest conversation
|
35 |
context += f"User: {user_input}\nAI: {ai_response}\n"
|
36 |
|
37 |
-
# Append the
|
38 |
-
history.append(
|
39 |
-
history.append(
|
|
|
40 |
return history
|
41 |
|
42 |
-
# Gradio interface using
|
43 |
-
interface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Launch the chatbot
|
46 |
interface.launch()
|
|
|
13 |
)
|
14 |
|
15 |
# Function to handle the chatbot interaction
|
16 |
+
def chat(user_input, history=None):
|
17 |
global context
|
18 |
+
if history is None:
|
19 |
+
history = []
|
20 |
+
|
21 |
if user_input.lower() == "exit":
|
22 |
+
return history + [{"role": "assistant", "content": "Ending session. Goodbye!"}]
|
23 |
|
24 |
# Construct the modified input including system instructions and context
|
25 |
modified_input = (
|
|
|
37 |
# Update the context with the latest conversation
|
38 |
context += f"User: {user_input}\nAI: {ai_response}\n"
|
39 |
|
40 |
+
# Append the conversation to the history in the correct format for Gradio
|
41 |
+
history.append({"role": "user", "content": user_input})
|
42 |
+
history.append({"role": "assistant", "content": ai_response})
|
43 |
+
|
44 |
return history
|
45 |
|
46 |
+
# Gradio interface using the Chatbot template
|
47 |
+
interface = gr.Interface(
|
48 |
+
fn=chat,
|
49 |
+
inputs=["text", "state"],
|
50 |
+
outputs=["chatbot", "state"],
|
51 |
+
live=True
|
52 |
+
)
|
53 |
|
54 |
# Launch the chatbot
|
55 |
interface.launch()
|