TejAndrewsACC commited on
Commit
a5f10f2
·
verified ·
1 Parent(s): b0ecf87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -19,13 +19,19 @@ def chat_function(message, history):
19
  )
20
 
21
  try:
 
22
  response = client.predict(
23
  message=modified_input,
24
  api_name="/chat_function"
25
  )
26
 
 
 
 
 
27
  context += f"User: {message}\nAI: {response}\n"
28
 
 
29
  history.append((message, response))
30
 
31
  return response, history
@@ -33,6 +39,7 @@ def chat_function(message, history):
33
  except Exception as e:
34
  return f"Error: {e}", history
35
 
 
36
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
37
  chatbot = gr.Chatbot()
38
  msg = gr.Textbox(placeholder="Type something...")
@@ -40,4 +47,4 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
40
 
41
  msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
42
 
43
- demo.launch()
 
19
  )
20
 
21
  try:
22
+ # Get the response from the model
23
  response = client.predict(
24
  message=modified_input,
25
  api_name="/chat_function"
26
  )
27
 
28
+ # Ensure the response is a string, not a list
29
+ response = " ".join(response) if isinstance(response, list) else response
30
+
31
+ # Update context
32
  context += f"User: {message}\nAI: {response}\n"
33
 
34
+ # Append the message and response to history
35
  history.append((message, response))
36
 
37
  return response, history
 
39
  except Exception as e:
40
  return f"Error: {e}", history
41
 
42
+ # Gradio UI setup
43
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
44
  chatbot = gr.Chatbot()
45
  msg = gr.Textbox(placeholder="Type something...")
 
47
 
48
  msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
49
 
50
+ demo.launch()