import gradio as gr from transformers import pipeline # Load the Automatic Speech Recognition (ASR) model for Finnish # asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small") asr_model = pipeline("automatic-speech-recognition", model="Finnish-NLP/wav2vec2-base-fi-voxpopuli-v2-finetuned") # Load the translation model for Finnish to English translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fi-en") # Function to handle translation from Finnish speech to English text def translate_speech(audio): # Convert Finnish speech to Finnish text finnish_text = asr_model(audio)["text"] # Translate Finnish text to English text english_text = translator(finnish_text)[0]["translation_text"] return english_text # Build Gradio Interface interface = gr.Interface( fn=translate_speech, inputs=gr.Audio(type="filepath"), # Remove the 'source' argument outputs="text", title="Finnish to English Speech Translator", description="This app translates Finnish speech to English text. You can upload an audio file, and see the translation appear in English!" ) # Launch the app interface.launch(share=True)