Pooja001 commited on
Commit
17de9ad
ยท
verified ยท
1 Parent(s): 93ce4d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -29
app.py CHANGED
@@ -11,9 +11,7 @@ warnings.filterwarnings("ignore", category=UserWarning)
11
 
12
  REPO_ID = "Pooja001/SpeechEmotionNet"
13
 
14
- # ---------------------------
15
- # Streamlit UI Settings
16
- # ---------------------------
17
  st.set_page_config(page_title="SpeechEmotionNet โ€” SER", layout="wide")
18
 
19
  st.markdown("""
@@ -35,12 +33,8 @@ st.markdown("""
35
  </style>
36
  """, unsafe_allow_html=True)
37
 
38
- st.title("๐ŸŽค SpeechEmotionNet โ€” Speech Emotion Recognition")
39
-
40
 
41
- # ============================
42
- # ๐Ÿ“Œ Load model + assets
43
- # ============================
44
  @st.cache_resource
45
  def load_assets():
46
  model_path = hf_hub_download(repo_id=REPO_ID, filename="SpeechEmotionNet_best.keras")
@@ -56,10 +50,6 @@ def load_assets():
56
 
57
  model, scaler, encoder = load_assets()
58
 
59
-
60
- # ============================
61
- # ๐Ÿ“Œ Feature Extraction
62
- # ============================
63
  def extract_features_from_array(y, sr=16000):
64
  y = librosa.util.normalize(y)
65
 
@@ -70,10 +60,6 @@ def extract_features_from_array(y, sr=16000):
70
 
71
  return np.hstack([mfccs, chroma, contrast, zcr])
72
 
73
-
74
- # ============================
75
- # ๐Ÿ“Œ Tabs Layout
76
- # ============================
77
  tab_pred, tab_explain, tab_eval = st.tabs([
78
  "Prediction",
79
  "Explainability (SHAP)",
@@ -81,9 +67,7 @@ tab_pred, tab_explain, tab_eval = st.tabs([
81
  ])
82
 
83
 
84
- # ========================================================
85
- # ๐Ÿ”ฎ PREDICTION TAB
86
- # ========================================================
87
  with tab_pred:
88
 
89
  uploaded_file = st.file_uploader("Upload a WAV file", type=["wav"])
@@ -127,10 +111,7 @@ with tab_pred:
127
  st.markdown(href, unsafe_allow_html=True)
128
 
129
 
130
-
131
- # ========================================================
132
- # ๐Ÿ” SHAP EXPLAINABILITY TAB (KernelExplainer Fix)
133
- # ========================================================
134
  with tab_explain:
135
 
136
  st.subheader("SHAP Explainability for Uploaded Audio")
@@ -151,7 +132,6 @@ with tab_explain:
151
 
152
  st.info(f"SHAP explanation for: {pred_label.upper()}")
153
 
154
- # LATE IMPORT โ†’ prevents HuggingFace runtime timeout
155
  import shap
156
 
157
  # Background sample
@@ -189,11 +169,7 @@ with tab_explain:
189
  ax.set_title("Top 10 Influential Features")
190
  st.pyplot(fig, use_container_width=True)
191
 
192
-
193
-
194
- # ========================================================
195
- # ๐Ÿ“Š EVALUATION TAB
196
- # ========================================================
197
  with tab_eval:
198
 
199
  st.subheader("Model Evaluation Metrics")
 
11
 
12
  REPO_ID = "Pooja001/SpeechEmotionNet"
13
 
14
+
 
 
15
  st.set_page_config(page_title="SpeechEmotionNet โ€” SER", layout="wide")
16
 
17
  st.markdown("""
 
33
  </style>
34
  """, unsafe_allow_html=True)
35
 
36
+ st.title(" SpeechEmotionNet โ€” Speech Emotion Recognition")
 
37
 
 
 
 
38
  @st.cache_resource
39
  def load_assets():
40
  model_path = hf_hub_download(repo_id=REPO_ID, filename="SpeechEmotionNet_best.keras")
 
50
 
51
  model, scaler, encoder = load_assets()
52
 
 
 
 
 
53
  def extract_features_from_array(y, sr=16000):
54
  y = librosa.util.normalize(y)
55
 
 
60
 
61
  return np.hstack([mfccs, chroma, contrast, zcr])
62
 
 
 
 
 
63
  tab_pred, tab_explain, tab_eval = st.tabs([
64
  "Prediction",
65
  "Explainability (SHAP)",
 
67
  ])
68
 
69
 
70
+ # Prediction
 
 
71
  with tab_pred:
72
 
73
  uploaded_file = st.file_uploader("Upload a WAV file", type=["wav"])
 
111
  st.markdown(href, unsafe_allow_html=True)
112
 
113
 
114
+ # SHAP - explainability
 
 
 
115
  with tab_explain:
116
 
117
  st.subheader("SHAP Explainability for Uploaded Audio")
 
132
 
133
  st.info(f"SHAP explanation for: {pred_label.upper()}")
134
 
 
135
  import shap
136
 
137
  # Background sample
 
169
  ax.set_title("Top 10 Influential Features")
170
  st.pyplot(fig, use_container_width=True)
171
 
172
+ # Evaluation
 
 
 
 
173
  with tab_eval:
174
 
175
  st.subheader("Model Evaluation Metrics")