Kamalaskar Disha Vinay (EXT) commited on
Commit
c99a178
Β·
1 Parent(s): dff6a3a

change requirements and model

Browse files
Files changed (1) hide show
  1. app.py +17 -7
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,19 +202,25 @@ 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
 
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,14 +253,18 @@ with gr.Blocks(title="Multimodal Emotion Recognition", theme=gr.themes.Soft()) a
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
  """
 
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, None, None, None
190
 
191
  try:
192
  # Preprocess
 
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
+ fused_result = {LABELS[i]: float(fused_probs[i]) for i in range(len(LABELS))}
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, fused_result, audio_result, text_result, video_result
221
 
222
  except Exception as e:
223
+ return f"Error: {str(e)}", None, None, None, None
224
 
225
  # Gradio Interface
226
  with gr.Blocks(title="Multimodal Emotion Recognition", theme=gr.themes.Soft()) as demo:
 
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, fused_output, audio_output, text_output, video_output]
267
  )
 
268
 
269
  gr.Markdown(
270
  """