waleedmohd commited on
Commit
d343db8
·
verified ·
1 Parent(s): ee1b736

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -71,7 +71,6 @@ class MultilingualNewsChatbot:
71
  'language': 'ar',
72
  'category': 'السياسة الدولية'
73
  },
74
- # More multilingual news content can be added here
75
  ]
76
 
77
  # Batch processing of knowledge
@@ -204,46 +203,41 @@ class MultilingualNewsChatbot:
204
 
205
  except Exception as e:
206
  # Error handling with multilingual support
207
- error_msg = f"Error processing query: {str(e)}"
208
- print(error_msg)
209
  return self.FALLBACK_RESPONSES.get(lang, self.FALLBACK_RESPONSES['en'])
210
 
211
- # Initialize the chatbot
212
- news_chatbot = MultilingualNewsChatbot()
213
-
214
- def chat_interface(message: str, history: List[List[str]], state: Dict) -> Tuple[str, Dict]:
215
  """
216
- Gradio chat interface for the multilingual news chatbot.
217
 
218
  Args:
219
  message (str): User's input message
220
- history (List): Conversation history
221
- state (Dict): Additional state information
222
 
223
  Returns:
224
- Tuple of response and updated state
225
  """
226
  try:
 
 
 
 
 
 
227
  response = news_chatbot.generate_response(message, include_confidence=True)
228
- return response, state or {}
229
  except Exception as e:
230
- error_response = news_chatbot.FALLBACK_RESPONSES['en']
231
  print(f"Interface error: {e}")
232
- return error_response, state or {}
233
 
234
  # Create Gradio interface
235
  demo = gr.ChatInterface(
236
  fn=chat_interface,
237
- title="🌍 BBC-Style Multilingual News Chatbot",
238
- description="Get the latest news and insights in English and Arabic.",
239
- theme="soft",
240
- examples=[
241
- ["What's happening in the Middle East?"],
242
- ["ما هي آخر التطورات الإقليمية؟"],
243
- ["Tell me about current global tensions"],
244
- ["حدثني عن الوضع العالمي"]
245
- ]
246
  )
247
 
248
  if __name__ == "__main__":
249
- demo.launch()
 
71
  'language': 'ar',
72
  'category': 'السياسة الدولية'
73
  },
 
74
  ]
75
 
76
  # Batch processing of knowledge
 
203
 
204
  except Exception as e:
205
  # Error handling with multilingual support
206
+ print(f"Error processing query: {str(e)}")
 
207
  return self.FALLBACK_RESPONSES.get(lang, self.FALLBACK_RESPONSES['en'])
208
 
209
+ def chat_interface(message, history):
 
 
 
210
  """
211
+ Simplified chat interface function.
212
 
213
  Args:
214
  message (str): User's input message
215
+ history (list): Conversation history
 
216
 
217
  Returns:
218
+ str: Generated response
219
  """
220
  try:
221
+ # Initialize chatbot if not already done
222
+ global news_chatbot
223
+ if 'news_chatbot' not in globals():
224
+ news_chatbot = MultilingualNewsChatbot()
225
+
226
+ # Generate response
227
  response = news_chatbot.generate_response(message, include_confidence=True)
228
+ return response
229
  except Exception as e:
230
+ error_response = "Sorry, an error occurred while processing your request."
231
  print(f"Interface error: {e}")
232
+ return error_response
233
 
234
  # Create Gradio interface
235
  demo = gr.ChatInterface(
236
  fn=chat_interface,
237
+ title="🌍 Multilingual News Chatbot",
238
+ description="Get insights in multiple languages",
239
+ theme="soft"
 
 
 
 
 
 
240
  )
241
 
242
  if __name__ == "__main__":
243
+ demo.launch(debug=True)