Gopalag commited on
Commit
46ffada
·
verified ·
1 Parent(s): 70253b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -45
app.py CHANGED
@@ -13,8 +13,6 @@ import numpy as np
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))
@@ -47,6 +45,7 @@ def process_images(front_img, side_img, real_height_cm):
47
 
48
  # Calculate body sizes
49
  body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
 
50
  measurements_df = pd.DataFrame([body_sizes]) if isinstance(body_sizes, dict) else pd.DataFrame(body_sizes)
51
 
52
  # Save measurements to CSV
@@ -56,61 +55,27 @@ def process_images(front_img, side_img, real_height_cm):
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
-
89
  return f"""
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
 
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))
 
45
 
46
  # Calculate body sizes
47
  body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
48
+ print(body_sizes)
49
  measurements_df = pd.DataFrame([body_sizes]) if isinstance(body_sizes, dict) else pd.DataFrame(body_sizes)
50
 
51
  # Save measurements to CSV
 
55
  else:
56
  measurements_df.to_csv(csv_file, mode='a', header=False, index=False)
57
 
58
+ # Prepare measurements for display
59
+ measurement_display = measurements_df.to_html(index=False, justify="center", border=1)
60
+ print(measurement_display)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  return f"""
 
62
  <h3 style="text-align: center;">Body Measurements</h3>
63
  <div style="text-align: center;">
 
64
  </div>
65
+ {measurement_display}
66
  """
67
 
68
+ # Create the Gradio interface
 
 
 
 
 
 
69
  interface = gr.Interface(
70
  fn=process_images,
71
  inputs=[
72
+ gr.Image(sources="webcam", type="numpy", label="Front Pose"),
73
+ gr.Image(sources="webcam", type="numpy", label="Side Pose"),
74
  gr.Number(label="Enter Your Height (cm)")
75
  ],
76
+ outputs=gr.HTML(label="Measurement Results"), # Use HTML output to display the measurements
77
  title="Body Sizing System Demo",
78
+ description="Capture two webcam images: Front View and Side View, and input your height in cm."
79
  )
80
 
81
  # Launch the app