ojas121 commited on
Commit
d6a1faf
Β·
verified Β·
1 Parent(s): 83e784c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -14,7 +14,7 @@ from huggingface_hub import snapshot_download
14
  from pydub import AudioSegment
15
  import noisereduce as nr
16
 
17
-
18
  st.markdown(
19
  """
20
  <style>
@@ -103,7 +103,8 @@ if uploaded_file:
103
  # 🎡 Display waveform
104
  st.markdown("<div class='subheader'>🎼 Audio Waveform:</div>", unsafe_allow_html=True)
105
  fig, ax = plt.subplots(figsize=(10, 4))
106
- librosa.display.waveshow(y, sr=sr, ax=ax)
 
107
  st.pyplot(fig)
108
 
109
  # βœ… Noise Reduction
@@ -130,10 +131,29 @@ if uploaded_file:
130
  st.markdown("<div class='subheader'>πŸ“ Transcribed Text:</div>", unsafe_allow_html=True)
131
  st.markdown(f"<div class='stMarkdown'>{transcription}</div>", unsafe_allow_html=True)
132
 
133
- # βœ… Emotion Detection
134
  st.markdown("<div class='subheader'>😊 Emotion Analysis:</div>", unsafe_allow_html=True)
 
135
  emotion_result = emotion_model(file_path)
136
- st.write(emotion_result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  # βœ… Play Original & Denoised Audio
139
  st.markdown("<div class='subheader'>πŸ”Š Play Audio:</div>", unsafe_allow_html=True)
 
14
  from pydub import AudioSegment
15
  import noisereduce as nr
16
 
17
+ # 🎨 Apply Custom Dark Mode CSS
18
  st.markdown(
19
  """
20
  <style>
 
103
  # 🎡 Display waveform
104
  st.markdown("<div class='subheader'>🎼 Audio Waveform:</div>", unsafe_allow_html=True)
105
  fig, ax = plt.subplots(figsize=(10, 4))
106
+ librosa.display.waveshow(y, sr=sr, ax=ax, color="cyan")
107
+ ax.set_facecolor("#121212") # Dark background for waveform
108
  st.pyplot(fig)
109
 
110
  # βœ… Noise Reduction
 
131
  st.markdown("<div class='subheader'>πŸ“ Transcribed Text:</div>", unsafe_allow_html=True)
132
  st.markdown(f"<div class='stMarkdown'>{transcription}</div>", unsafe_allow_html=True)
133
 
134
+ # βœ… Emotion Detection (Formatted Output)
135
  st.markdown("<div class='subheader'>😊 Emotion Analysis:</div>", unsafe_allow_html=True)
136
+
137
  emotion_result = emotion_model(file_path)
138
+ emotion_labels = {
139
+ "LABEL_0": "Neutral",
140
+ "LABEL_1": "Happy",
141
+ "LABEL_2": "Sad",
142
+ "LABEL_3": "Angry",
143
+ "LABEL_4": "Surprised"
144
+ }
145
+ top_emotion = max(emotion_result, key=lambda x: x["score"])
146
+ emotion_name = emotion_labels.get(top_emotion["label"], "Unknown")
147
+ emotion_score = top_emotion["score"]
148
+
149
+ st.markdown(
150
+ f"""
151
+ <div style="font-size:24px; color:#4CAF50; font-weight:bold;">
152
+ {emotion_name} ({emotion_score:.2%} confidence)
153
+ </div>
154
+ """,
155
+ unsafe_allow_html=True
156
+ )
157
 
158
  # βœ… Play Original & Denoised Audio
159
  st.markdown("<div class='subheader'>πŸ”Š Play Audio:</div>", unsafe_allow_html=True)