Spaces:
Runtime error
Runtime error
Alexander Seifert commited on
Commit ·
6e406cd
1
Parent(s): 721a7b8
add url option
Browse files
app.py
CHANGED
|
@@ -84,38 +84,32 @@ def transcribe(audio=None, url=None):
|
|
| 84 |
return response["modelOutputs"][0]
|
| 85 |
|
| 86 |
|
| 87 |
-
def run_demo(password,
|
| 88 |
if password not in [os.environ["PASSWORD"], os.environ["ROOT_PASSWORD"]]:
|
| 89 |
raise gr.Error("Der Zugriffscode ist falsch.")
|
| 90 |
|
| 91 |
-
if (
|
| 92 |
logger.warning(
|
| 93 |
-
"Achtung: Sie haben sowohl eine
|
| 94 |
" Wir verwenden nur die Datei, die Sie hochgeladen haben."
|
| 95 |
)
|
| 96 |
|
| 97 |
-
elif (
|
| 98 |
raise gr.Error(
|
| 99 |
-
"Sie müssen entweder eine
|
| 100 |
)
|
| 101 |
|
| 102 |
-
file = microphone if microphone is not None else file_upload
|
| 103 |
-
|
| 104 |
start = time.time()
|
| 105 |
-
cutoff = None if password == os.environ["ROOT_PASSWORD"] else 60_000
|
| 106 |
-
transcription = transcribe(AudioSegment.from_file(file)[:cutoff])
|
| 107 |
-
|
| 108 |
-
segments = []
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
logger.info(f"transcription took {time.time()-start:.3f}s")
|
| 118 |
-
return "
|
| 119 |
|
| 120 |
|
| 121 |
demo = gr.Interface(
|
|
@@ -123,7 +117,8 @@ demo = gr.Interface(
|
|
| 123 |
inputs=[
|
| 124 |
# gr.Textbox(label="Email", type="email"),
|
| 125 |
gr.Textbox(label="Zugriffscode (siehe oben)"),
|
| 126 |
-
gr.Audio(source="microphone", type="filepath", label="Aufnehmen"),
|
|
|
|
| 127 |
gr.Audio(source="upload", type="filepath", label="Datei hochladen"),
|
| 128 |
],
|
| 129 |
outputs=gr.Textbox(label="Automatisches Transkript"),
|
|
|
|
| 84 |
return response["modelOutputs"][0]
|
| 85 |
|
| 86 |
|
| 87 |
+
def run_demo(password, url, file_upload):
|
| 88 |
if password not in [os.environ["PASSWORD"], os.environ["ROOT_PASSWORD"]]:
|
| 89 |
raise gr.Error("Der Zugriffscode ist falsch.")
|
| 90 |
|
| 91 |
+
if (url is not None) and (file_upload is not None):
|
| 92 |
logger.warning(
|
| 93 |
+
"Achtung: Sie haben sowohl eine URL angegeben als auch eine Datei hochgeladen."
|
| 94 |
" Wir verwenden nur die Datei, die Sie hochgeladen haben."
|
| 95 |
)
|
| 96 |
|
| 97 |
+
elif (url is None) and (file_upload is None):
|
| 98 |
raise gr.Error(
|
| 99 |
+
"Sie müssen entweder eine URL angeben oder eine Datei hochladen."
|
| 100 |
)
|
| 101 |
|
|
|
|
|
|
|
| 102 |
start = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
if file_upload is not None:
|
| 105 |
+
cutoff = None if password == os.environ["ROOT_PASSWORD"] else 60_000
|
| 106 |
+
audio = AudioSegment.from_file(file_upload, format="mp3")[:cutoff]
|
| 107 |
+
transcription = transcribe(audio=audio, url=None)
|
| 108 |
+
else:
|
| 109 |
+
transcription = transcribe(audio=None, url=url)
|
| 110 |
|
| 111 |
logger.info(f"transcription took {time.time()-start:.3f}s")
|
| 112 |
+
return transcription["text"]
|
| 113 |
|
| 114 |
|
| 115 |
demo = gr.Interface(
|
|
|
|
| 117 |
inputs=[
|
| 118 |
# gr.Textbox(label="Email", type="email"),
|
| 119 |
gr.Textbox(label="Zugriffscode (siehe oben)"),
|
| 120 |
+
# gr.Audio(source="microphone", type="filepath", label="Aufnehmen"),
|
| 121 |
+
gr.Textbox(label="URL (z.B. YouTube-Video, Dropbox-Datei, etc.)"),
|
| 122 |
gr.Audio(source="upload", type="filepath", label="Datei hochladen"),
|
| 123 |
],
|
| 124 |
outputs=gr.Textbox(label="Automatisches Transkript"),
|