Kamalaskar Disha Vinay (EXT) commited on
Commit Β·
dff6a3a
1
Parent(s): 8d6129a
change requirements and model
Browse files
app.py
CHANGED
|
@@ -186,7 +186,7 @@ def predict_emotion(audio_file, text_input, video_file):
|
|
| 186 |
"""Main prediction function"""
|
| 187 |
|
| 188 |
if audio_file is None or video_file is None or not text_input.strip():
|
| 189 |
-
return "Please provide all three inputs: audio, text, and video", None
|
| 190 |
|
| 191 |
try:
|
| 192 |
# Preprocess
|
|
@@ -202,25 +202,19 @@ def predict_emotion(audio_file, text_input, video_file):
|
|
| 202 |
|
| 203 |
# Get probabilities
|
| 204 |
fused_probs = torch.softmax(fused_logits, dim=1)[0].cpu().numpy()
|
| 205 |
-
audio_probs = torch.softmax(a_logits, dim=1)[0].cpu().numpy()
|
| 206 |
-
text_probs = torch.softmax(t_logits, dim=1)[0].cpu().numpy()
|
| 207 |
-
video_probs = torch.softmax(v_logits, dim=1)[0].cpu().numpy()
|
| 208 |
|
| 209 |
# Format results
|
| 210 |
-
|
| 211 |
-
audio_result = {LABELS[i]: float(audio_probs[i]) for i in range(len(LABELS))}
|
| 212 |
-
text_result = {LABELS[i]: float(text_probs[i]) for i in range(len(LABELS))}
|
| 213 |
-
video_result = {LABELS[i]: float(video_probs[i]) for i in range(len(LABELS))}
|
| 214 |
|
| 215 |
predicted_emotion = LABELS[fused_probs.argmax()]
|
| 216 |
confidence = float(fused_probs.max())
|
| 217 |
|
| 218 |
result_text = f"π― **Predicted Emotion: {predicted_emotion.upper()}**\n\n**Confidence: {confidence:.2%}**"
|
| 219 |
|
| 220 |
-
return result_text,
|
| 221 |
|
| 222 |
except Exception as e:
|
| 223 |
-
return f"Error: {str(e)}", None
|
| 224 |
|
| 225 |
# Gradio Interface
|
| 226 |
with gr.Blocks(title="Multimodal Emotion Recognition", theme=gr.themes.Soft()) as demo:
|
|
@@ -253,18 +247,14 @@ with gr.Blocks(title="Multimodal Emotion Recognition", theme=gr.themes.Soft()) a
|
|
| 253 |
|
| 254 |
with gr.Column():
|
| 255 |
result_text = gr.Markdown(label="Result")
|
| 256 |
-
|
| 257 |
-
with gr.Accordion("π Detailed Predictions", open=True):
|
| 258 |
-
fused_output = gr.Label(label="π Fused Prediction", num_top_classes=4)
|
| 259 |
-
audio_output = gr.Label(label="π€ Audio-only Prediction", num_top_classes=4)
|
| 260 |
-
text_output = gr.Label(label="π Text-only Prediction", num_top_classes=4)
|
| 261 |
-
video_output = gr.Label(label="π₯ Video-only Prediction", num_top_classes=4)
|
| 262 |
|
| 263 |
predict_btn.click(
|
| 264 |
fn=predict_emotion,
|
| 265 |
inputs=[audio_input, text_input, video_input],
|
| 266 |
-
outputs=[result_text,
|
| 267 |
)
|
|
|
|
| 268 |
|
| 269 |
gr.Markdown(
|
| 270 |
"""
|
|
|
|
| 186 |
"""Main prediction function"""
|
| 187 |
|
| 188 |
if audio_file is None or video_file is None or not text_input.strip():
|
| 189 |
+
return "Please provide all three inputs: audio, text, and video", None
|
| 190 |
|
| 191 |
try:
|
| 192 |
# Preprocess
|
|
|
|
| 202 |
|
| 203 |
# Get probabilities
|
| 204 |
fused_probs = torch.softmax(fused_logits, dim=1)[0].cpu().numpy()
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
# Format results
|
| 207 |
+
result = {LABELS[i]: float(fused_probs[i]) for i in range(len(LABELS))}
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
predicted_emotion = LABELS[fused_probs.argmax()]
|
| 210 |
confidence = float(fused_probs.max())
|
| 211 |
|
| 212 |
result_text = f"π― **Predicted Emotion: {predicted_emotion.upper()}**\n\n**Confidence: {confidence:.2%}**"
|
| 213 |
|
| 214 |
+
return result_text, result
|
| 215 |
|
| 216 |
except Exception as e:
|
| 217 |
+
return f"Error: {str(e)}", None
|
| 218 |
|
| 219 |
# Gradio Interface
|
| 220 |
with gr.Blocks(title="Multimodal Emotion Recognition", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 247 |
|
| 248 |
with gr.Column():
|
| 249 |
result_text = gr.Markdown(label="Result")
|
| 250 |
+
result_output = gr.Label(label="π Prediction Results", num_top_classes=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
predict_btn.click(
|
| 253 |
fn=predict_emotion,
|
| 254 |
inputs=[audio_input, text_input, video_input],
|
| 255 |
+
outputs=[result_text, result_output]
|
| 256 |
)
|
| 257 |
+
|
| 258 |
|
| 259 |
gr.Markdown(
|
| 260 |
"""
|