sachin7777777 commited on
Commit
805335e
Β·
verified Β·
1 Parent(s): d921763

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -4,19 +4,17 @@ import pandas as pd
4
  import plotly.express as px
5
 
6
  # ------------------------------
7
- # Load pretrained models (CPU)
8
  # ------------------------------
9
  text_classifier = pipeline(
10
  "text-classification",
11
  model="j-hartmann/emotion-english-distilroberta-base",
12
- return_all_scores=True,
13
- device=-1 # CPU
14
  )
15
 
16
  audio_classifier = pipeline(
17
  "audio-classification",
18
- model="mrm8488/wav2vec2-small-xlsr-53-english-emotion",
19
- device=-1 # CPU
20
  )
21
 
22
  # ------------------------------
@@ -30,7 +28,7 @@ EMOJI_MAP = {
30
  "neutral": "😐",
31
  "sadness": "😒",
32
  "surprise": "😲",
33
- "hap": "πŸ˜„",
34
  "neu": "😐",
35
  "sad": "😒",
36
  "ang": "😑"
@@ -108,7 +106,7 @@ def predict(text, audio, w_text, w_audio):
108
  # Build Gradio interface
109
  # ------------------------------
110
  with gr.Blocks() as demo:
111
- gr.Markdown("## 🎭 CPU-Friendly Multimodal Emotion Classification")
112
 
113
  with gr.Row():
114
  with gr.Column():
@@ -121,6 +119,7 @@ with gr.Blocks() as demo:
121
  final_label = gr.Markdown(label="Predicted Emotion")
122
  chart_output = gr.Plot(label="Emotion Scores")
123
 
 
124
  btn.click(fn=predict, inputs=[txt, aud, w1, w2], outputs=[final_label, chart_output])
125
 
126
- demo.launch()
 
4
  import plotly.express as px
5
 
6
  # ------------------------------
7
+ # Load pretrained models
8
  # ------------------------------
9
  text_classifier = pipeline(
10
  "text-classification",
11
  model="j-hartmann/emotion-english-distilroberta-base",
12
+ return_all_scores=True
 
13
  )
14
 
15
  audio_classifier = pipeline(
16
  "audio-classification",
17
+ model="superb/wav2vec2-base-superb-er"
 
18
  )
19
 
20
  # ------------------------------
 
28
  "neutral": "😐",
29
  "sadness": "😒",
30
  "surprise": "😲",
31
+ "hap": "πŸ˜„", # for audio model
32
  "neu": "😐",
33
  "sad": "😒",
34
  "ang": "😑"
 
106
  # Build Gradio interface
107
  # ------------------------------
108
  with gr.Blocks() as demo:
109
+ gr.Markdown("## 🎭 Multimodal Emotion Classification (Text + Speech)")
110
 
111
  with gr.Row():
112
  with gr.Column():
 
119
  final_label = gr.Markdown(label="Predicted Emotion")
120
  chart_output = gr.Plot(label="Emotion Scores")
121
 
122
+ # Button click triggers prediction
123
  btn.click(fn=predict, inputs=[txt, aud, w1, w2], outputs=[final_label, chart_output])
124
 
125
+ demo.launch()