File size: 1,445 Bytes
2ce5d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from models import infere_speech_emotion, infere_text_emotion, infere_voice2text

with gr.Blocks() as demo:
    gr.HTML('''
        <h1 style="text-align:center;">Speech and Text Emotion Recognition</h1>
        <h2 style="text-align:center;">Determining someone's emotions can be challenging based solely on their tone or words <br> This app uses both to provide a more accurate analysis of emotional expression in a single audio recording</h2>
        ''')
    with gr.Row():
        input = gr.Audio(label="Audio File", type="filepath")
        with gr.Column():
            output0 = gr.Textbox(label="Text from the audio")
            output1 = gr.Textbox(label="Speech emotion")
            output2 = gr.Textbox(label="Text emotion")
    btn = gr.Button("Analyze audio")   
        
    btn.click(fn=infere_voice2text, inputs=input, outputs=output0)
    btn.click(fn=infere_speech_emotion, inputs=input, outputs=output1)
    output0.change(fn=infere_text_emotion, inputs=output0, outputs=output2)
    
    gr.HTML('''
        <br>
        <h3 style="text-align:center;">View examples of how speech and words can convey different emotions by clicking below</h3>
        ''')
    
    gr.Examples(
        [ 
            os.path.join(os.path.dirname(__file__), "audio/a_good_dream.wav"),
            os.path.join(os.path.dirname(__file__), "audio/hype_in_ai.wav"),
        ],
        input
    )

demo.launch()