TejAndrewsACC commited on
Commit
edb1715
·
verified ·
1 Parent(s): 6424df9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
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 + [("assistant", "Ending session. Goodbye!")] # Using tuples here to avoid errors
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 AI's response to the conversation history using the correct tuple format
38
- history.append(("user", user_input))
39
- history.append(("assistant", ai_response))
 
40
  return history
41
 
42
- # Gradio interface using ChatInterface
43
- interface = gr.Interface(fn=chat, inputs=["text", "state"], outputs=["chatbot", "state"])
 
 
 
 
 
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()