Casper / app.py
MaximilianChen's picture
Update app.py
48a358e
raw
history blame contribute delete
764 Bytes
from transformers import pipeline
import gradio as gr
import torch
device = "cuda:0" if torch.cuda.is_available() else "cpu"
asr = pipeline(
"automatic-speech-recognition",
model="MaximilianChen/Casper",
chunk_length_s=30,
device=device,
)
def transcribe_audio(mic=None, file=None):
if mic is not None:
audio = mic
elif file is not None:
audio = file
else:
return "You must either provide a mic recording or a file"
transcription = asr(audio)["text"]
return transcription
gr.Interface(
fn=transcribe_audio,
inputs=[
gr.Audio(source="microphone", type="filepath", optional=True),
gr.Audio(source="upload", type="filepath", optional=True),
],
outputs="text",
).launch()