jvcanavarro commited on
Commit
0db9e70
1 Parent(s): ef58f03

Add webcam support

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -1,6 +1,4 @@
1
  import gradio as gr
2
- import glob
3
- import os
4
 
5
  from src.core import load_model, predict_traits
6
 
@@ -12,26 +10,48 @@ TRAIT_NAMES = [
12
  "Openness",
13
  ]
14
 
15
- DESCRIPTION = "\n'Extraversion': outgoing, energetic, talkative, active, assertive, etc.\n'Neuroticism': worrying, self-pitying, unstable, tense, anxious, etc.\n'Agreeableness': sympathetic, forgiving, generous, kind, appreciative, etc.\n'Conscientiousness': responsible, organized, reliable, efficient, planful, etc.\n'Openness': artistic, curious, imaginative, insightful, original, wide interests, etc."
 
 
 
 
 
 
16
 
17
 
18
  def get_traits(video):
19
  model = load_model()
20
- # if webcam_video:
21
- # trait_values = predict_traits(webcam_video, model)
22
- # else:
23
  trait_values = predict_traits(video, model)
24
  return {k: float(v) for k, v in zip(TRAIT_NAMES, trait_values)}
25
 
26
 
27
- demo = gr.Interface(
 
 
 
 
 
 
 
 
 
 
28
  get_traits,
29
  inputs=gr.Video(label="Video", include_audio=True),
30
  outputs=gr.Label(num_top_classes=5, label="Results"),
31
- title="Personality Traits Prediction [Prototype]",
32
- description="Predicts the 5 psychological traits of a person using an short introduction video" + DESCRIPTION,
33
- thumbnail="https://cdn-icons-png.flaticon.com/512/3392/3392044.png",
34
- examples="egs",
35
- cache_examples=True,
 
 
 
 
 
 
 
 
 
36
  )
37
- demo.launch()
 
1
  import gradio as gr
 
 
2
 
3
  from src.core import load_model, predict_traits
4
 
 
10
  "Openness",
11
  ]
12
 
13
+ DESCRIPTION = [
14
+ "**Extraversion**: outgoing, energetic, talkative, active, assertive, etc.",
15
+ "**Neuroticism**: worrying, self-pitying, unstable, tense, anxious, etc.",
16
+ "**Agreeableness**: sympathetic, forgiving, generous, kind, appreciative, etc.",
17
+ "**Conscientiousness**: responsible, organized, reliable, efficient, planful, etc.",
18
+ "**Openness**: artistic, curious, imaginative, insightful, original, wide interests, etc.",
19
+ ]
20
 
21
 
22
  def get_traits(video):
23
  model = load_model()
 
 
 
24
  trait_values = predict_traits(video, model)
25
  return {k: float(v) for k, v in zip(TRAIT_NAMES, trait_values)}
26
 
27
 
28
+ params = dict(
29
+ # outputs=gr.Label(num_top_classes=5, label="Results"),
30
+ # title="Personality Traits Prediction 📑",
31
+ 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).",
32
+ article=" ".join(DESCRIPTION),
33
+ thumbnail="https://cdn-icons-png.flaticon.com/512/3392/3392044.png",
34
+ examples="egs",
35
+ cache_examples=False,
36
+ )
37
+
38
+ primary_interface = gr.Interface(
39
  get_traits,
40
  inputs=gr.Video(label="Video", include_audio=True),
41
  outputs=gr.Label(num_top_classes=5, label="Results"),
42
+ **params,
43
+ )
44
+
45
+ second_interface = gr.Interface(
46
+ get_traits,
47
+ inputs=gr.Video(label="Webcam", include_audio=True, source="webcam"),
48
+ outputs=gr.Label(num_top_classes=5, label="Results"),
49
+ **params,
50
+ )
51
+
52
+ app = gr.TabbedInterface(
53
+ [primary_interface, second_interface],
54
+ title="Personality Traits Prediction 📑",
55
+ tab_names=["Video Upload", "Webcam"],
56
  )
57
+ app.launch()