sami606713 commited on
Commit
628b599
·
verified ·
1 Parent(s): c07f07c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import streamlit as st
2
  import soundfile as sf
3
- # Use a pipeline as a high-level helper
4
- from transformers import pipeline
5
- import shutil
6
 
7
- # Clear the Hugging Face cache
8
- shutil.rmtree("./transformers_cache", ignore_errors=True)
 
 
9
  try:
10
- classifier = pipeline("audio-classification", model="sami606713/emotion_classification")
11
  except Exception as e:
12
- st.write(f"{e}")
13
 
14
  # Title and description
15
  st.title("Audio Emotion Classification")
@@ -20,15 +20,18 @@ uploaded_file = st.file_uploader("Choose an audio file...", type=["wav", "mp3",
20
 
21
  if uploaded_file is not None:
22
  # Load the audio file
23
- audio_input,sample_rate=sf.read(uploaded_file)
24
 
25
  # Display the audio player
26
  st.audio(uploaded_file)
27
 
28
  # Perform emotion classification
29
  st.write("Classifying...")
30
- predictions = classifier(audio_input)
31
-
32
- # Display the results
33
- for prediction in predictions:
34
- st.write(f"Emotion: {prediction['label']}, Score: {prediction['score']:.2f}")
 
 
 
 
1
  import streamlit as st
2
  import soundfile as sf
3
+ from transformers import pipeline, Wav2Vec2ForSequenceClassification, Wav2Vec2Tokenizer
 
 
4
 
5
+ # Load the model and tokenizer
6
+ model_name = "sami606713/emotion_classification"
7
+
8
+ # Initialize the pipeline
9
  try:
10
+ classifier = pipeline("audio-classification", model=model_name, tokenizer=model_name)
11
  except Exception as e:
12
+ st.write(f"Error loading model: {e}")
13
 
14
  # Title and description
15
  st.title("Audio Emotion Classification")
 
20
 
21
  if uploaded_file is not None:
22
  # Load the audio file
23
+ audio_input, sample_rate = sf.read(uploaded_file)
24
 
25
  # Display the audio player
26
  st.audio(uploaded_file)
27
 
28
  # Perform emotion classification
29
  st.write("Classifying...")
30
+ try:
31
+ predictions = classifier(audio_input, sampling_rate=sample_rate)
32
+
33
+ # Display the results
34
+ for prediction in predictions:
35
+ st.write(f"Emotion: {prediction['label']}, Score: {prediction['score']:.2f}")
36
+ except Exception as e:
37
+ st.write(f"Error during classification: {e}")