File size: 2,591 Bytes
f427fe9
ae8fbd2
f427fe9
ae8fbd2
 
 
 
 
b815c4a
ae8fbd2
 
f427fe9
 
ae8fbd2
6d2ca12
ae8fbd2
6d2ca12
ae8fbd2
 
 
6d2ca12
353faef
 
 
 
6d2ca12
 
 
ae8fbd2
353faef
6d2ca12
 
 
e564472
 
 
353faef
 
 
e564472
ae8fbd2
 
 
 
6d2ca12
 
e564472
 
 
 
6d2ca12
e564472
 
 
353faef
 
 
ae8fbd2
 
 
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
import streamlit as st
import pickle
from io import BytesIO
import pyperclip
from audio_processing import detect_language, process_long_audio, load_and_resample_audio
from model_utils import load_models
from config import SAMPLING_RATE
from llm_utils import generate_answer, summarize_transcript

# Load models at startup
load_models()

# Title of the app
st.title("Audio Player with Live Transcription and Q&A")

# ... (previous code remains the same)

def copy_to_clipboard(text):
    pyperclip.copy(text)
    st.success("Copied to clipboard!")

# Display uploaded files and options
if 'audio_files' in st.session_state and st.session_state.audio_files:
    for i, uploaded_file in enumerate(st.session_state.audio_files):
        col1, col2 = st.columns([1, 3])

        with col1:
            st.write(f"**File name**: {uploaded_file.name}")
            st.audio(uploaded_file, format=uploaded_file.type)
            st.write(f"**Detected Language**: {st.session_state.detected_languages[i]}")

        with col2:
            if st.button(f"Transcribe {uploaded_file.name}"):
                with st.spinner("Transcribing..."):
                    transcription = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE)
                    st.session_state.transcriptions[i] = transcription

            if st.session_state.transcriptions.get(i):
                st.write("**Transcription**:")
                st.write(st.session_state.transcriptions[i])
                if st.button("Copy Transcription", key=f"copy_transcription_{i}"):
                    copy_to_clipboard(st.session_state.transcriptions[i])

                # ... (summarization and Q&A code remains the same)

            if st.button(f"Translate {uploaded_file.name}"):
                with st.spinner("Translating..."):
                    with open('languages.pkl', 'rb') as f:
                        lang_dict = pickle.load(f)
                    detected_language_name = lang_dict[st.session_state.detected_languages[i]]

                    translation = process_long_audio(st.session_state.waveforms[i], SAMPLING_RATE, task="translate",
                                                     language=detected_language_name)
                    st.session_state.translations[i] = translation

            if st.session_state.translations.get(i):
                st.write("**Translation**:")
                st.write(st.session_state.translations[i])
                if st.button("Copy Translation", key=f"copy_translation_{i}"):
                    copy_to_clipboard(st.session_state.translations[i])