Spaces:
Sleeping
Sleeping
Commit ·
8ee4a2c
1
Parent(s): c916d05
feat(app): create app gui module
Browse files
src/emotion_analysis/app/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .gui import build_gui as build_gui
|
| 2 |
+
from .on_callback import on_classify as on_classify
|
src/emotion_analysis/app/gui.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable
|
| 2 |
+
|
| 3 |
+
from gradio import Audio, Blocks, Button, Column, Slider
|
| 4 |
+
|
| 5 |
+
from ..services import Classifier
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def build_gui(model: Classifier, on_btn_classify: Callable):
|
| 9 |
+
with Blocks() as demo:
|
| 10 |
+
with Column():
|
| 11 |
+
audio_input = Audio(
|
| 12 |
+
label="Audio input",
|
| 13 |
+
sources=["microphone", "upload"],
|
| 14 |
+
type="filepath",
|
| 15 |
+
)
|
| 16 |
+
classify_btn = Button(value="Classify")
|
| 17 |
+
|
| 18 |
+
with Column():
|
| 19 |
+
emotions = [
|
| 20 |
+
Slider(
|
| 21 |
+
label=emotion.capitalize(),
|
| 22 |
+
minimum=0,
|
| 23 |
+
maximum=1,
|
| 24 |
+
precision=0,
|
| 25 |
+
interactive=False,
|
| 26 |
+
)
|
| 27 |
+
for emotion in model.label2id.keys()
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
classify_btn.click(
|
| 31 |
+
fn=on_btn_classify(model), inputs=audio_input, outputs=emotions
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
return demo
|
src/emotion_analysis/app/on_callback.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
from ..services import Classifier
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def on_classify(model: Classifier):
|
| 7 |
+
def fn(audio: Path | str):
|
| 8 |
+
probs: dict[int, float] = model.predict(audio, return_probs=True) # type: ignore
|
| 9 |
+
print(probs)
|
| 10 |
+
return list(probs.values())
|
| 11 |
+
|
| 12 |
+
return fn
|