Gopalag commited on
Commit
8d1e04a
·
verified ·
1 Parent(s): aa06746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -30,7 +30,7 @@ def process_images(front_img, side_img, real_height_cm):
30
  fimage_array = preprocessing.image.img_to_array(front_img)
31
  simage_array = preprocessing.image.img_to_array(side_img)
32
 
33
- # bodypix prediction
34
  frontresult = bodypix_model.predict_single(fimage_array)
35
  sideresult = bodypix_model.predict_single(simage_array)
36
 
@@ -41,32 +41,28 @@ def process_images(front_img, side_img, real_height_cm):
41
  side_colored_mask = sideresult.get_colored_part_mask(side_mask, rainbow)
42
 
43
  frontposes = frontresult.get_poses()
44
- front_image_with_poses = draw_poses(
45
- fimage_array.copy(),
46
- frontposes,
47
- keypoints_color=(255, 100, 100),
48
- skeleton_color=(100, 100, 255)
49
- )
50
-
51
  sideposes = sideresult.get_poses()
52
- side_image_with_poses = draw_poses(
53
- simage_array.copy(),
54
- sideposes,
55
- keypoints_color=(255, 100, 100),
56
- skeleton_color=(100, 100, 255)
57
- )
58
 
59
  body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
60
  measurements_df = pd.DataFrame([body_sizes]) if isinstance(body_sizes, dict) else pd.DataFrame(body_sizes)
 
 
61
  csv_file = "Body-measurement.csv"
62
  if not os.path.exists(csv_file):
63
- # Save as a new file if it doesn't exist
64
  measurements_df.to_csv(csv_file, index=False)
65
  else:
66
- # Append to the existing file
67
  measurements_df.to_csv(csv_file, mode='a', header=False, index=False)
68
-
69
- return "Your body part measured and saved to the database."
 
 
 
 
 
 
 
 
 
70
 
71
  # Create the Gradio interface
72
  interface = gr.Interface(
@@ -76,7 +72,7 @@ interface = gr.Interface(
76
  gr.Image(sources="webcam", type="numpy", label="Side Pose"),
77
  gr.Number(label="Enter Your Height (cm)")
78
  ],
79
- outputs=gr.Textbox(label="Confirmation Message"), # Confirmation message output
80
  title="Body Sizing System Demo",
81
  description="Capture two webcam images: Front View and Side View, and input your height in cm."
82
  )
 
30
  fimage_array = preprocessing.image.img_to_array(front_img)
31
  simage_array = preprocessing.image.img_to_array(side_img)
32
 
33
+ # BodyPix prediction
34
  frontresult = bodypix_model.predict_single(fimage_array)
35
  sideresult = bodypix_model.predict_single(simage_array)
36
 
 
41
  side_colored_mask = sideresult.get_colored_part_mask(side_mask, rainbow)
42
 
43
  frontposes = frontresult.get_poses()
 
 
 
 
 
 
 
44
  sideposes = sideresult.get_poses()
 
 
 
 
 
 
45
 
46
  body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
47
  measurements_df = pd.DataFrame([body_sizes]) if isinstance(body_sizes, dict) else pd.DataFrame(body_sizes)
48
+
49
+ # Save measurements to CSV
50
  csv_file = "Body-measurement.csv"
51
  if not os.path.exists(csv_file):
 
52
  measurements_df.to_csv(csv_file, index=False)
53
  else:
 
54
  measurements_df.to_csv(csv_file, mode='a', header=False, index=False)
55
+
56
+ # Format measurements as HTML
57
+ measurements_html = measurements_df.to_html(index=False, justify="center", border=1)
58
+
59
+ return f"""
60
+ <h3 style="text-align: center;">Body Measurements</h3>
61
+ <div style="text-align: center;">
62
+ <img src="https://huggingface.co/front-logo.png" alt="Hugging Face Logo" style="width: 100px; margin-bottom: 20px;"/>
63
+ </div>
64
+ {measurements_html}
65
+ """
66
 
67
  # Create the Gradio interface
68
  interface = gr.Interface(
 
72
  gr.Image(sources="webcam", type="numpy", label="Side Pose"),
73
  gr.Number(label="Enter Your Height (cm)")
74
  ],
75
+ outputs=gr.HTML(label="Measurement Results"), # Use HTML output to display the logo and measurements
76
  title="Body Sizing System Demo",
77
  description="Capture two webcam images: Front View and Side View, and input your height in cm."
78
  )