Nada commited on
Commit
a54fe99
·
1 Parent(s): 5525e9f
Files changed (1) hide show
  1. chatbot.py +18 -9
chatbot.py CHANGED
@@ -309,23 +309,32 @@ Response:"""
309
 
310
  def _load_emotion_model(self):
311
  try:
 
312
  return pipeline(
313
  "text-classification",
314
  model="SamLowe/roberta-base-go_emotions",
315
  top_k=None,
316
  device_map="auto" if self.device == "cuda" else None,
317
- cache_dir=CACHE_DIR
 
318
  )
319
  except Exception as e:
320
  logger.error(f"Error loading emotion model: {e}")
321
- # Fallback
322
- return pipeline(
323
- "text-classification",
324
- model="j-hartmann/emotion-english-distilroberta-base",
325
- return_all_scores=True,
326
- device_map="auto" if self.device == "cuda" else None,
327
- cache_dir=CACHE_DIR
328
- )
 
 
 
 
 
 
 
329
 
330
  def _initialize_llm(self, model_name: str, use_4bit: bool):
331
  try:
 
309
 
310
  def _load_emotion_model(self):
311
  try:
312
+ # Use safetensors explicitly for the primary model
313
  return pipeline(
314
  "text-classification",
315
  model="SamLowe/roberta-base-go_emotions",
316
  top_k=None,
317
  device_map="auto" if self.device == "cuda" else None,
318
+ cache_dir=CACHE_DIR,
319
+ use_safetensors=True # Explicitly use safetensors
320
  )
321
  except Exception as e:
322
  logger.error(f"Error loading emotion model: {e}")
323
+ # Fallback to a simpler model with safetensors
324
+ try:
325
+ return pipeline(
326
+ "text-classification",
327
+ model="j-hartmann/emotion-english-distilroberta-base",
328
+ return_all_scores=True,
329
+ device_map="auto" if self.device == "cuda" else None,
330
+ cache_dir=CACHE_DIR,
331
+ use_safetensors=True, # Explicitly use safetensors
332
+ from_tf=True # Use TensorFlow weights if available
333
+ )
334
+ except Exception as e:
335
+ logger.error(f"Error loading fallback emotion model: {e}")
336
+ # Return a simple pipeline that always returns neutral
337
+ return lambda text: [{"label": "neutral", "score": 1.0}]
338
 
339
  def _initialize_llm(self, model_name: str, use_4bit: bool):
340
  try: