Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|