Spaces:
Runtime error
Runtime error
Update app/api/image_router.py
Browse files- app/api/image_router.py +9 -13
app/api/image_router.py
CHANGED
|
@@ -178,29 +178,25 @@ async def virtual_try_on(
|
|
| 178 |
@router.post("/generate-shoe", response_class=StreamingResponse)
|
| 179 |
async def generate_shoe(request: ShoeGenerateRequest):
|
| 180 |
"""
|
| 181 |
-
Generate shoe product images from a
|
| 182 |
-
Streams the first generated image back
|
| 183 |
"""
|
| 184 |
-
logger.info("Received request to /generate-shoe: %s", request.
|
| 185 |
|
| 186 |
-
if not request.
|
| 187 |
-
raise HTTPException(status_code=400, detail="`
|
| 188 |
|
| 189 |
try:
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
color=request.color,
|
| 193 |
-
perspective=request.perspective,
|
| 194 |
-
variations=request.variations or 1,
|
| 195 |
-
)
|
| 196 |
|
| 197 |
if images and len(images) > 0:
|
| 198 |
-
# Stream the first image
|
| 199 |
img_io: BytesIO = images[0]
|
| 200 |
img_io.seek(0)
|
| 201 |
return StreamingResponse(img_io, media_type="image/png")
|
| 202 |
else:
|
| 203 |
-
#
|
| 204 |
detail = {"success": False, "notes": "No image generated."}
|
| 205 |
if gen_text:
|
| 206 |
detail["model_text"] = gen_text
|
|
|
|
| 178 |
@router.post("/generate-shoe", response_class=StreamingResponse)
|
| 179 |
async def generate_shoe(request: ShoeGenerateRequest):
|
| 180 |
"""
|
| 181 |
+
Generate shoe product images from a raw prompt.
|
| 182 |
+
Streams the first generated image back.
|
| 183 |
"""
|
| 184 |
+
logger.info("Received request to /generate-shoe: %s", request.prompt[:80])
|
| 185 |
|
| 186 |
+
if not request.prompt:
|
| 187 |
+
raise HTTPException(status_code=400, detail="`prompt` field is required.")
|
| 188 |
|
| 189 |
try:
|
| 190 |
+
# Call service with the raw prompt
|
| 191 |
+
gen_text, images = generate_shoe_images(prompt=request.prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
if images and len(images) > 0:
|
| 194 |
+
# Stream the first image
|
| 195 |
img_io: BytesIO = images[0]
|
| 196 |
img_io.seek(0)
|
| 197 |
return StreamingResponse(img_io, media_type="image/png")
|
| 198 |
else:
|
| 199 |
+
# Handle failure / text-only response
|
| 200 |
detail = {"success": False, "notes": "No image generated."}
|
| 201 |
if gen_text:
|
| 202 |
detail["model_text"] = gen_text
|