Update app.py
Browse files
app.py
CHANGED
@@ -314,6 +314,33 @@ def tryon():
|
|
314 |
'mask_image': mask_base64
|
315 |
})
|
316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
# Route index
|
319 |
@app.route('/', methods=['GET'])
|
|
|
314 |
'mask_image': mask_base64
|
315 |
})
|
316 |
|
317 |
+
@app.route('/get_mask', methods=['POST'])
|
318 |
+
def get_mask():
|
319 |
+
try:
|
320 |
+
# Récupérer l'image du corps à partir de la requête
|
321 |
+
img_file = request.files['image']
|
322 |
+
img = Image.open(img_file.stream).convert("RGB").resize((384, 512))
|
323 |
+
categorie = request.form.get('categorie', 'upper_body') # Paramètre avec valeur par défaut
|
324 |
+
|
325 |
+
# Appliquer la détection des points clés
|
326 |
+
keypoints = openpose_model(img) # Utilise votre modèle
|
327 |
+
model_parse, _ = parsing_model(img) # Utilise votre modèle
|
328 |
+
|
329 |
+
# Obtenir le masque
|
330 |
+
mask, mask_gray = get_mask_location('hd', categorie , model_parse, keypoints)
|
331 |
+
|
332 |
+
# Convertir le masque en image (si nécessaire)
|
333 |
+
mask_gray = (1 - transforms.ToTensor()(mask_gray)) * tensor_transfrom(img)
|
334 |
+
mask_gray = to_pil_image((mask_gray + 1.0) / 2.0)
|
335 |
+
|
336 |
+
# Convertir l'image en base64 si besoin pour le retour
|
337 |
+
img_byte_arr = io.BytesIO()
|
338 |
+
mask_gray.save(img_byte_arr, format='PNG')
|
339 |
+
img_byte_arr.seek(0)
|
340 |
+
return jsonify({'mask': img_byte_arr.getvalue().decode('latin1')}) # Utiliser une méthode appropriée pour l'encodage
|
341 |
+
|
342 |
+
except Exception as e:
|
343 |
+
return jsonify({'error': str(e)}), 500
|
344 |
|
345 |
# Route index
|
346 |
@app.route('/', methods=['GET'])
|