Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import json
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
import modal
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
from loguru import logger
|
| 8 |
from pydub import AudioSegment
|
|
@@ -17,8 +18,13 @@ run_transcription = modal.Function.lookup(
|
|
| 17 |
st.set_page_config(page_title="Speech to Text Transcription App")
|
| 18 |
|
| 19 |
|
|
|
|
| 20 |
def transcribe(url, audio_b64, cutoff):
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def password_is_correct(password):
|
|
@@ -61,6 +67,10 @@ def run():
|
|
| 61 |
"URL (e.g. YouTube video, Dropbox file, etc.)",
|
| 62 |
value="",
|
| 63 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
audio_file = col2.file_uploader(
|
| 66 |
"Datei auswählen", type=[".wav", ".mp3", ".flac", ".m4a", ".ogg"]
|
|
@@ -73,14 +83,16 @@ def run():
|
|
| 73 |
)
|
| 74 |
|
| 75 |
cutoff = audio_b64 = None
|
| 76 |
-
cutoff =
|
| 77 |
if audio_file or url:
|
| 78 |
# with st.expander(("Audio" if audio_file else "Video") + " abspielen"):
|
| 79 |
if audio_file:
|
| 80 |
st.audio(audio_file)
|
| 81 |
-
audio_file = AudioSegment.from_file(audio_file)[:cutoff]
|
| 82 |
audio_b64 = base64.b64encode(audio_file.export().read()).decode("ascii")
|
| 83 |
if url:
|
|
|
|
|
|
|
| 84 |
st.video(url)
|
| 85 |
|
| 86 |
if input_is_ready(password, audio_file, url) and submit_button:
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
import modal
|
| 6 |
+
import requests
|
| 7 |
import streamlit as st
|
| 8 |
from loguru import logger
|
| 9 |
from pydub import AudioSegment
|
|
|
|
| 18 |
st.set_page_config(page_title="Speech to Text Transcription App")
|
| 19 |
|
| 20 |
|
| 21 |
+
@st.cache_data(show_spinner=False)
|
| 22 |
def transcribe(url, audio_b64, cutoff):
|
| 23 |
+
payload = {"url": url, "audio_b64": audio_b64, "cutoff": cutoff}
|
| 24 |
+
response = requests.post(
|
| 25 |
+
"https://aseifert--ffpub-transcription-fastapi-app.modal.run/transcribe", json=payload
|
| 26 |
+
)
|
| 27 |
+
return response.json()
|
| 28 |
|
| 29 |
|
| 30 |
def password_is_correct(password):
|
|
|
|
| 67 |
"URL (e.g. YouTube video, Dropbox file, etc.)",
|
| 68 |
value="",
|
| 69 |
)
|
| 70 |
+
if "youtu" in url:
|
| 71 |
+
url = url.replace("youtu.be/", "youtube.com/watch?v=")
|
| 72 |
+
elif "dropbox" in url:
|
| 73 |
+
url = url.replace("dl=0", "raw=1")
|
| 74 |
else:
|
| 75 |
audio_file = col2.file_uploader(
|
| 76 |
"Datei auswählen", type=[".wav", ".mp3", ".flac", ".m4a", ".ogg"]
|
|
|
|
| 83 |
)
|
| 84 |
|
| 85 |
cutoff = audio_b64 = None
|
| 86 |
+
cutoff = None if password in ROOT_PASSWORDS else 60
|
| 87 |
if audio_file or url:
|
| 88 |
# with st.expander(("Audio" if audio_file else "Video") + " abspielen"):
|
| 89 |
if audio_file:
|
| 90 |
st.audio(audio_file)
|
| 91 |
+
audio_file = AudioSegment.from_file(audio_file)[: cutoff * 1000 if cutoff else None]
|
| 92 |
audio_b64 = base64.b64encode(audio_file.export().read()).decode("ascii")
|
| 93 |
if url:
|
| 94 |
+
if url == "https://www.youtube.com/watch?v=6UONiGMmbS4":
|
| 95 |
+
cutoff = None
|
| 96 |
st.video(url)
|
| 97 |
|
| 98 |
if input_is_ready(password, audio_file, url) and submit_button:
|