File size: 1,792 Bytes
0dfe33d
 
 
 
 
 
 
 
 
 
 
 
0db9e70
 
 
 
 
 
 
d6ea22f
0dfe33d
 
 
 
 
 
 
0db9e70
 
 
 
 
 
 
0dfe33d
 
 
d4c8cee
 
0db9e70
 
 
 
 
 
 
 
 
 
 
 
 
 
0dfe33d
0db9e70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr

from src.core import load_model, predict_traits

TRAIT_NAMES = [
    "Extraversion",
    "Agreeableness",
    "Conscientiousness",
    "Neurotisicm",
    "Openness",
]

DESCRIPTION = [
    "**Extraversion**: outgoing, energetic, talkative, active, assertive, etc.",
    "**Neuroticism**: worrying, self-pitying, unstable, tense, anxious, etc.",
    "**Agreeableness**: sympathetic, forgiving, generous, kind, appreciative, etc.",
    "**Conscientiousness**: responsible, organized, reliable, efficient, planful, etc.",
    "**Openness**: artistic, curious, imaginative, insightful, original, wide interests, etc.",
]


def get_traits(video):
    model = load_model()
    trait_values = predict_traits(video, model)
    return {k: float(v) for k, v in zip(TRAIT_NAMES, trait_values)}


params = dict(
    description="Predicts the Big-Five psychology traits of a person based an short introduction video. Adapted from [Deep Impression: Audiovisual Deep Residual Networks for Multimodal Apparent Personality Trait Recognition](https://arxiv.org/abs/1609.05119).",
    article=" ".join(DESCRIPTION),
    thumbnail="https://cdn-icons-png.flaticon.com/512/3392/3392044.png",
)

primary_interface = gr.Interface(
    get_traits,
    inputs=gr.Video(label="Video", include_audio=True),
    outputs=gr.Label(num_top_classes=5, label="Results"),
    examples="egs",
    cache_examples=True,
    **params,
)

second_interface = gr.Interface(
    get_traits,
    inputs=gr.Video(label="Webcam", include_audio=True, source="webcam"),
    outputs=gr.Label(num_top_classes=5, label="Results"),
    **params,
)

app = gr.TabbedInterface(
    [primary_interface, second_interface],
    title="Personality Traits Prediction 📑",
    tab_names=["Video Upload", "Webcam"],
)
app.launch()