oslohaze commited on
Commit
faa1118
·
verified ·
1 Parent(s): 4c245c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Translation pipeline
5
+ translation_pipeline = pipeline("translation_en_to_ml")
6
+
7
+ # ASR pipeline
8
+ asr_pipeline = pipeline("automatic-speech-recognition", model="vrclc/w2v2bert_malayalam")
9
+
10
+ # Translation function
11
+ def translate(text):
12
+ translated_text = translation_pipeline(text, max_length=40)[0]['translation_text']
13
+ return translated_text
14
+
15
+ # ASR function
16
+ def recognize_speech(audio_file):
17
+ result = asr_pipeline(audio_file)
18
+ transcription = result[0]['transcription']
19
+ return transcription
20
+
21
+ # Interface setup
22
+ iface = gr.Interface(
23
+ fn=[translate, recognize_speech],
24
+ inputs=[
25
+ gr.Textbox(lines=5, label="Enter English Text to Translate"),
26
+ gr.File(label="Upload Audio File for Speech Recognition")
27
+ ],
28
+ outputs=[
29
+ gr.Textbox(label="Malayalam Translation"),
30
+ gr.Textbox(label="Malayalam Speech Recognition")
31
+ ],
32
+ title="English to Malayalam Translation and Speech Recognition",
33
+ theme="compact"
34
+ )
35
+
36
+ # Launch the interface
37
+ iface.launch()