Leo Liu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -96,36 +96,32 @@ def main():
|
|
96 |
</div>
|
97 |
""", unsafe_allow_html=True)
|
98 |
|
99 |
-
|
100 |
# Audio file uploader
|
101 |
uploaded_file = st.file_uploader("π€ Please upload your Cantonese customer service audio file", type=["wav", "mp3", "flac"])
|
102 |
|
103 |
if uploaded_file is not None:
|
104 |
file_type = magic.from_buffer(uploaded_file.read(), mime=True)
|
105 |
-
uploaded_file.seek(0)
|
106 |
if not file_type.startswith("audio/"):
|
107 |
st.error("β οΈ Sorry, the uploaded file format is not supported. Please upload an audio file.")
|
108 |
return
|
109 |
|
110 |
-
|
111 |
st.audio(uploaded_file, format="audio/wav")
|
112 |
temp_audio_path = "uploaded_audio.wav"
|
113 |
with open(temp_audio_path, "wb") as f:
|
114 |
f.write(uploaded_file.getbuffer())
|
115 |
|
116 |
progress_bar = st.progress(0)
|
117 |
-
status_container = st.empty()
|
118 |
|
119 |
# Step 1: Audio transcription
|
120 |
-
|
121 |
-
with st.spinner('π Transcribing, please wait...'):
|
122 |
transcript = transcribe_audio(temp_audio_path)
|
123 |
progress_bar.progress(50)
|
124 |
st.write("**Transcript:**", transcript)
|
125 |
|
126 |
# Step 2: Sentiment Analysis
|
127 |
-
|
128 |
-
|
129 |
progress_bar.progress(100)
|
130 |
st.write("**Sentiment Analysis Result:**", quality_rating)
|
131 |
|
|
|
96 |
</div>
|
97 |
""", unsafe_allow_html=True)
|
98 |
|
|
|
99 |
# Audio file uploader
|
100 |
uploaded_file = st.file_uploader("π€ Please upload your Cantonese customer service audio file", type=["wav", "mp3", "flac"])
|
101 |
|
102 |
if uploaded_file is not None:
|
103 |
file_type = magic.from_buffer(uploaded_file.read(), mime=True)
|
104 |
+
uploaded_file.seek(0)
|
105 |
if not file_type.startswith("audio/"):
|
106 |
st.error("β οΈ Sorry, the uploaded file format is not supported. Please upload an audio file.")
|
107 |
return
|
108 |
|
|
|
109 |
st.audio(uploaded_file, format="audio/wav")
|
110 |
temp_audio_path = "uploaded_audio.wav"
|
111 |
with open(temp_audio_path, "wb") as f:
|
112 |
f.write(uploaded_file.getbuffer())
|
113 |
|
114 |
progress_bar = st.progress(0)
|
|
|
115 |
|
116 |
# Step 1: Audio transcription
|
117 |
+
with st.spinner('π Step 1: Transcribing audio, please wait... '):
|
|
|
118 |
transcript = transcribe_audio(temp_audio_path)
|
119 |
progress_bar.progress(50)
|
120 |
st.write("**Transcript:**", transcript)
|
121 |
|
122 |
# Step 2: Sentiment Analysis
|
123 |
+
with st.spinner('π§ββοΈ Step 2: Analyzing sentiment, please wait... '):
|
124 |
+
quality_rating = rate_quality(transcript)
|
125 |
progress_bar.progress(100)
|
126 |
st.write("**Sentiment Analysis Result:**", quality_rating)
|
127 |
|