Update app.py
Browse files
app.py
CHANGED
|
@@ -192,7 +192,7 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
| 192 |
)
|
| 193 |
|
| 194 |
prompt = "a photo of " + garment_des
|
| 195 |
-
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality
|
| 196 |
if not isinstance(prompt, list):
|
| 197 |
prompt = [prompt] * 1
|
| 198 |
if not isinstance(negative_prompt, list):
|
|
@@ -220,7 +220,7 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
| 220 |
negative_pooled_prompt_embeds=negative_pooled_prompt_embeds.to(device, torch.float16),
|
| 221 |
num_inference_steps=denoise_steps,
|
| 222 |
generator=generator,
|
| 223 |
-
strength=1.
|
| 224 |
pose_img=pose_img.to(device, torch.float16),
|
| 225 |
text_embeds_cloth=prompt_embeds_c.to(device, torch.float16),
|
| 226 |
cloth=garm_tensor.to(device, torch.float16),
|
|
@@ -229,7 +229,7 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
| 229 |
height=1024,
|
| 230 |
width=768,
|
| 231 |
ip_adapter_image=garm_img.resize((768, 1024)),
|
| 232 |
-
guidance_scale=
|
| 233 |
)[0]
|
| 234 |
|
| 235 |
if is_checked_crop:
|
|
@@ -314,6 +314,31 @@ def tryon():
|
|
| 314 |
'mask_image': mask_base64
|
| 315 |
})
|
| 316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
@spaces.GPU
|
| 318 |
def generate_mask(human_img, categorie='upper_body'):
|
| 319 |
device = "cuda"
|
|
@@ -362,27 +387,7 @@ def generate_mask_api():
|
|
| 362 |
logging.error(f"Error generating mask: {e}")
|
| 363 |
return jsonify({'error': str(e)}), 500
|
| 364 |
|
| 365 |
-
# Route index
|
| 366 |
-
@app.route('/', methods=['GET'])
|
| 367 |
-
def index():
|
| 368 |
|
| 369 |
-
# Renvoyer l'image
|
| 370 |
-
try:
|
| 371 |
-
return 'Welcome to IDM VTON API'
|
| 372 |
-
except FileNotFoundError:
|
| 373 |
-
return jsonify({'error': 'Image not found'}), 404
|
| 374 |
-
|
| 375 |
-
# Route pour récupérer l'image générée
|
| 376 |
-
@app.route('/api/get_image/<image_id>', methods=['GET'])
|
| 377 |
-
def get_image(image_id):
|
| 378 |
-
# Construire le chemin complet de l'image
|
| 379 |
-
image_path = image_id # Assurez-vous que le nom de fichier correspond à celui que vous avez utilisé lors de la sauvegarde
|
| 380 |
-
|
| 381 |
-
# Renvoyer l'image
|
| 382 |
-
try:
|
| 383 |
-
return send_file(image_path, mimetype='image/webp')
|
| 384 |
-
except FileNotFoundError:
|
| 385 |
-
return jsonify({'error': 'Image not found'}), 404
|
| 386 |
|
| 387 |
if __name__ == "__main__":
|
| 388 |
app.run(debug=False, host="0.0.0.0", port=7860)
|
|
|
|
| 192 |
)
|
| 193 |
|
| 194 |
prompt = "a photo of " + garment_des
|
| 195 |
+
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality"
|
| 196 |
if not isinstance(prompt, list):
|
| 197 |
prompt = [prompt] * 1
|
| 198 |
if not isinstance(negative_prompt, list):
|
|
|
|
| 220 |
negative_pooled_prompt_embeds=negative_pooled_prompt_embeds.to(device, torch.float16),
|
| 221 |
num_inference_steps=denoise_steps,
|
| 222 |
generator=generator,
|
| 223 |
+
strength=1.0,
|
| 224 |
pose_img=pose_img.to(device, torch.float16),
|
| 225 |
text_embeds_cloth=prompt_embeds_c.to(device, torch.float16),
|
| 226 |
cloth=garm_tensor.to(device, torch.float16),
|
|
|
|
| 229 |
height=1024,
|
| 230 |
width=768,
|
| 231 |
ip_adapter_image=garm_img.resize((768, 1024)),
|
| 232 |
+
guidance_scale=4.0,
|
| 233 |
)[0]
|
| 234 |
|
| 235 |
if is_checked_crop:
|
|
|
|
| 314 |
'mask_image': mask_base64
|
| 315 |
})
|
| 316 |
|
| 317 |
+
|
| 318 |
+
# Route index
|
| 319 |
+
@app.route('/', methods=['GET'])
|
| 320 |
+
def index():
|
| 321 |
+
|
| 322 |
+
# Renvoyer l'image
|
| 323 |
+
try:
|
| 324 |
+
return 'Welcome to IDM VTON API'
|
| 325 |
+
except FileNotFoundError:
|
| 326 |
+
return jsonify({'error': 'Image not found'}), 404
|
| 327 |
+
|
| 328 |
+
# Route pour récupérer l'image générée
|
| 329 |
+
@app.route('/api/get_image/<image_id>', methods=['GET'])
|
| 330 |
+
def get_image(image_id):
|
| 331 |
+
# Construire le chemin complet de l'image
|
| 332 |
+
image_path = image_id # Assurez-vous que le nom de fichier correspond à celui que vous avez utilisé lors de la sauvegarde
|
| 333 |
+
|
| 334 |
+
# Renvoyer l'image
|
| 335 |
+
try:
|
| 336 |
+
return send_file(image_path, mimetype='image/webp')
|
| 337 |
+
except FileNotFoundError:
|
| 338 |
+
return jsonify({'error': 'Image not found'}), 404
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
|
| 342 |
@spaces.GPU
|
| 343 |
def generate_mask(human_img, categorie='upper_body'):
|
| 344 |
device = "cuda"
|
|
|
|
| 387 |
logging.error(f"Error generating mask: {e}")
|
| 388 |
return jsonify({'error': str(e)}), 500
|
| 389 |
|
|
|
|
|
|
|
|
|
|
| 390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
if __name__ == "__main__":
|
| 393 |
app.run(debug=False, host="0.0.0.0", port=7860)
|