Hammad712 commited on
Commit
7bb1cd2
·
verified ·
1 Parent(s): 3991abb

Update app/api/image_router.py

Browse files
Files changed (1) hide show
  1. 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 textual description.
182
- Streams the first generated image back; if no image, returns JSON with model text.
183
  """
184
- logger.info("Received request to /generate-shoe: %s", request.style[:80])
185
 
186
- if not request.style:
187
- raise HTTPException(status_code=400, detail="`style` is required.")
188
 
189
  try:
190
- gen_text, images = generate_shoe_images(
191
- style=request.style,
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 (consistent with other endpoints)
199
  img_io: BytesIO = images[0]
200
  img_io.seek(0)
201
  return StreamingResponse(img_io, media_type="image/png")
202
  else:
203
- # If no image was produced, return any model text or an error summary as JSON
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