Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
from transformers.pipelines.audio_utils import ffmpeg_read
|
5 |
+
|
6 |
+
MODEL_NAME = "openai/whisper-large-v3"
|
7 |
+
BATCH_SIZE = 8
|
8 |
+
FILE_LIMIT_MB = 1000
|
9 |
+
|
10 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
11 |
+
|
12 |
+
pipe = pipeline(
|
13 |
+
task="automatic-speech-recognition",
|
14 |
+
model=MODEL_NAME,
|
15 |
+
chunk_length_s=30,
|
16 |
+
device=device,
|
17 |
+
)
|
18 |
+
|
19 |
+
def transcribe(inputs, task):
|
20 |
+
if inputs is None:
|
21 |
+
raise gr.Error("No audio file submitted! Please upload an audio file before submitting your request.")
|
22 |
+
|
23 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
24 |
+
return text
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=transcribe,
|
28 |
+
inputs=[
|
29 |
+
gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio file"),
|
30 |
+
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
31 |
+
],
|
32 |
+
outputs="text",
|
33 |
+
layout="horizontal",
|
34 |
+
theme="huggingface",
|
35 |
+
title="Whisper Large V3: Transcribe Audio",
|
36 |
+
description=(
|
37 |
+
"Transcribe audio files with the click of a button! This demo uses the OpenAI Whisper"
|
38 |
+
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
39 |
+
" of arbitrary length."
|
40 |
+
),
|
41 |
+
allow_flagging="never",
|
42 |
+
)
|
43 |
+
|
44 |
+
demo.launch(enable_queue=True)
|