Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,40 @@
|
|
1 |
import streamlit as st
|
2 |
import pickle
|
3 |
from io import BytesIO
|
4 |
-
import pyperclip
|
5 |
from audio_processing import detect_language, process_long_audio, load_and_resample_audio
|
6 |
from model_utils import load_models
|
7 |
from config import SAMPLING_RATE
|
8 |
-
# from llm_utils import generate_answer, summarize_transcript
|
9 |
|
10 |
# Load models at startup
|
11 |
load_models()
|
12 |
|
13 |
# Title of the app
|
14 |
-
st.title("Audio Player with Live Transcription
|
15 |
|
16 |
-
#
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Display uploaded files and options
|
23 |
if 'audio_files' in st.session_state and st.session_state.audio_files:
|
@@ -38,10 +55,6 @@ if 'audio_files' in st.session_state and st.session_state.audio_files:
|
|
38 |
if st.session_state.transcriptions.get(i):
|
39 |
st.write("**Transcription**:")
|
40 |
st.write(st.session_state.transcriptions[i])
|
41 |
-
if st.button("Copy Transcription", key=f"copy_transcription_{i}"):
|
42 |
-
copy_to_clipboard(st.session_state.transcriptions[i])
|
43 |
-
|
44 |
-
# ... (summarization and Q&A code remains the same)
|
45 |
|
46 |
if st.button(f"Translate {uploaded_file.name}"):
|
47 |
with st.spinner("Translating..."):
|
@@ -55,6 +68,4 @@ if 'audio_files' in st.session_state and st.session_state.audio_files:
|
|
55 |
|
56 |
if st.session_state.translations.get(i):
|
57 |
st.write("**Translation**:")
|
58 |
-
st.write(st.session_state.translations[i])
|
59 |
-
if st.button("Copy Translation", key=f"copy_translation_{i}"):
|
60 |
-
copy_to_clipboard(st.session_state.translations[i])
|
|
|
1 |
import streamlit as st
|
2 |
import pickle
|
3 |
from io import BytesIO
|
|
|
4 |
from audio_processing import detect_language, process_long_audio, load_and_resample_audio
|
5 |
from model_utils import load_models
|
6 |
from config import SAMPLING_RATE
|
|
|
7 |
|
8 |
# Load models at startup
|
9 |
load_models()
|
10 |
|
11 |
# Title of the app
|
12 |
+
st.title("Audio Player with Live Transcription")
|
13 |
|
14 |
+
# Sidebar for file uploader and submit button
|
15 |
+
st.sidebar.header("Upload Audio Files")
|
16 |
+
uploaded_files = st.sidebar.file_uploader("Choose audio files", type=["mp3", "wav"], accept_multiple_files=True)
|
17 |
+
submit_button = st.sidebar.button("Submit")
|
18 |
|
19 |
+
# Session state to hold data
|
20 |
+
if 'audio_files' not in st.session_state:
|
21 |
+
st.session_state.audio_files = []
|
22 |
+
st.session_state.transcriptions = {}
|
23 |
+
st.session_state.translations = {}
|
24 |
+
st.session_state.detected_languages = []
|
25 |
+
st.session_state.waveforms = []
|
26 |
+
|
27 |
+
# Process uploaded files
|
28 |
+
if submit_button and uploaded_files is not None:
|
29 |
+
st.session_state.audio_files = uploaded_files
|
30 |
+
st.session_state.detected_languages = []
|
31 |
+
st.session_state.waveforms = []
|
32 |
+
|
33 |
+
for uploaded_file in uploaded_files:
|
34 |
+
waveform = load_and_resample_audio(BytesIO(uploaded_file.read()))
|
35 |
+
st.session_state.waveforms.append(waveform)
|
36 |
+
detected_language = detect_language(waveform)
|
37 |
+
st.session_state.detected_languages.append(detected_language)
|
38 |
|
39 |
# Display uploaded files and options
|
40 |
if 'audio_files' in st.session_state and st.session_state.audio_files:
|
|
|
55 |
if st.session_state.transcriptions.get(i):
|
56 |
st.write("**Transcription**:")
|
57 |
st.write(st.session_state.transcriptions[i])
|
|
|
|
|
|
|
|
|
58 |
|
59 |
if st.button(f"Translate {uploaded_file.name}"):
|
60 |
with st.spinner("Translating..."):
|
|
|
68 |
|
69 |
if st.session_state.translations.get(i):
|
70 |
st.write("**Translation**:")
|
71 |
+
st.write(st.session_state.translations[i])
|
|
|
|