ibrahim313 commited on
Commit
cebc769
·
verified ·
1 Parent(s): 9dc92cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -55,8 +55,9 @@ pipe = load_model()
55
  def convert_to_wav(audio_file):
56
  """Converts uploaded audio file to WAV format."""
57
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_wav:
58
- y, sr = librosa.load(audio_file, sr=None)
59
- sf.write(tmp_wav.name, y, sr)
 
60
  return tmp_wav.name
61
 
62
  def classify_audio(audio_file):
@@ -137,6 +138,9 @@ if uploaded_file is not None:
137
  plot_bgcolor='rgba(0,0,0,0)'
138
  )
139
  st.plotly_chart(fig_waveform, use_container_width=True)
 
 
 
140
 
141
  except Exception as e:
142
  st.error(f"An error occurred while processing the audio: {str(e)}")
@@ -148,4 +152,3 @@ st.markdown("""
148
  <p>Created with ❤️ by AI. Powered by Streamlit and Hugging Face Transformers.</p>
149
  </div>
150
  """, unsafe_allow_html=True)
151
-
 
55
  def convert_to_wav(audio_file):
56
  """Converts uploaded audio file to WAV format."""
57
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_wav:
58
+ # Use soundfile to load and save the audio file as WAV
59
+ audio_data, samplerate = sf.read(audio_file)
60
+ sf.write(tmp_wav.name, audio_data, samplerate)
61
  return tmp_wav.name
62
 
63
  def classify_audio(audio_file):
 
138
  plot_bgcolor='rgba(0,0,0,0)'
139
  )
140
  st.plotly_chart(fig_waveform, use_container_width=True)
141
+
142
+ # 🎈 Show balloons after successfully displaying the results
143
+ st.balloons()
144
 
145
  except Exception as e:
146
  st.error(f"An error occurred while processing the audio: {str(e)}")
 
152
  <p>Created with ❤️ by AI. Powered by Streamlit and Hugging Face Transformers.</p>
153
  </div>
154
  """, unsafe_allow_html=True)