Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
•
accb4e2
1
Parent(s):
7034aab
Update app.py
Browse files
app.py
CHANGED
@@ -19,36 +19,38 @@ def transcribe(file, task, return_timestamps):
|
|
19 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
20 |
text = outputs["text"]
|
21 |
timestamps = outputs["chunks"]
|
22 |
-
|
23 |
if return_timestamps==True:
|
24 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
25 |
-
|
26 |
else:
|
27 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
28 |
-
|
29 |
-
text = "\n".join(str(feature) for feature in timestamps)
|
30 |
-
return text
|
31 |
|
|
|
|
|
|
|
32 |
|
33 |
file_transcribe = gr.Interface(
|
34 |
fn=transcribe,
|
35 |
inputs=[
|
36 |
-
gr.
|
37 |
-
gr.
|
38 |
-
gr.
|
39 |
],
|
40 |
-
outputs="
|
41 |
-
|
42 |
-
|
43 |
title="Whisper Demo: Transcribe Audio",
|
44 |
description=(
|
45 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
46 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
47 |
" of arbitrary length."
|
48 |
),
|
49 |
-
|
50 |
cache_examples=True,
|
51 |
allow_flagging="never",
|
|
|
52 |
)
|
53 |
|
54 |
-
file_transcribe.
|
|
|
|
19 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
20 |
text = outputs["text"]
|
21 |
timestamps = outputs["chunks"]
|
22 |
+
|
23 |
if return_timestamps==True:
|
24 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
25 |
+
|
26 |
else:
|
27 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
|
|
|
|
|
|
28 |
|
29 |
+
text = "<br>".join(str(feature) for feature in timestamps)
|
30 |
+
text = f"<h4>Transcription</h4><div style='overflow-y: scroll; height: 400px;'>{text}</div>"
|
31 |
+
return file, text
|
32 |
|
33 |
file_transcribe = gr.Interface(
|
34 |
fn=transcribe,
|
35 |
inputs=[
|
36 |
+
gr.Audio(source="upload", label="Audio file", type="filepath"),
|
37 |
+
gr.Radio(["transcribe"], label="Task", value="transcribe"),
|
38 |
+
gr.Checkbox(value=True, label="Return timestamps"),
|
39 |
],
|
40 |
+
outputs= [gr.Audio(label="Processed Audio", type="filepath"),
|
41 |
+
gr.outputs.HTML("text")
|
42 |
+
],
|
43 |
title="Whisper Demo: Transcribe Audio",
|
44 |
description=(
|
45 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
46 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
47 |
" of arbitrary length."
|
48 |
),
|
49 |
+
|
50 |
cache_examples=True,
|
51 |
allow_flagging="never",
|
52 |
+
|
53 |
)
|
54 |
|
55 |
+
file_transcribe.queue(concurrency_count=3)
|
56 |
+
file_transcribe.launch(share=True, debug = True)
|