Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
demo = gr.Blocks()
|
6 |
+
|
7 |
+
EXAMPLES = ["cantina.wav"]
|
8 |
+
|
9 |
+
def speech_to_text(x):
|
10 |
+
return [("yada yada", "speaker 0"), ("blah blah blah", "speaker 1")]
|
11 |
+
|
12 |
+
def summarize(y, c):
|
13 |
+
return "> " + len(c)*"stuff"
|
14 |
+
|
15 |
+
def sentiment(x, y):
|
16 |
+
if y == 0:
|
17 |
+
return [("yada yada", "happy")]
|
18 |
+
if y == 1:
|
19 |
+
return [("blah blah blah", "sad")]
|
20 |
+
|
21 |
+
with demo:
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
audio = gr.Audio(label="Audio file", type='filepath')
|
25 |
+
with gr.Row():
|
26 |
+
btn = gr.Button("Transcribe")
|
27 |
+
with gr.Row():
|
28 |
+
examples = gr.components.Dataset(components=[audio], samples=[EXAMPLES], type="index")
|
29 |
+
with gr.Column():
|
30 |
+
gr.Markdown("**Diarized Output:**")
|
31 |
+
diarized = gr.HighlightedText(label="Diarized Output")
|
32 |
+
gr.Markdown("Choose speaker(s) for summarization:")
|
33 |
+
check = gr.CheckboxGroup(["Speaker 0", "Speaker 1"], show_label=False)
|
34 |
+
gr.Textbox("**Summary:**")
|
35 |
+
summary = gr.Markdown()
|
36 |
+
gr.Markdown("Choose speaker for sentiment analysis:")
|
37 |
+
radio = gr.Radio(["Speaker 0", "Speaker 1"], show_label=False, type="index")
|
38 |
+
analyzed = gr.HighlightedText(label="Customer Sentiment")
|
39 |
+
|
40 |
+
btn.click(speech_to_text, audio, diarized)
|
41 |
+
check.change(summarize, [diarized, check], summary)
|
42 |
+
radio.change(sentiment, [diarized, radio], analyzed)
|
43 |
+
|
44 |
+
def load_example(example_id):
|
45 |
+
processed_examples = audio.preprocess_example(EXAMPLES[example_id])
|
46 |
+
return processed_examples
|
47 |
+
|
48 |
+
examples.click(load_example, inputs=[examples], outputs=[audio], _preprocess=False)
|
49 |
+
|
50 |
+
demo.launch()
|