File size: 1,743 Bytes
103a375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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'))
    )