Saad0KH commited on
Commit
2edf2fd
Β·
verified Β·
1 Parent(s): 6c6a5cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -58,7 +58,7 @@ def detect_and_segment_persons(image, clothes):
58
 
59
  bboxes, kpss = detector.detect(img)
60
  if bboxes.shape[0] == 0: # Aucun visage dΓ©tectΓ©
61
- return [encode_image_to_base64(image)]
62
 
63
  height, width, _ = img.shape # Get image dimensions
64
 
@@ -80,13 +80,18 @@ def detect_and_segment_persons(image, clothes):
80
  pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
81
 
82
  # Segment clothing for the detected person
83
- segmented_result = segment_clothing(pil_img, clothes)
 
84
 
85
  # Combine the segmented images for all persons
86
  all_segmented_images.extend(segmented_result)
87
 
88
  return all_segmented_images
89
 
 
 
 
 
90
  @app.route('/api/detect', methods=['POST'])
91
  def detect():
92
  try:
@@ -104,4 +109,4 @@ def detect():
104
  return jsonify({'error': str(e)}), 500
105
 
106
  if __name__ == "__main__":
107
- app.run(debug=True, host="0.0.0.0", port=7860)
 
58
 
59
  bboxes, kpss = detector.detect(img)
60
  if bboxes.shape[0] == 0: # Aucun visage dΓ©tectΓ©
61
+ return []
62
 
63
  height, width, _ = img.shape # Get image dimensions
64
 
 
80
  pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
81
 
82
  # Segment clothing for the detected person
83
+ img_rm_background = remove_background(pil_img)
84
+ segmented_result = segment_clothing(img_rm_background, clothes)
85
 
86
  # Combine the segmented images for all persons
87
  all_segmented_images.extend(segmented_result)
88
 
89
  return all_segmented_images
90
 
91
+ @app.route('/', methods=['GET'])
92
+ def welcome():
93
+ return "Welcome to Clothing Segmentation API"
94
+
95
  @app.route('/api/detect', methods=['POST'])
96
  def detect():
97
  try:
 
109
  return jsonify({'error': str(e)}), 500
110
 
111
  if __name__ == "__main__":
112
+ app.run(debug=True, host="0.0.0.0", port=7860)