import os from dotenv import load_dotenv import numpy as np import gradio as gr # eloquent imports import model_wben as asr import model_llama as llm #import model_llamacpp as llm import fn_diff as dff load_dotenv() ## Front-End with gr.Blocks() as demo: # record audio gr.Markdown( """ # Eloquent is ready. Press the Record. Start Speaking. Press Stop. Click on Transcribe. Transcription and improved text will appear below. """ ) myspeech = gr.Audio(sources=["microphone"]) with gr.Row(): with gr.Column(): # transcribe b1 = gr.Button("Click to Transcribe Audio") mytranscription = gr.Textbox( label="speech transcription", autoscroll=True, max_lines=5 ) with gr.Column(): b2 = gr.Button("Click to Improve Transcription") myspeech_improved = gr.Textbox( label="improved speech" ) myspeech_diff = gr.HighlightedText( label="transcript and improved speech differences", combine_adjacent=True, show_legend=True, color_map={"+": "green", "-": "red"}) b1.click(fn=asr.transcribe, inputs=myspeech, outputs=mytranscription) b2.click(fn=llm.improve_grammar, inputs=[mytranscription], outputs=[myspeech_improved] ) myspeech_improved.change(fn=dff.diff_texts, inputs=[mytranscription,myspeech_improved], outputs=myspeech_diff ) if __name__ == "__main__": demo.queue() demo.launch( share=False, server_name=os.getenv('GRADIO_SERVER_IP'), server_port=int(os.getenv('GRADIO_SERVER_PORT')) )