chayanbhansali commited on
Commit
d346fac
·
verified ·
1 Parent(s): aeafe2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -78,6 +78,9 @@ class RAGChatbot:
78
  return response.split("Answer:")[-1].strip()
79
 
80
  def chat(self, query, history):
 
 
 
81
  try:
82
  # Retrieve relevant context
83
  context = self.retrieve_relevant_context(query)
@@ -87,9 +90,10 @@ class RAGChatbot:
87
 
88
  # Append to history and return as list of tuples
89
  updated_history = history + [[query, response]]
90
- return updated_history
91
  except Exception as e:
92
- return history + [[query, f"An error occurred: {str(e)}"]]
 
93
 
94
  # Create Gradio interface
95
  def create_interface():
@@ -128,7 +132,7 @@ def create_interface():
128
  outputs=[chatbot, msg]
129
  )
130
 
131
- clear_btn.click(lambda: None, None, [chatbot, msg])
132
 
133
  return demo
134
 
 
78
  return response.split("Answer:")[-1].strip()
79
 
80
  def chat(self, query, history):
81
+ if not query:
82
+ return history, ""
83
+
84
  try:
85
  # Retrieve relevant context
86
  context = self.retrieve_relevant_context(query)
 
90
 
91
  # Append to history and return as list of tuples
92
  updated_history = history + [[query, response]]
93
+ return updated_history, ""
94
  except Exception as e:
95
+ error_response = f"An error occurred: {str(e)}"
96
+ return history + [[query, error_response]], ""
97
 
98
  # Create Gradio interface
99
  def create_interface():
 
132
  outputs=[chatbot, msg]
133
  )
134
 
135
+ clear_btn.click(lambda: (None, ""), None, [chatbot, msg])
136
 
137
  return demo
138