SamuelMiller commited on
Commit
0fad229
1 Parent(s): 3b8bc2d

Create scratch.py

Browse files
Files changed (1) hide show
  1. scratch.py +56 -0
scratch.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # >>>>>> Adapted/frankensteined from these scripts: <<<<<<<
3
+ # for Summary Interface:
4
+ # >>>> https://huggingface.co/spaces/khxu/pegasus-text-summarizers/blob/main/app.py
5
+ # Audio Interface
6
+ # >>>> https://huggingface.co/spaces/iSky/Speech-audio-to-text-with-grammar-correction/blob/main/app.py
7
+ # Gramar
8
+ # >>>> https://huggingface.co/deep-learning-analytics/GrammarCorrector/blob/main/README.md
9
+
10
+
11
+ import gradio as gr
12
+ from transformers import pipeline
13
+ from gradio.mix import Parallel, Series
14
+
15
+ # >>>>>>>>>>>>>>>>>>>> Danger Below <<<<<<<<<<<<<<<<<<<<<<
16
+ # Load Interfaces:
17
+ s2t = gr.Interface.load('huggingface/hf-internal-testing/processor_with_lm')
18
+ grammar = gr.Interface.load('huggingface/deep-learning-analytics/GrammarCorrector')
19
+ sum_it = gr.Interface.load('huggingface/SamuelMiller/lil_sum_sum')
20
+
21
+ # Audio Functions:
22
+ def out(audio):
23
+ flag = True
24
+ if audio==None:
25
+ return "no audio"
26
+
27
+ elif flag:
28
+ a = s2t(audio)
29
+ #g = grammar(a)
30
+ #s = sum_it(g) # Summarize Audio with sum_it
31
+ return a #grammar(a, num_return_sequences=1) # grammar(s), # Grammar Filter
32
+
33
+ else:
34
+ return "something is wrong in the function?"
35
+
36
+
37
+ # Construct Interfaces:
38
+ iface = gr.Interface(
39
+ fn=out,
40
+ title="Speech Audio to text (with corrected grammar)",
41
+ description="Let's Hear It!! This app transforms your speech (input) to text with corrected grammar after (output)!",
42
+ inputs= gr.inputs.Audio(source="microphone", type="filepath", label=None, optional=True),
43
+ outputs= 'text'
44
+ )
45
+
46
+ # Launch Interface
47
+ iface.launch(enable_queue=True,show_error=True)
48
+
49
+ # From Original Code:
50
+ # gr.inputs.Audio(source="upload", type="filepath", label=None, optional=True),
51
+ # examples=[["Grammar-Correct-Sample.mp3"], ["Grammar-Wrong-Sample.mp3"],],
52
+
53
+ #def speech_to_text(inp):
54
+ #pass # speech recognition model defined here
55
+
56
+ #gr.Interface(speech_to_text, inputs="mic", outputs=gr.Textbox(label="Predicted text", lines=4))