Spaces:
Runtime error
Runtime error
Commit
Β·
cbb2414
1
Parent(s):
91beaca
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
from gradio.mix import Series
|
|
|
5 |
|
6 |
path_to_L_model = str(os.environ['path_to_L_model'])
|
7 |
read_token = str(os.environ['read_token'])
|
@@ -9,17 +10,46 @@ read_token = str(os.environ['read_token'])
|
|
9 |
description = "Talk to Breud!"
|
10 |
title = "Breud (BERT + Freud)"
|
11 |
|
12 |
-
wisper = gr.Interface.load("models/openai/whisper-base")
|
13 |
|
14 |
-
interface_model_L = gr.Interface.load(
|
15 |
-
|
16 |
-
|
17 |
-
)
|
18 |
|
19 |
-
Series(
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
from gradio.mix import Series
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
path_to_L_model = str(os.environ['path_to_L_model'])
|
8 |
read_token = str(os.environ['read_token'])
|
|
|
10 |
description = "Talk to Breud!"
|
11 |
title = "Breud (BERT + Freud)"
|
12 |
|
13 |
+
# wisper = gr.Interface.load("models/openai/whisper-base")
|
14 |
|
15 |
+
# interface_model_L = gr.Interface.load(
|
16 |
+
# name=path_to_L_model,
|
17 |
+
# api_key=read_token,
|
18 |
+
# )
|
19 |
|
20 |
+
# Series(
|
21 |
+
# wisper,
|
22 |
+
# interface_model_L,
|
23 |
+
# description = description,
|
24 |
+
# title = title,
|
25 |
+
# inputs = gr.Audio(source="microphone"),
|
26 |
+
# ).launch()
|
27 |
+
|
28 |
+
|
29 |
+
asr = pipeline("automatic-speech-recognition", "models/openai/whisper-base")
|
30 |
+
classifier = pipeline("text-classification", path_to_L_model, api_token=read_token)
|
31 |
+
|
32 |
+
|
33 |
+
def speech_to_text(speech):
|
34 |
+
text = asr(speech)["text"]
|
35 |
+
return text
|
36 |
+
|
37 |
+
|
38 |
+
def text_to_sentiment(text):
|
39 |
+
return classifier(text)[0]["label"]
|
40 |
+
|
41 |
+
|
42 |
+
demo = gr.Blocks()
|
43 |
+
|
44 |
+
with demo:
|
45 |
+
audio_file = gr.Audio(source="microphone")
|
46 |
+
text = gr.Textbox()
|
47 |
+
label = gr.Label()
|
48 |
+
|
49 |
+
b1 = gr.Button("Recognize Speech")
|
50 |
+
b2 = gr.Button("Classify Sentiment")
|
51 |
+
|
52 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
53 |
+
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
54 |
+
|
55 |
+
demo.launch()
|