Spaces:
Runtime error
Runtime error
Commit
•
dc523cd
1
Parent(s):
fc211fe
Integrate code from openai/whisper
Browse files
app.py
CHANGED
@@ -1,7 +1,41 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def greet(name):
|
4 |
return "Hello " + name + "!!"
|
5 |
|
6 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
MODEL_NAME = "openai/whisper-tiny"
|
5 |
+
|
6 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
7 |
+
|
8 |
+
pipe = pipeline(
|
9 |
+
task="automatic-speech-recognition",
|
10 |
+
model=MODEL_NAME,
|
11 |
+
chunk_length_s=30,
|
12 |
+
device=device,
|
13 |
+
)
|
14 |
+
|
15 |
+
def transcribe(inputs, task):
|
16 |
+
if inputs is None:
|
17 |
+
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
18 |
+
|
19 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
20 |
+
return text
|
21 |
|
22 |
def greet(name):
|
23 |
return "Hello " + name + "!!"
|
24 |
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=transcribe,
|
27 |
+
inputs=[
|
28 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
29 |
+
],
|
30 |
+
outputs="text",
|
31 |
+
layout="horizontal",
|
32 |
+
theme="huggingface",
|
33 |
+
title="test",
|
34 |
+
description=(
|
35 |
+
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
36 |
+
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
37 |
+
" of arbitrary length."
|
38 |
+
),
|
39 |
+
allow_flagging="never",
|
40 |
+
)
|
41 |
iface.launch()
|