Spaces:
Runtime error
Runtime error
Update app.py
Browse files42 unmodified lines43444546464748494950515152535433 unmodified lines88899091919293949596979798991001011021031041051061071081091101111121131141151164 unmodified lines1211221231081091101241251261271281291301311321331341351361371381391401411421431441458 unmodified lines1541551561251571581591606 unmodified lines167168169138139140170171172173174175192 unmodified lines36836937033937137237337442 unmodified lines device=self.device ) # Load CORRECT audio emotion recognition model # Load WORKING audio emotion recognition model self.emotion_model = pipeline( "audio-classification", model="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", model="superb/wav2vec2-base-superb-er", device=self.device )[1] ) # Conversation history self.conversations = {}33 unmodified lines return f"Transcription error: {str(e)}" def recognize_emotion(self, audio_path): """Recognize emotion from audio using proper audio model""" """Recognize emotion from audio using working model""" try: if audio_path is None: return "neutral" result = self.emotion_model(audio_path) return result[0]["label"].lower() emotion_label = result[0]["label"].lower() # Map SUPERB emotions to common emotions emotion_mapping = { "ang": "angry", "hap": "happy", "exc": "excited", "sad": "sad", "fru": "frustrated", "fea": "fearful", "sur": "surprised", "neu": "neutral", "dis": "disgusted" } return emotion_mapping.get(emotion_label, emotion_label) except Exception as e: print(f"Emotion recognition error: {e}") return "neutral"4 unmodified lines if text.startswith("Transcription error") or not text.strip(): return "I'm sorry, I couldn't understand what you said. Could you please try again?" # Build context-aware prompt emotion_prompt = f"[User seems {emotion}] " if emotion != "neutral" else "" prompt = f"{emotion_prompt}User: {text}\nMaya:" # Build context-aware prompt with emotion emotion_responses = { "angry": "I understand you're feeling frustrated. Let me help you with that.", "sad": "I can sense you're feeling down. I'm here to listen and support you.", "happy": "I love your positive energy! That's wonderful to hear.", "excited": "Your enthusiasm is contagious! Tell me more about it.", "fearful": "I can hear the concern in your voice. Let's work through this together.", "surprised": "That sounds quite unexpected! What happened?", "frustrated": "I can tell this is bothering you. Let's see how I can help.", "neutral": "I'm listening. Please go on." } emotion_context = emotion_responses.get(emotion, "I'm here to help.") # Simple but effective response generation if len(text.split()) < 3: return f"{emotion_context} Could you tell me more about that?" prompt = f"User ({emotion}): {text}\nMaya (helpful assistant):" # Tokenize with proper attention mask inputs = self.llm_tokenizer(8 unmodified lines outputs = self.llm_model.generate( input_ids=inputs.input_ids, attention_mask=inputs.attention_mask, max_new_tokens=80, max_new_tokens=60, temperature=0.7, do_sample=True, pad_token_id=self.llm_tokenizer.eos_token_id,6 unmodified lines skip_special_tokens=True ).strip() # Clean up response if not response: response = "I understand. Could you tell me more about that?" # Clean up and add emotion context if response is empty if not response or len(response) < 5: return emotion_context return response 192 unmodified lines outputs=[transcription_output, audio_output, conversation_history] )
# Launch the app - FIXED: Removed show_tips parameter# Launch the appif __name__ == "__main__": demo.launch( server_name="0.0.0.0",app.py+45-13