rajistics commited on
Commit
ff39d68
1 Parent(s): 4a2fff9
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import datetime
3
+ from transformers import pipeline
4
+ import gradio as gr
5
+
6
+
7
+ asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
8
+
9
+ def transcribe(audio):
10
+ text = asr(audio)["text"]
11
+ return text
12
+
13
+ classifier = pipeline(
14
+ "text-classification",
15
+ model="bhadresh-savani/distilbert-base-uncased-emotion")
16
+
17
+ def speech_to_text(speech):
18
+ text = asr(speech)["text"]
19
+ return text
20
+
21
+ def text_to_sentiment(text):
22
+ sentiment = classifier(text)[0]["label"]
23
+ return sentiment
24
+
25
+ demo = gr.Blocks()
26
+
27
+ with demo:
28
+ #audio_file = gr.Audio(type="filepath")
29
+ audio_file = gr.inputs.Audio(source="microphone", type="filepath")
30
+ text = gr.Textbox()
31
+ label = gr.Label()
32
+ saved = gr.Textbox()
33
+ savedAll = gr.Textbox()
34
+
35
+ b1 = gr.Button("Recognize Speech")
36
+ b2 = gr.Button("Classify Sentiment")
37
+
38
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
39
+ b2.click(text_to_sentiment, inputs=text, outputs=label)
40
+
41
+ demo.launch(share=True)