Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,24 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
from speechbrain.inference.interfaces import foreign_class
|
3 |
|
4 |
# Initialize the classifier
|
5 |
classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Classify the file
|
10 |
-
out_prob, score, index, text_lab = classifier.classify_file(
|
11 |
# Display the output
|
12 |
st.write(text_lab)
|
13 |
else:
|
|
|
1 |
import streamlit as st
|
2 |
+
import tempfile
|
3 |
+
import os
|
4 |
from speechbrain.inference.interfaces import foreign_class
|
5 |
|
6 |
# Initialize the classifier
|
7 |
classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
8 |
|
9 |
+
def save_uploaded_file(uploaded_file):
|
10 |
+
temp_dir = tempfile.TemporaryDirectory()
|
11 |
+
file_path = os.path.join(temp_dir.name, uploaded_file.name)
|
12 |
+
with open(file_path, "wb") as f:
|
13 |
+
f.write(uploaded_file.getbuffer())
|
14 |
+
return file_path
|
15 |
+
|
16 |
+
def emotion(uploaded_file):
|
17 |
+
if uploaded_file is not None:
|
18 |
+
# Save the uploaded file to a temporary location
|
19 |
+
file_path = save_uploaded_file(uploaded_file)
|
20 |
# Classify the file
|
21 |
+
out_prob, score, index, text_lab = classifier.classify_file(file_path)
|
22 |
# Display the output
|
23 |
st.write(text_lab)
|
24 |
else:
|