Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ import numpy as np
|
|
13 |
from calculations import measure_body_sizes
|
14 |
import gradio as gr
|
15 |
import pandas as pd
|
|
|
|
|
16 |
|
17 |
# Load BodyPix model
|
18 |
bodypix_model = load_model(download_model(BodyPixModelPaths.MOBILENET_FLOAT_50_STRIDE_16))
|
@@ -54,34 +56,33 @@ def process_images(front_img, side_img, real_height_cm):
|
|
54 |
else:
|
55 |
measurements_df.to_csv(csv_file, mode='a', header=False, index=False)
|
56 |
|
57 |
-
# Prepare measurements for display
|
58 |
-
measurement_display = measurements_df.
|
|
|
|
|
59 |
index=False,
|
60 |
justify="center",
|
61 |
border=1,
|
62 |
-
classes="
|
63 |
)
|
64 |
|
65 |
-
# Add CSS styling for the table
|
66 |
css_styles = """
|
67 |
<style>
|
68 |
-
.
|
69 |
-
width:
|
70 |
margin: 0 auto;
|
71 |
border-collapse: collapse;
|
72 |
font-size: 16px;
|
73 |
-
text-align:
|
74 |
}
|
75 |
-
.
|
76 |
border: 1px solid #dddddd;
|
77 |
padding: 8px;
|
78 |
}
|
79 |
-
.
|
80 |
background-color: #f4f4f4;
|
81 |
}
|
82 |
-
.styled-table tr:nth-child(even) {
|
83 |
-
background-color: #f9f9f9;
|
84 |
-
}
|
85 |
</style>
|
86 |
"""
|
87 |
|
@@ -89,22 +90,27 @@ def process_images(front_img, side_img, real_height_cm):
|
|
89 |
{css_styles}
|
90 |
<h3 style="text-align: center;">Body Measurements</h3>
|
91 |
<div style="text-align: center;">
|
92 |
-
|
93 |
</div>
|
94 |
-
{measurement_display}
|
95 |
"""
|
96 |
|
97 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
interface = gr.Interface(
|
99 |
fn=process_images,
|
100 |
inputs=[
|
101 |
-
gr.Image(sources="webcam", type="numpy", label="Front Pose"),
|
102 |
-
gr.Image(sources="webcam", type="numpy", label="Side Pose"),
|
103 |
gr.Number(label="Enter Your Height (cm)")
|
104 |
],
|
105 |
-
outputs=gr.HTML(label="Measurement Results"),
|
106 |
title="Body Sizing System Demo",
|
107 |
-
description="Capture
|
108 |
)
|
109 |
|
110 |
# Launch the app
|
|
|
13 |
from calculations import measure_body_sizes
|
14 |
import gradio as gr
|
15 |
import pandas as pd
|
16 |
+
import time
|
17 |
+
from threading import Timer
|
18 |
|
19 |
# Load BodyPix model
|
20 |
bodypix_model = load_model(download_model(BodyPixModelPaths.MOBILENET_FLOAT_50_STRIDE_16))
|
|
|
56 |
else:
|
57 |
measurements_df.to_csv(csv_file, mode='a', header=False, index=False)
|
58 |
|
59 |
+
# Prepare measurements for vertical display
|
60 |
+
measurement_display = measurements_df.T.reset_index()
|
61 |
+
measurement_display.columns = ["Measurement", "Value"]
|
62 |
+
vertical_table_html = measurement_display.to_html(
|
63 |
index=False,
|
64 |
justify="center",
|
65 |
border=1,
|
66 |
+
classes="vertical-table"
|
67 |
)
|
68 |
|
69 |
+
# Add CSS styling for the vertical table
|
70 |
css_styles = """
|
71 |
<style>
|
72 |
+
.vertical-table {
|
73 |
+
width: 60%;
|
74 |
margin: 0 auto;
|
75 |
border-collapse: collapse;
|
76 |
font-size: 16px;
|
77 |
+
text-align: left;
|
78 |
}
|
79 |
+
.vertical-table th, .vertical-table td {
|
80 |
border: 1px solid #dddddd;
|
81 |
padding: 8px;
|
82 |
}
|
83 |
+
.vertical-table th {
|
84 |
background-color: #f4f4f4;
|
85 |
}
|
|
|
|
|
|
|
86 |
</style>
|
87 |
"""
|
88 |
|
|
|
90 |
{css_styles}
|
91 |
<h3 style="text-align: center;">Body Measurements</h3>
|
92 |
<div style="text-align: center;">
|
93 |
+
{vertical_table_html}
|
94 |
</div>
|
|
|
95 |
"""
|
96 |
|
97 |
+
# Gradio interface with countdown and upload options
|
98 |
+
def start_countdown():
|
99 |
+
for i in range(5, 0, -1):
|
100 |
+
print(f"Capturing in {i} seconds...")
|
101 |
+
time.sleep(1)
|
102 |
+
print("Image captured!")
|
103 |
+
|
104 |
interface = gr.Interface(
|
105 |
fn=process_images,
|
106 |
inputs=[
|
107 |
+
gr.Image(sources=["webcam", "upload"], type="numpy", label="Front Pose"),
|
108 |
+
gr.Image(sources=["webcam", "upload"], type="numpy", label="Side Pose"),
|
109 |
gr.Number(label="Enter Your Height (cm)")
|
110 |
],
|
111 |
+
outputs=gr.HTML(label="Measurement Results"),
|
112 |
title="Body Sizing System Demo",
|
113 |
+
description="Capture images from webcam or upload, and input your height in cm. 5-second countdown included for webcam captures."
|
114 |
)
|
115 |
|
116 |
# Launch the app
|