LittleMonkeyLab commited on
Commit
7cf6c19
·
1 Parent(s): aaf0eee

initial commit

Browse files
app.py CHANGED
@@ -1,7 +1,162 @@
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ """
2
+ File: app.py
3
+ Author: Elena Ryumina and Dmitry Ryumin
4
+ Description: Description: Main application file for Facial_Expression_Recognition.
5
+ The file defines the Gradio interface, sets up the main blocks,
6
+ and includes event handlers for various components.
7
+ License: MIT License
8
+ """
9
+
10
  import gradio as gr
11
 
12
+ # Importing necessary components for the Gradio app
13
+ from app.description import DESCRIPTION_STATIC, DESCRIPTION_DYNAMIC
14
+ from app.authors import AUTHORS
15
+ from app.app_utils import preprocess_image_and_predict, preprocess_video_and_predict
16
+
17
+
18
+ def clear_static_info():
19
+ return (
20
+ gr.Image(value=None, type="pil"),
21
+ gr.Image(value=None, scale=1, elem_classes="dl5"),
22
+ gr.Image(value=None, scale=1, elem_classes="dl2"),
23
+ gr.Label(value=None, num_top_classes=3, scale=1, elem_classes="dl3"),
24
+ )
25
+
26
+ def clear_dynamic_info():
27
+ return (
28
+ gr.Video(value=None),
29
+ gr.Video(value=None),
30
+ gr.Video(value=None),
31
+ gr.Video(value=None),
32
+ gr.Plot(value=None),
33
+ )
34
+
35
+ with gr.Blocks(css="app.css") as demo:
36
+ # Header with Observatory logo
37
+ with gr.Row(elem_classes="header-container"):
38
+ with gr.Column():
39
+ gr.Image("images/LMLOBS.png", show_label=False, container=False, elem_classes="header-logo")
40
+
41
+ gr.Markdown("# Facial Emotion Expression Demo")
42
+ gr.Markdown("### LittleMonkeyLab | Goldsmiths Observatory")
43
+
44
+ with gr.Tab("Dynamic App"):
45
+ with gr.Row():
46
+ with gr.Column(scale=2):
47
+ input_video = gr.Video(elem_classes="video1")
48
+ gr.Markdown("""
49
+ ### How to use:
50
+ 1. Upload a video or use one of the examples below
51
+ 2. Click 'Submit' to analyze facial expressions
52
+ 3. Watch the processed video and emotion statistics
53
+ """)
54
+ with gr.Row():
55
+ clear_btn_dynamic = gr.Button(
56
+ value="Clear", interactive=True, scale=1
57
+ )
58
+ submit_dynamic = gr.Button(
59
+ value="Submit", interactive=True, scale=1, elem_classes="submit"
60
+ )
61
+ with gr.Column(scale=2, elem_classes="dl4"):
62
+ with gr.Row():
63
+ output_video = gr.Video(label="Original video", scale=1, elem_classes="video2")
64
+ output_face = gr.Video(label="Pre-processed video", scale=1, elem_classes="video3", visible=False)
65
+ output_heatmaps = gr.Video(label="Heatmaps", scale=1, elem_classes="video4", visible=False)
66
+ output_statistics = gr.Plot(label="Statistics of emotions", elem_classes="stat")
67
+ emotion_averages = gr.Dataframe(
68
+ headers=["Emotion", "Average Intensity", "Peak Value"],
69
+ label="Emotion Analysis Summary",
70
+ elem_classes="emotion-summary"
71
+ )
72
+ gr.Markdown("""
73
+ ### Understanding the Results:
74
+ - The graph shows emotion intensities over time
75
+ - Higher peaks indicate stronger emotional expressions
76
+ - Multiple emotions can be present simultaneously
77
+ - Common patterns:
78
+ * Happiness: Upturned mouth, raised cheeks
79
+ * Sadness: Downturned mouth, raised inner eyebrows
80
+ * Anger: Lowered eyebrows, tightened lips
81
+ * Surprise: Raised eyebrows, widened eyes
82
+ * Fear: Widened eyes, raised outer eyebrows
83
+ * Disgust: Wrinkled nose, raised upper lip
84
+ * Neutral: Relaxed facial features
85
+ """)
86
+ gr.Examples(
87
+ ["videos/video1.mp4",
88
+ "videos/video2.mp4",
89
+ ],
90
+ [input_video],
91
+ )
92
+
93
+ with gr.Tab("Static App"):
94
+ with gr.Row():
95
+ with gr.Column(scale=2, elem_classes="dl1"):
96
+ input_image = gr.Image(label="Original image", type="pil")
97
+ with gr.Row():
98
+ clear_btn = gr.Button(
99
+ value="Clear", interactive=True, scale=1, elem_classes="clear"
100
+ )
101
+ submit = gr.Button(
102
+ value="Submit", interactive=True, scale=1, elem_classes="submit"
103
+ )
104
+ with gr.Column(scale=1, elem_classes="dl4"):
105
+ with gr.Row():
106
+ output_image = gr.Image(label="Face", scale=1, elem_classes="dl5")
107
+ output_heatmap = gr.Image(label="Heatmap", scale=1, elem_classes="dl2")
108
+ output_label = gr.Label(num_top_classes=3, scale=1, elem_classes="dl3")
109
+ gr.Examples(
110
+ [
111
+ "images/fig7.jpg",
112
+ "images/fig1.jpg",
113
+ "images/fig2.jpg",
114
+ "images/fig3.jpg",
115
+ "images/fig4.jpg",
116
+ "images/fig5.jpg",
117
+ "images/fig6.jpg",
118
+ ],
119
+ [input_image],
120
+ )
121
+
122
+ # Footer with LittleMonkeyLab logo
123
+ with gr.Row(elem_classes="center-content"):
124
+ with gr.Column():
125
+ gr.Image("images/LMLLOGO.png", show_label=False, container=False, elem_classes="footer-logo")
126
+ gr.Markdown("© LittleMonkeyLab | Goldsmiths Observatory", elem_classes="footer-text")
127
+
128
+ submit.click(
129
+ fn=preprocess_image_and_predict,
130
+ inputs=[input_image],
131
+ outputs=[output_image, output_heatmap, output_label],
132
+ queue=True,
133
+ )
134
+ clear_btn.click(
135
+ fn=clear_static_info,
136
+ inputs=[],
137
+ outputs=[input_image, output_image, output_heatmap, output_label],
138
+ queue=True,
139
+ )
140
+
141
+ submit_dynamic.click(
142
+ fn=preprocess_video_and_predict,
143
+ inputs=[input_video],
144
+ outputs=[output_video, output_face, output_heatmaps, output_statistics, emotion_averages],
145
+ queue=True,
146
+ )
147
+ clear_btn_dynamic.click(
148
+ fn=clear_dynamic_info,
149
+ inputs=[],
150
+ outputs=[
151
+ input_video,
152
+ output_video,
153
+ output_face,
154
+ output_heatmaps,
155
+ output_statistics,
156
+ emotion_averages
157
+ ],
158
+ queue=True,
159
+ )
160
 
161
+ if __name__ == "__main__":
162
+ demo.queue(api_open=False).launch(share=False)
images/GoldObs.png ADDED
images/LMLLAB.png ADDED
images/LMLLOGO.png ADDED
images/LMLOBS.png ADDED
images/fig1.jpg ADDED
images/fig2.jpg ADDED
images/fig3.jpg ADDED
images/fig4.jpg ADDED
images/fig5.jpg ADDED
images/fig6.jpg ADDED
images/fig7.jpg ADDED
images/videos/video1.mp4 ADDED
Binary file (680 kB). View file
 
images/videos/video2.mp4 ADDED
Binary file (182 kB). View file