suomi_english / app.py
akash-43's picture
Update app.py
0592306 verified
raw
history blame
1.09 kB
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")
# 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(source=["microphone", "upload"], type="filepath"),
outputs="text",
title="Finnish to English Speech Translator",
description="This app translates Finnish speech to English text. You can either speak in Finnish or upload an audio file, and see the translation appear in English!"
)
# Launch the app
interface.launch(api=True)