-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHome.py
72 lines (60 loc) · 2.16 KB
/
Home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import pandas as pd
import numpy as np
from st_audiorec import st_audiorec
import tempfile
# import tensorflow as tf
# import keras
# import librosa
# st.write(tf.__version__)
# st.write(librosa.__version__)
# st.write(keras.__version__)
from functions import generate_df, predict_result, save_uploaded_file, process_audio, user_evaluation
from st_audiorec import st_audiorec
acting_script = pd.read_csv('csv/acting-scripts.csv')
# Initialize session state variables
shuffle = st.button("Shuffle")
st.write("Act on following script and emotions!")
if ('rand_script' not in st.session_state) or shuffle:
acting_script = pd.read_csv('csv/acting-scripts.csv')
rand_row = acting_script.sample()
st.session_state.rand_script = rand_row["script"].values[0]
st.session_state.rand_emotion = rand_row["emotion"].values[0]
# Use session state variables
st.title(st.session_state.rand_script)
st.write("Emotion: ", st.session_state.rand_emotion)
st.divider()
st.subheader("Record audio")
audio_record = st_audiorec()
st.write("or")
st.subheader("Upload audio")
audio_upload = st.file_uploader("Upload file", type=['wav', 'mp3', 'flac'])
st.divider()
# Process uploaded file
if audio_upload:
st.write("Your audio:")
st.audio(audio_upload, format='audio/wav')
predict = st.button("Proceed")
st.divider()
if predict:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(audio_upload.read())
temp_file_path = temp_file.name
result = process_audio(temp_file_path)
st.write("Result:")
st.subheader(result)
user_evaluation(result, st.session_state.rand_emotion)
# Process recorded audio
if audio_record:
st.write("Your audio:")
st.audio(audio_record)
predict = st.button("Proceed")
st.divider()
if predict:
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
temp_file.write(audio_record)
temp_file_path = temp_file.name
result = process_audio(temp_file_path)
st.write("Result:")
st.subheader(result)
user_evaluation(result, st.session_state.rand_emotion)