GojoSaturo commited on
Commit
e59b53b
β€’
1 Parent(s): 843dfaa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from googletrans import Translator
3
+ import torch
4
+ # Initialize Translator
5
+ from transformers import pipeline
6
+ translator = Translator()
7
+ MODEL_NAME = "openai/whisper-base"
8
+ device = 0 if torch.cuda.is_available() else "cpu"
9
+ pipe = pipeline(
10
+ task="automatic-speech-recognition",
11
+ model=MODEL_NAME,
12
+ chunk_length_s=30,
13
+ device=device,
14
+ )
15
+
16
+
17
+ def transcribe_audio(audio):
18
+ text = pipe(audio)["text"]
19
+ return text
20
+ # return translated_text
21
+
22
+ audio_record = gr.inputs.Audio(source='microphone', label='Record Audio')
23
+ output_text = gr.outputs.Textbox(label='Transcription')
24
+
25
+ interface = gr.Interface(fn=transcribe_audio, inputs=audio_record, outputs=output_text)
26
+ interface.launch()