Spaces:
Sleeping
Sleeping
File size: 1,022 Bytes
5abfa23 |
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 |
import gradio as gr
import tensorflow as tf
from transformers import Wav2Vec2Processor, TFWav2Vec2Model
import librosa
# Load the model and processor
processor = Wav2Vec2Processor.from_pretrained("openai/whisper-tiny")
model = TFWav2Vec2Model.from_pretrained("kobrasoft/kobraspeech-rnn-cs")
def transcribe(audio):
# Load audio
audio, rate = librosa.load(audio, sr=16000)
# Process audio
inputs = processor(audio, sampling_rate=rate, return_tensors="tf", padding="longest")
logits = model(inputs.input_values).logits
# Decode the logits
predicted_ids = tf.argmax(logits, axis=-1)
transcription = processor.batch_decode(predicted_ids)[0]
return transcription
# Create Gradio interface
iface = gr.Interface(
fn=transcribe,
inputs=gr.inputs.Audio(source="microphone", type="filepath"),
outputs="text",
title="ASR Model Demo",
description="Upload an audio file or record your voice to get the transcription."
)
if __name__ == "__main__":
iface.launch()
|