akash-43 commited on
Commit
98c332d
·
verified ·
1 Parent(s): 636933f

added app.py file

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Automatic Speech Recognition (ASR) model for Finnish
5
+ asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small", language="finnish")
6
+
7
+ # Load the translation model for Finnish to English
8
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fi-en")
9
+
10
+ # Function to handle translation from Finnish speech to English text
11
+ def translate_speech(audio):
12
+ # Convert Finnish speech to Finnish text
13
+ finnish_text = asr_model(audio)["text"]
14
+ # Translate Finnish text to English text
15
+ english_text = translator(finnish_text)[0]["translation_text"]
16
+ return english_text
17
+
18
+ # Build Gradio Interface
19
+ interface = gr.Interface(
20
+ fn=translate_speech,
21
+ inputs=gr.Audio(source=["microphone", "upload"], type="filepath"),
22
+ outputs="text",
23
+ title="Finnish to English Speech Translator",
24
+ 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!"
25
+ )
26
+
27
+ # Launch the app
28
+ interface.launch(api=True)