nami0342 commited on
Commit
5c21454
·
1 Parent(s): eb6ea25

Add parameter validation logic in /vton/

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -307,8 +307,27 @@ async def vton_run(
307
  denoise_steps: int = 30,
308
  seed: int = 42
309
  ):
310
- target_human = Image.open(io.BytesIO(await upload_human.read()))
311
- target_cloth = Image.open(io.BytesIO(await upload_cloth.read()))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
  results = quick_tryon(target_human, target_cloth, input_prompt)
314
 
 
307
  denoise_steps: int = 30,
308
  seed: int = 42
309
  ):
310
+ # Validate file parameters
311
+ if not upload_human or not upload_human.filename:
312
+ return {"error": "Human image file is required"}
313
+ if not upload_cloth or not upload_cloth.filename:
314
+ return {"error": "Cloth image file is required"}
315
+
316
+ # Validate file contents
317
+ human_content = await upload_human.read()
318
+ cloth_content = await upload_cloth.read()
319
+
320
+ if not human_content:
321
+ return {"error": "Human image file is empty"}
322
+ if not cloth_content:
323
+ return {"error": "Cloth image file is empty"}
324
+
325
+ # Reset file pointers for reading
326
+ await upload_human.seek(0)
327
+ await upload_cloth.seek(0)
328
+
329
+ target_human = Image.open(io.BytesIO(human_content))
330
+ target_cloth = Image.open(io.BytesIO(cloth_content))
331
 
332
  results = quick_tryon(target_human, target_cloth, input_prompt)
333