Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import soundfile as sf
|
| 3 |
-
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
import shutil
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
-
classifier = pipeline("audio-classification", model=
|
| 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 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|