nikdevs commited on
Commit
157e551
·
verified ·
1 Parent(s): eaeaa63

handler: support image_format/webp/quality and guidance alias for flowcore client compat

Browse files
Files changed (1) hide show
  1. worker/handler.py +5 -4
worker/handler.py CHANGED
@@ -122,7 +122,7 @@ def handler(job):
122
  w, h = max(64, w - w % 16), max(64, h - h % 16)
123
 
124
  steps = int(inp.get("num_inference_steps", inp.get("steps", 8)))
125
- cfg = float(inp.get("true_cfg_scale", inp.get("cfg", 1.0)))
126
  num_images = min(int(inp.get("num_images", 1)), 4)
127
  seed = inp.get("seed")
128
  if seed is None or int(seed) < 0:
@@ -163,12 +163,13 @@ def handler(job):
163
  ).images
164
  timings["generate_s"] = round(time.time() - t, 1)
165
 
166
- fmt = str(inp.get("output_format", "png")).lower()
167
- fmt = "JPEG" if fmt in ("jpg", "jpeg") else "PNG"
 
168
  out = []
169
  for img in images:
170
  buf = io.BytesIO()
171
- img.save(buf, format=fmt, quality=95)
172
  out.append(base64.b64encode(buf.getvalue()).decode())
173
  return {"images": out, "seed": seed, "width": w, "height": h, "timings": timings}
174
  except Exception as e:
 
122
  w, h = max(64, w - w % 16), max(64, h - h % 16)
123
 
124
  steps = int(inp.get("num_inference_steps", inp.get("steps", 8)))
125
+ cfg = float(inp.get("true_cfg_scale", inp.get("cfg", inp.get("guidance", 1.0))))
126
  num_images = min(int(inp.get("num_images", 1)), 4)
127
  seed = inp.get("seed")
128
  if seed is None or int(seed) < 0:
 
163
  ).images
164
  timings["generate_s"] = round(time.time() - t, 1)
165
 
166
+ fmt = str(inp.get("output_format") or inp.get("image_format") or "png").lower()
167
+ fmt = {"jpg": "JPEG", "jpeg": "JPEG", "webp": "WEBP"}.get(fmt, "PNG")
168
+ quality = int(inp.get("image_quality", 95))
169
  out = []
170
  for img in images:
171
  buf = io.BytesIO()
172
+ img.save(buf, format=fmt, quality=quality)
173
  out.append(base64.b64encode(buf.getvalue()).decode())
174
  return {"images": out, "seed": seed, "width": w, "height": h, "timings": timings}
175
  except Exception as e: