File size: 2,930 Bytes
b037802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr

def main():
    title = """<h1 align="center">🎀 Multilingual ASR πŸ’¬</h1>"""
    description = """
    πŸ’» This demo showcases a general-purpose speech recognition model called Whisper. It is trained on a large dataset of diverse audio and supports multilingual speech recognition, speech translation, and language identification tasks.<br><br>
    <br>
    βš™οΈ Components of the tool:<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp; - Real-time multilingual speech recognition<br>
    &nbsp;&nbsp;&nbsp;&nbsp; - Language identification<br>
    &nbsp;&nbsp;&nbsp;&nbsp; - Sentiment analysis of the transcriptions<br>
    <br>
    🎯 The sentiment analysis results are provided as a dictionary with different emotions and their corresponding scores.<br>
    <br>
    πŸ˜ƒ The sentiment analysis results are displayed with emojis representing the corresponding sentiment.<br>
    <br>
    βœ… The higher the score for a specific emotion, the stronger the presence of that emotion in the transcribed text.<br>
    <br>
    ❓ Use the microphone for real-time speech recognition.<br>
    <br>
    ⚑️ The model will transcribe the audio and perform sentiment analysis on the transcribed text.<br>
    """

    custom_css = """
    #banner-image {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }
    #chat-message {
        font-size: 14px;
        min-height: 300px;
    }
    """

    block = gr.Blocks(css=custom_css)

    with block:
        gr.HTML(title)

        with gr.Row():
            with gr.Column():
                gr.HTML(description)

        with gr.Group():
            with gr.Box():
                audio = gr.Audio(
                    label="Input Audio",
                    show_label=False,
                    source="microphone",
                    type="filepath"
                )

                sentiment_option = gr.Radio(
                    choices=["Sentiment Only", "Sentiment + Score"],
                    label="Select an option",
                    default="Sentiment Only"
                )

                btn = gr.Button("Transcribe")

            lang_str = gr.Textbox(label="Language")

            text = gr.Textbox(label="Transcription")

            sentiment_output = gr.Textbox(label="Sentiment Analysis Results", output=True)

            prediction = gr.Textbox(label="Prediction")
            
            language_translation = gr.Textbox(label="Language Translation")
            

            btn.click(inference, inputs=[audio, sentiment_option], outputs=[lang_str, text, sentiment_output, prediction,language_translation])

            # gr.HTML('''
            # <div class="footer">
            #     <p>Model by <a href="https://github.com/openai/whisper" style="text-decoration: underline;" target="_blank">OpenAI</a>
            #     </p>
            # </div>
            # ''') 

    block.launch()