Spaces:
Sleeping
Sleeping
import os | |
from transformers import pipeline | |
import gradio as gr | |
# Fetch the token from the environment | |
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN") | |
model_id = "akadriu/whisper-medium-sq" # update with your model id | |
pipe = pipeline("automatic-speech-recognition", model=model_id, token=hf_token) | |
def transcribe_speech(filepath): | |
output = pipe( | |
filepath, | |
max_new_tokens=256, | |
generate_kwargs={ | |
"task": "transcribe", | |
"language": "albanian", | |
}, # update with the language you've fine-tuned on | |
chunk_length_s=30, | |
batch_size=8, | |
) | |
return output["text"] | |
import gradio as gr | |
demo = gr.Blocks() | |
mic_transcribe = gr.Interface( | |
fn=transcribe_speech, | |
inputs=gr.Audio(sources="microphone", type="filepath"), | |
outputs=gr.outputs.Textbox(), | |
) | |
file_transcribe = gr.Interface( | |
fn=transcribe_speech, | |
inputs=gr.Audio(sources="upload", type="filepath"), | |
outputs="text", | |
) | |
with demo: | |
gr.TabbedInterface( | |
[mic_transcribe, file_transcribe], | |
["Transcribe Microphone", "Transcribe Audio File"], | |
) | |
demo.launch(debug=True) | |