Spaces:
Runtime error
Runtime error
Alexander Seifert
commited on
Commit
•
56cc953
1
Parent(s):
161a5eb
cut at 60 secs
Browse files
app.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
import base64
|
2 |
import os
|
3 |
import time
|
|
|
4 |
|
5 |
import banana_dev as banana
|
6 |
import gradio as gr
|
7 |
from loguru import logger
|
|
|
8 |
|
9 |
api_key = os.environ["BANANA_API_KEY"]
|
10 |
model_key = os.environ["BANANA_MODEL_KEY"]
|
11 |
password = os.environ["PASSWORD"]
|
12 |
|
13 |
|
14 |
-
def transcribe(
|
15 |
-
if
|
16 |
-
|
17 |
-
audio = f.read()
|
18 |
-
audio_b64 = base64.b64encode(audio).decode("ISO-8859-1")
|
19 |
payload = {"audio_b64": audio_b64}
|
20 |
else:
|
21 |
payload = {"url": url}
|
22 |
-
# payload["email"] = email
|
23 |
response = banana.run(api_key, model_key, payload)
|
24 |
print(response)
|
25 |
|
@@ -48,7 +47,7 @@ def run_demo(password, microphone, file_upload):
|
|
48 |
file = microphone if microphone is not None else file_upload
|
49 |
|
50 |
start = time.time()
|
51 |
-
transcription = transcribe(file)
|
52 |
logger.info(f"transcription took {time.time()-start:.3f}s")
|
53 |
return "\n\n".join([seg["text"].strip() for seg in transcription["segments"]])
|
54 |
|
|
|
1 |
import base64
|
2 |
import os
|
3 |
import time
|
4 |
+
from io import BytesIO
|
5 |
|
6 |
import banana_dev as banana
|
7 |
import gradio as gr
|
8 |
from loguru import logger
|
9 |
+
from pydub import AudioSegment
|
10 |
|
11 |
api_key = os.environ["BANANA_API_KEY"]
|
12 |
model_key = os.environ["BANANA_MODEL_KEY"]
|
13 |
password = os.environ["PASSWORD"]
|
14 |
|
15 |
|
16 |
+
def transcribe(audio=None, url=None):
|
17 |
+
if audio:
|
18 |
+
audio_b64 = base64.b64encode(audio.export().read()).decode("ascii")
|
|
|
|
|
19 |
payload = {"audio_b64": audio_b64}
|
20 |
else:
|
21 |
payload = {"url": url}
|
|
|
22 |
response = banana.run(api_key, model_key, payload)
|
23 |
print(response)
|
24 |
|
|
|
47 |
file = microphone if microphone is not None else file_upload
|
48 |
|
49 |
start = time.time()
|
50 |
+
transcription = transcribe(AudioSegment.from_file(file)[:60_000])
|
51 |
logger.info(f"transcription took {time.time()-start:.3f}s")
|
52 |
return "\n\n".join([seg["text"].strip() for seg in transcription["segments"]])
|
53 |
|