Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,12 +43,12 @@ class ConversationalAI:
|
|
| 43 |
device=self.device
|
| 44 |
)
|
| 45 |
|
| 46 |
-
# Load emotion recognition
|
| 47 |
self.emotion_model = pipeline(
|
| 48 |
"audio-classification",
|
| 49 |
-
model="
|
| 50 |
device=self.device
|
| 51 |
-
)
|
| 52 |
|
| 53 |
# Conversation history
|
| 54 |
self.conversations = {}
|
|
@@ -87,15 +87,16 @@ class ConversationalAI:
|
|
| 87 |
except Exception as e:
|
| 88 |
return f"Transcription error: {str(e)}"
|
| 89 |
|
| 90 |
-
def recognize_emotion(self,
|
| 91 |
-
"""Recognize emotion from
|
| 92 |
try:
|
| 93 |
-
if
|
| 94 |
return "neutral"
|
| 95 |
|
| 96 |
-
result = self.emotion_model(
|
| 97 |
return result[0]["label"].lower()
|
| 98 |
-
except:
|
|
|
|
| 99 |
return "neutral"
|
| 100 |
|
| 101 |
def generate_response(self, text, emotion, conversation_history):
|
|
@@ -176,8 +177,8 @@ class ConversationalAI:
|
|
| 176 |
# Step 1: Transcribe audio
|
| 177 |
transcription = self.transcribe_audio(audio_input)
|
| 178 |
|
| 179 |
-
# Step 2: Recognize emotion from
|
| 180 |
-
emotion = self.recognize_emotion(
|
| 181 |
|
| 182 |
# Step 3: Generate response
|
| 183 |
response_text = self.generate_response(
|
|
@@ -335,12 +336,11 @@ with gr.Blocks(
|
|
| 335 |
outputs=[transcription_output, audio_output, conversation_history]
|
| 336 |
)
|
| 337 |
|
| 338 |
-
# Launch the app
|
| 339 |
if __name__ == "__main__":
|
| 340 |
demo.launch(
|
| 341 |
server_name="0.0.0.0",
|
| 342 |
server_port=7860,
|
| 343 |
show_error=True,
|
| 344 |
-
show_tips=False,
|
| 345 |
quiet=True
|
| 346 |
)
|
|
|
|
| 43 |
device=self.device
|
| 44 |
)
|
| 45 |
|
| 46 |
+
# Load CORRECT audio emotion recognition model
|
| 47 |
self.emotion_model = pipeline(
|
| 48 |
"audio-classification",
|
| 49 |
+
model="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
| 50 |
device=self.device
|
| 51 |
+
)[1]
|
| 52 |
|
| 53 |
# Conversation history
|
| 54 |
self.conversations = {}
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
return f"Transcription error: {str(e)}"
|
| 89 |
|
| 90 |
+
def recognize_emotion(self, audio_path):
|
| 91 |
+
"""Recognize emotion from audio using proper audio model"""
|
| 92 |
try:
|
| 93 |
+
if audio_path is None:
|
| 94 |
return "neutral"
|
| 95 |
|
| 96 |
+
result = self.emotion_model(audio_path)
|
| 97 |
return result[0]["label"].lower()
|
| 98 |
+
except Exception as e:
|
| 99 |
+
print(f"Emotion recognition error: {e}")
|
| 100 |
return "neutral"
|
| 101 |
|
| 102 |
def generate_response(self, text, emotion, conversation_history):
|
|
|
|
| 177 |
# Step 1: Transcribe audio
|
| 178 |
transcription = self.transcribe_audio(audio_input)
|
| 179 |
|
| 180 |
+
# Step 2: Recognize emotion from audio
|
| 181 |
+
emotion = self.recognize_emotion(audio_input)
|
| 182 |
|
| 183 |
# Step 3: Generate response
|
| 184 |
response_text = self.generate_response(
|
|
|
|
| 336 |
outputs=[transcription_output, audio_output, conversation_history]
|
| 337 |
)
|
| 338 |
|
| 339 |
+
# Launch the app - FIXED: Removed show_tips parameter
|
| 340 |
if __name__ == "__main__":
|
| 341 |
demo.launch(
|
| 342 |
server_name="0.0.0.0",
|
| 343 |
server_port=7860,
|
| 344 |
show_error=True,
|
|
|
|
| 345 |
quiet=True
|
| 346 |
)
|