Spaces:
Runtime error
Runtime error
Alexander Seifert
commited on
Commit
·
e414a67
1
Parent(s):
cf239e0
update
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import base64
|
|
|
2 |
import os
|
3 |
|
4 |
import modal
|
@@ -11,43 +12,76 @@ run_transcription = modal.lookup("ffpub-transcription", "run_transcription")
|
|
11 |
st.set_page_config(page_title="Speech to Text Transcription App")
|
12 |
|
13 |
|
14 |
-
@st.cache
|
15 |
def transcribe(url, audio_b64):
|
16 |
return run_transcription.call(url=url, audio_b64=audio_b64)
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def run():
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
password = st.text_input("Zugriffscode (siehe oben)")
|
21 |
-
audio_file =
|
22 |
-
|
23 |
-
)
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# https://www.youtube.com/watch?v=pLAaQO1iPz0
|
29 |
-
submit_button =
|
30 |
-
label="Transkribieren"
|
|
|
|
|
31 |
)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
st.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
for seg in transcription["text"].split("\n\n"):
|
49 |
st.write(seg)
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
try:
|
|
|
1 |
import base64
|
2 |
+
import json
|
3 |
import os
|
4 |
|
5 |
import modal
|
|
|
12 |
st.set_page_config(page_title="Speech to Text Transcription App")
|
13 |
|
14 |
|
15 |
+
@st.cache(show_spinner=False)
|
16 |
def transcribe(url, audio_b64):
|
17 |
return run_transcription.call(url=url, audio_b64=audio_b64)
|
18 |
|
19 |
|
20 |
+
def password_is_correct(password):
|
21 |
+
return password in [os.environ["PASSWORD"], os.environ["ROOT_PASSWORD"]]
|
22 |
+
|
23 |
+
|
24 |
+
def input_is_ready(password, audio_file, url):
|
25 |
+
return password_is_correct(password) and (audio_file or url)
|
26 |
+
|
27 |
+
|
28 |
def run():
|
29 |
+
submit_button = False
|
30 |
+
if "is_expanded" not in st.session_state:
|
31 |
+
st.session_state["is_expanded"] = True
|
32 |
+
|
33 |
+
# expander = st.expander("Einstellungen", expanded=st.session_state["is_expanded"])
|
34 |
+
# with expander:
|
35 |
password = st.text_input("Zugriffscode (siehe oben)")
|
36 |
+
url = audio_file = None
|
37 |
+
|
38 |
+
col1, col2 = st.columns([1, 3])
|
39 |
+
type = col1.radio("", ["URL", "Datei-Upload"])
|
40 |
+
if type == "URL":
|
41 |
+
url = col2.text_input(
|
42 |
+
"URL (e.g. YouTube video, Dropbox file, etc.)",
|
43 |
+
value="",
|
44 |
+
)
|
45 |
+
else:
|
46 |
+
audio_file = col2.file_uploader(
|
47 |
+
"Datei auswählen", type=[".wav", ".mp3", ".flac", ".m4a", ".ogg"]
|
48 |
+
)
|
49 |
# https://www.youtube.com/watch?v=pLAaQO1iPz0
|
50 |
+
submit_button = col1.button(
|
51 |
+
label="⚡ Transkribieren"
|
52 |
+
+ (" (Zugriffscode inkorrekt)" if not password_is_correct(password) else ""),
|
53 |
+
disabled=(not password_is_correct(password) or (not audio_file and not url)),
|
54 |
)
|
55 |
|
56 |
+
audio_b64 = None
|
57 |
+
if audio_file or url:
|
58 |
+
with st.expander("Medien-Preview"):
|
59 |
+
if audio_file:
|
60 |
+
st.audio(audio_file)
|
61 |
+
cutoff = None if password == os.environ["ROOT_PASSWORD"] else 60_000
|
62 |
+
audio_file = AudioSegment.from_file(audio_file)[:cutoff]
|
63 |
+
audio_b64 = base64.b64encode(audio_file.export().read()).decode("ascii")
|
64 |
+
if url:
|
65 |
+
st.video(url)
|
66 |
+
|
67 |
+
if input_is_ready(password, audio_file, url) and submit_button:
|
68 |
+
# my_bar = st.progress(0)
|
69 |
+
# for percent_complete in range(100):
|
70 |
+
# time.sleep(1)
|
71 |
+
# my_bar.progress(percent_complete + 1)
|
72 |
+
|
73 |
+
with st.spinner("Transkription läuft..."):
|
74 |
+
transcription = transcribe(url, audio_b64)
|
75 |
+
|
76 |
for seg in transcription["text"].split("\n\n"):
|
77 |
st.write(seg)
|
78 |
+
|
79 |
+
st.download_button(
|
80 |
+
label="OTR-Datei herunterladen",
|
81 |
+
data=json.dumps(transcription["otr"], indent=2, ensure_ascii=False),
|
82 |
+
file_name="transkript.otr",
|
83 |
+
mime="application/json",
|
84 |
+
)
|
85 |
|
86 |
|
87 |
try:
|