eliwill commited on
Commit
841baa6
·
1 Parent(s): bcba41d

Add new demo

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -1,18 +1,32 @@
 
 
1
  import gradio as gr
2
 
3
- def welcome(name):
4
- return f"Welcome to Gradio, {name}!"
5
-
6
- with gr.Blocks() as demo:
7
- gr.Markdown(
8
- """
9
- # Krishnamurti Text Generator Program
10
- Hello, and welcome to the *Krishamurti Text-Generation Program*
11
- Please enter your question below.
12
- """)
13
- inp = gr.Textbox(placeholder="What is your name?")
14
- out = gr.Textbox()
15
- inp.change(welcome, inp, out)
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  demo.launch()
18
 
 
1
+ from transformers import pipeline
2
+
3
  import gradio as gr
4
 
5
+ asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
6
+ classifier = pipeline("text-classification")
7
+
8
+
9
+ def speech_to_text(speech):
10
+ text = asr(speech)["text"]
11
+ return text
12
+
13
+
14
+ def text_to_sentiment(text):
15
+ return classifier(text)[0]["label"]
16
+
17
+
18
+ demo = gr.Blocks()
19
+
20
+ with demo:
21
+ audio_file = gr.Audio(type="filepath")
22
+ text = gr.Textbox()
23
+ label = gr.Label()
24
+
25
+ b1 = gr.Button("Recognize Speech")
26
+ b2 = gr.Button("Classify Sentiment")
27
+
28
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
29
+ b2.click(text_to_sentiment, inputs=text, outputs=label)
30
 
31
  demo.launch()
32