asif00 commited on
Commit
17c1345
·
verified ·
1 Parent(s): 5f3b06a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -1,16 +1,36 @@
 
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
4
- pipe = pipeline(model="asif00/whisper-bangla")
 
 
 
 
5
 
6
 
 
7
  def transcribe(audio):
8
- text = pipe(audio)["text"]
9
  return text
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  iface = gr.Interface(
13
- fn=transcribe,
14
  inputs=gr.Audio(sources="microphone", type="filepath"),
15
  outputs="text",
16
  title="Whisper Bangla",
 
1
+ import spaces
2
  from transformers import pipeline
3
  import gradio as gr
4
+ import torch
5
 
6
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
+ asr = pipeline(model="asif00/whisper-bangla").to(device=device)
8
+ ser = pipeline("text2text-generation", model="asif00/mbart_bn_error_correction").to(
9
+ device=device
10
+ )
11
 
12
 
13
+ @spaces.GPU
14
  def transcribe(audio):
15
+ text = asr(audio)["text"]
16
  return text
17
 
18
 
19
+ @spaces.GPU
20
+ def correction(text):
21
+ corrected_text = ser(text)
22
+ print(corrected_text)
23
+ return corrected_text
24
+
25
+
26
+ def transcribe_and_correct(audio):
27
+ text = transcribe(audio)
28
+ corrected_text = correction(text)
29
+ return corrected_text
30
+
31
+
32
  iface = gr.Interface(
33
+ fn=transcribe_and_correct,
34
  inputs=gr.Audio(sources="microphone", type="filepath"),
35
  outputs="text",
36
  title="Whisper Bangla",