Spaces:
Sleeping
Sleeping
File size: 1,205 Bytes
68e0a01 ef45f89 8542e1c 68e0a01 5c3c208 68e0a01 5c3c208 8542e1c 5c3c208 936827b 5c3c208 2e518ce 5c3c208 |
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 46 47 48 |
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
import gradio as gr
# import spaces
# from datasets import load_dataset
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model_id = "distil-whisper/distil-large-v3"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
)
model.to(device)
processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
max_new_tokens=128,
torch_dtype=torch_dtype,
device=device,
)
# Function to process audio input and transcribe it
# @spaces.GPU
def transcribe(audio):
# Load and preprocess the audio
result = pipe(audio)["text"]
return result
# Gradio interface
interface = gr.Interface(
fn=transcribe,
inputs=gr.Audio(sources="microphone", type="filepath"),
outputs="text",
title="Whisper Voice Transcription with Hugging Face"
)
# Launch the app
#
interface.launch()
|