RahulGanapathy commited on
Commit
8fbc968
·
verified ·
1 Parent(s): 42399aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -16,13 +16,11 @@ SYSTEM_MESSAGE = (
16
 
17
  # Function to handle chatbot responses
18
  def respond(message, history):
19
- # Ensure history is a list of tuples
20
- if not isinstance(history, list) or not all(isinstance(i, tuple) and len(i) == 2 for i in history):
21
  history = []
22
 
23
  messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
24
 
25
- # Ensure history is correctly formatted
26
  for user, bot in history:
27
  messages.append({"role": "user", "content": user})
28
  messages.append({"role": "assistant", "content": bot})
@@ -38,17 +36,16 @@ def respond(message, history):
38
  # ✅ Append correctly formatted tuple to history
39
  history.append((message, bot_reply))
40
 
41
- return history, bot_reply
42
 
43
  # Create Gradio chatbot UI
44
- chatbot_ui = gr.Chatbot()
45
-
46
  demo = gr.Interface(
47
  fn=respond,
48
- inputs=["text", chatbot_ui], # Ensure chatbot component receives formatted history
49
- outputs=[chatbot_ui, "text"], # Ensure chatbot returns formatted history
50
  title="Misinformation Detection Chatbot",
51
  description="Ask anything, and the chatbot will verify whether it's true or false.",
 
52
  )
53
 
54
  if __name__ == "__main__":
 
16
 
17
  # Function to handle chatbot responses
18
  def respond(message, history):
19
+ if history is None:
 
20
  history = []
21
 
22
  messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
23
 
 
24
  for user, bot in history:
25
  messages.append({"role": "user", "content": user})
26
  messages.append({"role": "assistant", "content": bot})
 
36
  # ✅ Append correctly formatted tuple to history
37
  history.append((message, bot_reply))
38
 
39
+ return history
40
 
41
  # Create Gradio chatbot UI
 
 
42
  demo = gr.Interface(
43
  fn=respond,
44
+ inputs=["text", "state"], # Pass state properly
45
+ outputs=["chatbot", "state"], # Chatbot is dynamically handled
46
  title="Misinformation Detection Chatbot",
47
  description="Ask anything, and the chatbot will verify whether it's true or false.",
48
+ live=True,
49
  )
50
 
51
  if __name__ == "__main__":