kozak-vaclav's picture
Create app.py
5abfa23 verified
raw
history blame
1.02 kB
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()