LogicGoInfotechSpaces commited on
Commit
be32143
·
1 Parent(s): 81334f2

Add /api/image-edit endpoint for image upload and result API

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -390,6 +390,32 @@ _register_attribute_endpoint("/api/orange-hair-text", "Orange hair (text)")
390
  _register_attribute_endpoint("/api/blonde-hair-text", "Blonde hair (text)")
391
 
392
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  # Mount Gradio under /app and expose FastAPI at root for clean API base
394
  app = gr.mount_gradio_app(api, demo, path="/app")
395
 
 
390
  _register_attribute_endpoint("/api/blonde-hair-text", "Blonde hair (text)")
391
 
392
 
393
+ @app.post("/api/image-edit")
394
+ async def api_image_edit(
395
+ file: UploadFile = File(...),
396
+ attribute: str = Form("Smile"),
397
+ strength: float = Form(5.0),
398
+ align_face: bool = Form(False),
399
+ use_bg_mask: bool = Form(False),
400
+ custom_text_edit: str = Form("")
401
+ ):
402
+ data = await file.read()
403
+ image = Image.open(io.BytesIO(data)).convert("RGB")
404
+
405
+ result = run_edit(
406
+ image=image,
407
+ attribute=attribute,
408
+ strength=strength,
409
+ align_face=align_face,
410
+ use_bg_mask=use_bg_mask,
411
+ custom_text_edit=custom_text_edit
412
+ )
413
+ buf = io.BytesIO()
414
+ result.save(buf, format="PNG")
415
+ buf.seek(0)
416
+ return StreamingResponse(buf, media_type="image/png")
417
+
418
+
419
  # Mount Gradio under /app and expose FastAPI at root for clean API base
420
  app = gr.mount_gradio_app(api, demo, path="/app")
421