Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
File: app.py
|
| 3 |
Author: Dr. Gordon Wright
|
| 4 |
-
Description:
|
| 5 |
The file defines the Gradio interface, sets up the main blocks,
|
| 6 |
and includes event handlers for various components.
|
| 7 |
License: MIT License
|
|
@@ -14,7 +14,6 @@ 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"),
|
|
@@ -33,35 +32,36 @@ def clear_dynamic_info():
|
|
| 33 |
)
|
| 34 |
|
| 35 |
with gr.Blocks(css="app.css") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
with gr.Tab("Static Faces"):
|
| 37 |
gr.Markdown(value=DESCRIPTION_STATIC)
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column(scale=2, elem_classes="dl1"):
|
| 40 |
input_image = gr.Image(label="Original image", type="pil")
|
| 41 |
with gr.Row():
|
| 42 |
-
clear_btn = gr.Button(
|
| 43 |
-
|
| 44 |
-
)
|
| 45 |
-
submit = gr.Button(
|
| 46 |
-
value="Submit", interactive=True, scale=1, elem_classes="submit"
|
| 47 |
-
)
|
| 48 |
with gr.Column(scale=1, elem_classes="dl4"):
|
| 49 |
with gr.Row():
|
| 50 |
output_image = gr.Image(label="Face", scale=1, elem_classes="dl5")
|
| 51 |
output_heatmap = gr.Image(label="Heatmap", scale=1, elem_classes="dl2")
|
| 52 |
output_label = gr.Label(num_top_classes=3, scale=1, elem_classes="dl3")
|
| 53 |
-
gr.Examples(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
],
|
| 63 |
-
[input_image],
|
| 64 |
-
)
|
| 65 |
|
| 66 |
with gr.Tab("Dynamic Faces"):
|
| 67 |
gr.Markdown(value=DESCRIPTION_DYNAMIC)
|
|
@@ -69,28 +69,25 @@ with gr.Blocks(css="app.css") as demo:
|
|
| 69 |
with gr.Column(scale=2):
|
| 70 |
input_video = gr.Video(elem_classes="video1")
|
| 71 |
with gr.Row():
|
| 72 |
-
clear_btn_dynamic = gr.Button(
|
| 73 |
-
|
| 74 |
-
)
|
| 75 |
-
submit_dynamic = gr.Button(
|
| 76 |
-
value="Submit", interactive=True, scale=1, elem_classes="submit"
|
| 77 |
-
)
|
| 78 |
with gr.Column(scale=2, elem_classes="dl4"):
|
| 79 |
with gr.Row():
|
| 80 |
output_video = gr.Video(label="Original video", scale=1, elem_classes="video2")
|
| 81 |
output_face = gr.Video(label="Pre-processed video", scale=1, elem_classes="video3")
|
| 82 |
output_heatmaps = gr.Video(label="Heatmaps", scale=1, elem_classes="video4")
|
| 83 |
output_statistics = gr.Plot(label="Statistics of emotions", elem_classes="stat")
|
| 84 |
-
gr.Examples(
|
| 85 |
-
["videos/BillClinton.mp4"
|
| 86 |
-
],
|
| 87 |
-
[input_video],
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
|
| 91 |
with gr.Tab("References"):
|
| 92 |
gr.Markdown(value=AUTHORS)
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
submit.click(
|
| 95 |
fn=preprocess_image_and_predict,
|
| 96 |
inputs=[input_image],
|
|
@@ -103,7 +100,7 @@ with gr.Blocks(css="app.css") as demo:
|
|
| 103 |
outputs=[input_image, output_image, output_heatmap, output_label],
|
| 104 |
queue=True,
|
| 105 |
)
|
| 106 |
-
|
| 107 |
submit_dynamic.click(
|
| 108 |
fn=preprocess_video_and_predict,
|
| 109 |
inputs=input_video,
|
|
|
|
| 1 |
"""
|
| 2 |
File: app.py
|
| 3 |
Author: Dr. Gordon Wright
|
| 4 |
+
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
|
|
|
|
| 14 |
from app.authors import AUTHORS
|
| 15 |
from app.app_utils import preprocess_image_and_predict, preprocess_video_and_predict
|
| 16 |
|
|
|
|
| 17 |
def clear_static_info():
|
| 18 |
return (
|
| 19 |
gr.Image(value=None, type="pil"),
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
with gr.Blocks(css="app.css") as demo:
|
| 35 |
+
# Header with Observatory logo
|
| 36 |
+
with gr.Row(elem_classes="header-container"):
|
| 37 |
+
with gr.Column():
|
| 38 |
+
gr.Image("images/LMLOBS.png", show_label=False, container=False, elem_classes="header-logo")
|
| 39 |
+
|
| 40 |
+
gr.Markdown("# Facial Expression Recognition")
|
| 41 |
+
gr.Markdown("### LittleMonkeyLab | Goldsmiths Observatory")
|
| 42 |
+
|
| 43 |
with gr.Tab("Static Faces"):
|
| 44 |
gr.Markdown(value=DESCRIPTION_STATIC)
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column(scale=2, elem_classes="dl1"):
|
| 47 |
input_image = gr.Image(label="Original image", type="pil")
|
| 48 |
with gr.Row():
|
| 49 |
+
clear_btn = gr.Button(value="Clear", interactive=True, scale=1, elem_classes="clear")
|
| 50 |
+
submit = gr.Button(value="Submit", interactive=True, scale=1, elem_classes="submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
with gr.Column(scale=1, elem_classes="dl4"):
|
| 52 |
with gr.Row():
|
| 53 |
output_image = gr.Image(label="Face", scale=1, elem_classes="dl5")
|
| 54 |
output_heatmap = gr.Image(label="Heatmap", scale=1, elem_classes="dl2")
|
| 55 |
output_label = gr.Label(num_top_classes=3, scale=1, elem_classes="dl3")
|
| 56 |
+
gr.Examples([
|
| 57 |
+
"images/Anger.png",
|
| 58 |
+
"images/contempt.png",
|
| 59 |
+
"images/Disgust.png",
|
| 60 |
+
"images/Happy.png",
|
| 61 |
+
"images/Fear.png",
|
| 62 |
+
"images/Sad.png",
|
| 63 |
+
"images/Surprise.png",
|
| 64 |
+
], [input_image])
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
with gr.Tab("Dynamic Faces"):
|
| 67 |
gr.Markdown(value=DESCRIPTION_DYNAMIC)
|
|
|
|
| 69 |
with gr.Column(scale=2):
|
| 70 |
input_video = gr.Video(elem_classes="video1")
|
| 71 |
with gr.Row():
|
| 72 |
+
clear_btn_dynamic = gr.Button(value="Clear", interactive=True, scale=1)
|
| 73 |
+
submit_dynamic = gr.Button(value="Submit", interactive=True, scale=1, elem_classes="submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
with gr.Column(scale=2, elem_classes="dl4"):
|
| 75 |
with gr.Row():
|
| 76 |
output_video = gr.Video(label="Original video", scale=1, elem_classes="video2")
|
| 77 |
output_face = gr.Video(label="Pre-processed video", scale=1, elem_classes="video3")
|
| 78 |
output_heatmaps = gr.Video(label="Heatmaps", scale=1, elem_classes="video4")
|
| 79 |
output_statistics = gr.Plot(label="Statistics of emotions", elem_classes="stat")
|
| 80 |
+
gr.Examples(["videos/BillClinton.mp4"], [input_video])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
with gr.Tab("References"):
|
| 83 |
gr.Markdown(value=AUTHORS)
|
| 84 |
+
|
| 85 |
+
# Footer with branding
|
| 86 |
+
with gr.Row(elem_classes="center-content"):
|
| 87 |
+
with gr.Column():
|
| 88 |
+
gr.Image("images/LMLLOGO.png", show_label=False, container=False, elem_classes="footer-logo")
|
| 89 |
+
gr.Markdown("© LittleMonkeyLab | Goldsmiths Observatory", elem_classes="footer-text")
|
| 90 |
+
|
| 91 |
submit.click(
|
| 92 |
fn=preprocess_image_and_predict,
|
| 93 |
inputs=[input_image],
|
|
|
|
| 100 |
outputs=[input_image, output_image, output_heatmap, output_label],
|
| 101 |
queue=True,
|
| 102 |
)
|
| 103 |
+
|
| 104 |
submit_dynamic.click(
|
| 105 |
fn=preprocess_video_and_predict,
|
| 106 |
inputs=input_video,
|