Spaces:
Paused
Paused
File size: 1,376 Bytes
a3c1698 4946e6a 08e100b 0bc0be3 08e100b 0bc0be3 08e100b 0bc0be3 4946e6a 08e100b 0bc0be3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# Imports
import gradio as gr
import spaces
import torch
from transformers import pipeline
# Pre-Initialize
DEVICE = "auto"
if DEVICE == "auto":
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
print(f"[SYSTEM] | Using {DEVICE} type compute device.")
# Variables
BATCH_SIZE = 8
pipe = pipeline(task="automatic-speech-recognition", model="openai/whisper-large-v3-turbo", chunk_length_s=30, device=device)
@spaces.GPU
def transcribe(inputs, task):
if inputs is None: raise gr.Error("Invalid input.")
output = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
return output
def cloud():
print("[CLOUD] | Space maintained.")
# Initialize
with gr.Blocks(css=css) as main:
with gr.Column():
gr.Markdown("🪄 Transcribe audio to text.")
with gr.Column():
input = gr.Audio(sources="upload", type="filepath", label="Input"),
type = gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
submit = gr.Button("▶")
maintain = gr.Button("☁️")
with gr.Column():
output = gr.Textbox(lines=1, value=DEFAULT_INPUT, label="Output")
submit.click(transcribe, inputs=[input, type], outputs=[output], queue=False)
maintain.click(cloud, inputs=[], outputs=[], queue=False)
main.launch(show_api=True) |