Spaces:
Sleeping
Sleeping
Update app.py -- added copy paste text functionality
Browse files
app.py
CHANGED
@@ -1,15 +1,20 @@
|
|
1 |
-
import
|
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")
|
@@ -39,14 +44,13 @@ if submit_button and uploaded_files is not None:
|
|
39 |
# Display uploaded files and options
|
40 |
if 'audio_files' in st.session_state and st.session_state.audio_files:
|
41 |
for i, uploaded_file in enumerate(st.session_state.audio_files):
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
st.write(f"**File name**: {uploaded_file.name}")
|
46 |
-
st.audio(uploaded_file, format=uploaded_file.type)
|
47 |
-
st.write(f"**Detected Language**: {st.session_state.detected_languages[i]}")
|
48 |
|
49 |
-
with
|
50 |
if st.button(f"Transcribe {uploaded_file.name}"):
|
51 |
with st.spinner("Transcribing..."):
|
52 |
transcription = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE)
|
@@ -54,8 +58,10 @@ if 'audio_files' in st.session_state and st.session_state.audio_files:
|
|
54 |
|
55 |
if st.session_state.transcriptions.get(i):
|
56 |
st.write("**Transcription**:")
|
57 |
-
st.
|
|
|
58 |
|
|
|
59 |
if st.button(f"Translate {uploaded_file.name}"):
|
60 |
with st.spinner("Translating..."):
|
61 |
with open('languages.pkl', 'rb') as f:
|
@@ -65,7 +71,7 @@ if 'audio_files' in st.session_state and st.session_state.audio_files:
|
|
65 |
translation = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE, task="translate",
|
66 |
language=detected_language_name)
|
67 |
st.session_state.translations[i] = translation
|
68 |
-
|
69 |
if st.session_state.translations.get(i):
|
70 |
st.write("**Translation**:")
|
71 |
-
st.
|
|
|
|
1 |
+
import torch
|
2 |
import pickle
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
from io import BytesIO
|
|
|
|
|
6 |
from config import SAMPLING_RATE
|
7 |
+
from model_utils import load_models
|
8 |
+
from audio_processing import detect_language, process_long_audio, load_and_resample_audio
|
9 |
+
|
10 |
+
# Clear GPU cache
|
11 |
+
torch.cuda.empty_cache()
|
12 |
|
13 |
# Load models at startup
|
14 |
load_models()
|
15 |
|
16 |
# Title of the app
|
17 |
+
st.title("Audio Player with Live Transcription and Translation")
|
18 |
|
19 |
# Sidebar for file uploader and submit button
|
20 |
st.sidebar.header("Upload Audio Files")
|
|
|
44 |
# Display uploaded files and options
|
45 |
if 'audio_files' in st.session_state and st.session_state.audio_files:
|
46 |
for i, uploaded_file in enumerate(st.session_state.audio_files):
|
47 |
+
st.write(f"**File name**: {uploaded_file.name}")
|
48 |
+
st.audio(uploaded_file, format=uploaded_file.type)
|
49 |
+
st.write(f"**Detected Language**: {st.session_state.detected_languages[i]}")
|
50 |
|
51 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
52 |
|
53 |
+
with col1:
|
54 |
if st.button(f"Transcribe {uploaded_file.name}"):
|
55 |
with st.spinner("Transcribing..."):
|
56 |
transcription = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE)
|
|
|
58 |
|
59 |
if st.session_state.transcriptions.get(i):
|
60 |
st.write("**Transcription**:")
|
61 |
+
st.text_area("", st.session_state.transcriptions[i], height=200, key=f"transcription_{i}")
|
62 |
+
st.markdown(f'<div style="text-align: right;"><a href="data:text/plain;charset=UTF-8,{st.session_state.transcriptions[i]}" download="transcription_{uploaded_file.name}.txt">Download Transcription</a></div>', unsafe_allow_html=True)
|
63 |
|
64 |
+
with col2:
|
65 |
if st.button(f"Translate {uploaded_file.name}"):
|
66 |
with st.spinner("Translating..."):
|
67 |
with open('languages.pkl', 'rb') as f:
|
|
|
71 |
translation = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE, task="translate",
|
72 |
language=detected_language_name)
|
73 |
st.session_state.translations[i] = translation
|
|
|
74 |
if st.session_state.translations.get(i):
|
75 |
st.write("**Translation**:")
|
76 |
+
st.text_area("", st.session_state.translations[i], height=200, key=f"translation_{i}")
|
77 |
+
st.markdown(f'<div style="text-align: right;"><a href="data:text/plain;charset=UTF-8,{st.session_state.translations[i]}" download="translation_{uploaded_file.name}.txt">Download Translation</a></div>', unsafe_allow_html=True)
|