SamuelMiller commited on
Commit
32e7fd5
·
1 Parent(s): 3f14393

Update scrach.py

Browse files
Files changed (1) hide show
  1. scrach.py +36 -0
scrach.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adapted from from: https://huggingface.co/spaces/iSky/Speech-audio-to-text-with-grammar-correction/tree/main
2
+
3
+ # Imports:
4
+ import gradio as gr
5
+ from transformers import pipeline
6
+
7
+ # Load Interfaces:
8
+ s2t = gr.Interface.load('huggingface/facebook/s2t-medium-librispeech-asr')
9
+ grammar = gr.Interface.load('huggingface/prithivida/grammar_error_correcter_v1')
10
+
11
+
12
+ # Audio Functions:
13
+ def out(audio1,audio2):
14
+ if (audio1==None) and (audio2==None):
15
+ return "no audio","no audio"
16
+ elif audio1==None:
17
+
18
+ x=s2t(audio2)
19
+ return x, grammar(x)
20
+ else:
21
+ x=s2t(audio1)
22
+ return x, grammar(x)
23
+
24
+
25
+ # Construct Interfaces:
26
+ iface = gr.Interface(
27
+ fn=out,
28
+ title="Speech Audio to text (with corrected grammar)",
29
+ description="2 possible input methods of audio file, transformed to text (as an output) and corrected grammar after(another output)!",
30
+ inputs=[gr.inputs.Audio(source="upload", type="filepath", label=None, optional=True),
31
+ gr.inputs.Audio(source="microphone", type="filepath", label=None, optional=True)],
32
+ examples=[["Grammar-Correct-Sample.mp3"], ["Grammar-Wrong-Sample.mp3"],],
33
+ outputs=['text','text']
34
+ )
35
+
36
+ iface.launch(enable_queue=True,show_error=True)