-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
86 lines (74 loc) · 3.24 KB
/
streamlit_app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import streamlit as st
from src.youtube_downloader import youtube_downloader
from src.speech_to_text import process_file
from src.file_management import st_save_uploaded_file, create_dir_if_not_exists
def app():
# Set up page
st.set_page_config(
page_title=st.secrets["page"]["page_title"],
page_icon=st.secrets["page"]["page_icon"],
layout=st.secrets["page"]["layout"])
st.markdown(st.secrets["page"]["hide_menu_style"], unsafe_allow_html=True)
st.markdown(st.secrets["page"]["footer"], unsafe_allow_html=True)
# Session State Initialization
if 'processed' not in st.session_state:
st.session_state['processed'] = False
if 'file_path' not in st.session_state:
st.session_state['file_path'] = ""
if 'done' not in st.session_state:
st.session_state['done'] = False
# database path
database_path = st.secrets["data"]["database_path"]
create_dir_if_not_exists(database_path)
# Header
st.image("./assets/images/banner.png")
st.markdown(open("./assets/text/introduction.md",
'r').read(), unsafe_allow_html=True)
# choose an input method
choice = st.radio(
"Choose an input method:",
("Enter a YouTube link", "Upload a file"),
index=0,
format_func=lambda x: "📁 " + x if x == "Upload a file" else "🔗 " + x
)
# Create a file uploader widget
if choice == "Upload a file":
uploaded_file = st.file_uploader(
"Upload a file",
type=["wav", "flac"],
accept_multiple_files=False
)
if uploaded_file is not None:
# Save uploaded file to disk
st_save_uploaded_file(uploaded_file, database_path)
# Process downloaded file
if st.button("Process File"):
with st.spinner('Processing file...'):
results = process_file(os.path.join(
database_path, uploaded_file.name))
st.text_area("Speaker's script:", results, height=512)
st.session_state["done"] = True
# Create a text area widget for YouTube link
elif choice == "Enter a YouTube link":
youtube_link = st.text_input("Enter a YouTube link")
if youtube_link:
if not st.session_state['processed']:
if youtube_link.find("list") == -1:
with st.spinner('Donwloading from Youtube'):
file_path = youtube_downloader(
youtube_link, database_path)
st.session_state['file_path'] = file_path
st.session_state['processed'] = True
if youtube_link.find("list") != -1:
st.warning(
"This page doesn't work with playlist, please give simple video url.")
# Process downloaded file
if st.session_state['file_path'] != "":
if st.button("Process File"):
with st.spinner('Processing file...'):
results = process_file(st.session_state['file_path'])
st.text_area("Speaker's script:", results, height=2048)
st.session_state["done"] = True
if __name__ == "__main__":
app()