SamuelMiller/sum_it
0
1 2# >>>>>> Adapted/frankensteined from these scripts: <<<<<<<3# for Summary Interface:4# >>>> https://huggingface.co/spaces/khxu/pegasus-text-summarizers/blob/main/app.py5# Audio Interface6# >>>> https://huggingface.co/spaces/iSky/Speech-audio-to-text-with-grammar-correction/blob/main/app.py7# Gramar8# >>>> https://huggingface.co/deep-learning-analytics/GrammarCorrector/blob/main/README.md9 10 11import gradio as gr12from transformers import pipeline13from gradio.mix import Parallel, Series14 15# >>>>>>>>>>>>>>>>>>>> Danger Below <<<<<<<<<<<<<<<<<<<<<<16# Load Interfaces:17s2t = gr.Interface.load('huggingface/hf-internal-testing/processor_with_lm')18grammar = gr.Interface.load('huggingface/deep-learning-analytics/GrammarCorrector')19sum_it = gr.Interface.load('huggingface/SamuelMiller/lil_sum_sum') 20 21# Audio Functions:22def out(audio):23 flag = True24 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_it31 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:38iface = 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 Interface47iface.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 here55 56#gr.Interface(speech_to_text, inputs="mic", outputs=gr.Textbox(label="Predicted text", lines=4))