sum_it / scrach.py
SamuelMiller's picture
Update scrach.py
ea0991d
raw
history blame
1.37 kB
# Adapted from from: https://huggingface.co/spaces/iSky/Speech-audio-to-text-with-grammar-correction/tree/main
# Imports:
import gradio as gr
from transformers import pipeline
# Load Interfaces:
s2t = gr.Interface.load('huggingface/facebook/s2t-medium-librispeech-asr')
grammar = gr.Interface.load('huggingface/prithivida/grammar_error_correcter_v1')
# Audio Functions:
def out(audio1,audio2):
if (audio1==None) and (audio2==None):
return "no audio","no audio"
elif audio1==None:
x=s2t(audio2)
return x, grammar(x)
else:
x=s2t(audio1)
return x, grammar(x)
# Construct Interfaces:
iface = gr.Interface(
fn=out,
title="Speech Audio to text (with corrected grammar)",
description="2 possible input methods of audio file, transformed to text (as an output) and corrected grammar after(another output)!",
inputs=[gr.inputs.Audio(source="upload", type="filepath", label=None, optional=True),
gr.inputs.Audio(source="microphone", type="filepath", label=None, optional=True)],
examples=[["Grammar-Correct-Sample.mp3"], ["Grammar-Wrong-Sample.mp3"],],
outputs=['text','text']
)
iface.launch(enable_queue=True,show_error=True)
# Hello there I am not in a house. The house was old long ago when everyone was made of snow.
# The house was old long ago when everyone was made of snow.