File size: 922 Bytes
ff39d68
 
 
 
 
 
 
 
35b1732
 
ff39d68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35b1732
ff39d68
35b1732
 
ff39d68
35b1732
ff39d68
 
35b1732
 
 
 
ff39d68
 
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
import streamlit as st
import datetime
from transformers import pipeline
import gradio as gr


asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")

classifier = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")

def transcribe(audio):
    text = asr(audio)["text"]
    return text

def speech_to_text(speech):
    text = asr(speech)["text"]
    return text

def text_to_sentiment(text):
    sentiment = classifier(text)[0]["label"]
    return sentiment 
    
demo = gr.Blocks()

with demo:

    audio_file = gr.inputs.Audio(source="microphone", type="filepath")
    b1 = gr.Button("Recognize Speech") 
    b1.click(speech_to_text, inputs=audio_file, outputs=text)
    text = gr.Textbox()
 
    b2 = gr.Button("Classify Sentiment")
    b2.click(text_to_sentiment, inputs=text, outputs=label)
    label = gr.Label()
    
    
    
    
demo.launch(share=True)