Alexander Seifert
add passwords again
b602cc6
raw
history blame
1.73 kB
import base64
import os
import modal
import streamlit as st
from loguru import logger
from pydub import AudioSegment
run_transcription = modal.lookup("ffpub-transcription", "run_transcription")
st.set_page_config(page_title="Speech to Text Transcription App")
@st.cache
def transcribe(url, audio_b64):
return run_transcription.call(url=url, audio_b64=audio_b64)
def run():
password = st.text_input("Zugriffscode (siehe oben)")
audio_file = st.file_uploader(
"Datei auswählen", type=[".wav", ".mp3", ".flac", ".m4a", ".ogg"]
)
url = st.text_input(
"URL (e.g. YouTube video, Dropbox file, etc.)",
value="",
)
# https://www.youtube.com/watch?v=pLAaQO1iPz0
submit_button = st.button(
label="Transkribieren", disabled=(not audio_file and not url)
)
if password not in [os.environ["PASSWORD"], os.environ["ROOT_PASSWORD"]]:
st.error("Zugriffscode ist falsch.")
st.stop()
if audio_file is not None:
st.audio(audio_file)
cutoff = None if password == os.environ["ROOT_PASSWORD"] else 60_000
audio_file = AudioSegment.from_file(audio_file)[:cutoff]
audio_b64 = base64.b64encode(audio_file.export().read()).decode("ascii")
if url:
st.video(url)
if submit_button:
audio_b64 = None
transcription = transcribe(url, audio_b64)
for seg in transcription["text"].split("\n\n"):
st.write(seg)
st.json(transcription)
try:
run()
except Exception as e:
logger.error(e)
st.error(
"Leider ist ein unerwarter Fehler aufgetreten. Ich könnte mir das Problem sofort ansehen, Sie erreichen mich unter alexander.seifert@gmail.com"
)