q6 commited on
Commit
5f3b56f
·
1 Parent(s): 0fb7f80

Return encrypted generation files

Browse files
Files changed (2) hide show
  1. API.md +1 -1
  2. app.py +13 -4
API.md CHANGED
@@ -70,7 +70,7 @@ Content-Type: application/json
70
  }
71
  ```
72
 
73
- Returns a PNG with ComfyUI workflow and parameter metadata, scaled after generation by the decimal `return_scale` from `0.01` through `1`, with content type `image/png`. Regional prompts and their mask nodes are included in the metadata. Use `1` for full resolution. `regions` accepts up to three spatial prompts on a 5 by 5 grid. Set `regional_mode` to `attention` for Attention Couple (PPM), or omit it for soft conditioning. Regional prompts establish subjects from the first sampling step. The reduced-strength global prompt starts after the first fifth to complete the environment while regions remain active. Each internal region edge feathers by half a grid cell, so overlap adjacent regions by one cell for a smooth crossfade. `area` accepts `auto`, `full`, `tl`, `tc`, `tr`, `ml`, `mc`, `mr`, `bl`, `bc`, `br`, `th`, `mh`, `bh`, `lh`, `ch`, or `rh`. It also accepts any single cell from `a1` through `e5`, or a rectangular inclusive range such as `a1:c5`. `auto` places one prompt in the center, two left and right, or three left, center, and right. Columns run left to right and rows run top to bottom. Region strength defaults to `1`. Use the global `prompt` for environment, lighting, shared style, and composition outside regions. Omitting `regions` keeps whole-image generation unchanged. Set either scheduler to `AlignYourSteps` to use `AlignYourStepsScheduler` with fixed model type `SDXL` and the corresponding steps and denoise values. Only `prompt` is required for the built-in site defaults. LoRAs and detailers run in array order. A blank detailer `prompt` or `negative` inherits the matching main prompt. Each request creates fresh sampler seeds. When `upscale` is true, the selected upscaler is normalized to the requested `upscale_scale` resolution before the second sampler. Leave `second_model` empty to reuse the first model and LoRA chain; otherwise `second_loras` applies to the selected second model. Width and height must be multiples of 8 from 64 through 2048; steps must be from 1 through 100.
74
 
75
  ## Archive
76
 
 
70
  }
71
  ```
72
 
73
+ Returns an encrypted `.epng` with ComfyUI workflow and parameter metadata, scaled after generation by the decimal `return_scale` from `0.01` through `1`, with content type `application/octet-stream`. Regional prompts and their mask nodes are included in the metadata. Use `1` for full resolution. `regions` accepts up to three spatial prompts on a 5 by 5 grid. Set `regional_mode` to `attention` for Attention Couple (PPM), or omit it for soft conditioning. Regional prompts establish subjects from the first sampling step. The reduced-strength global prompt starts after the first fifth to complete the environment while regions remain active. Each internal region edge feathers by half a grid cell, so overlap adjacent regions by one cell for a smooth crossfade. `area` accepts `auto`, `full`, `tl`, `tc`, `tr`, `ml`, `mc`, `mr`, `bl`, `bc`, `br`, `th`, `mh`, `bh`, `lh`, `ch`, or `rh`. It also accepts any single cell from `a1` through `e5`, or a rectangular inclusive range such as `a1:c5`. `auto` places one prompt in the center, two left and right, or three left, center, and right. Columns run left to right and rows run top to bottom. Region strength defaults to `1`. Use the global `prompt` for environment, lighting, shared style, and composition outside regions. Omitting `regions` keeps whole-image generation unchanged. Set either scheduler to `AlignYourSteps` to use `AlignYourStepsScheduler` with fixed model type `SDXL` and the corresponding steps and denoise values. Only `prompt` is required for the built-in site defaults. LoRAs and detailers run in array order. A blank detailer `prompt` or `negative` inherits the matching main prompt. Each request creates fresh sampler seeds. When `upscale` is true, the selected upscaler is normalized to the requested `upscale_scale` resolution before the second sampler. Leave `second_model` empty to reuse the first model and LoRA chain; otherwise `second_loras` applies to the selected second model. Width and height must be multiples of 8 from 64 through 2048; steps must be from 1 through 100.
74
 
75
  ## Archive
76
 
app.py CHANGED
@@ -2040,7 +2040,11 @@ def api_generate(body, p=""):
2040
  if not valid_pass(p):
2041
  raise gr.Error("Invalid password")
2042
 
2043
- return generate_image(DirectRequest.model_validate_json(body))
 
 
 
 
2044
 
2045
 
2046
  def api_health(p=""):
@@ -2117,7 +2121,7 @@ def queued_generate(request):
2117
  PASSWORD,
2118
  api_name="/generate",
2119
  )
2120
- return Image.open(result).copy()
2121
 
2122
 
2123
  def queued_matrix_cell(request):
@@ -2643,7 +2647,11 @@ def direct(
2643
  Image.Resampling.LANCZOS,
2644
  )
2645
 
2646
- return Response(content=image_png_bytes(image), media_type="image/png")
 
 
 
 
2647
 
2648
 
2649
  @api.post(
@@ -3083,6 +3091,7 @@ with gr.Blocks(title="Image generation") as demo:
3083
  api_pass_input = gr.Textbox(visible=False)
3084
  request_input = gr.Textbox(visible=False)
3085
  api_json_output = gr.JSON(visible=False)
 
3086
  matrix_output = gr.Textbox(visible=False)
3087
  login_button.click(
3088
  login,
@@ -3184,7 +3193,7 @@ with gr.Blocks(title="Image generation") as demo:
3184
  request_input,
3185
  api_pass_input,
3186
  ],
3187
- output,
3188
  api_name="generate",
3189
  )
3190
 
 
2040
  if not valid_pass(p):
2041
  raise gr.Error("Invalid password")
2042
 
2043
+ image = generate_image(DirectRequest.model_validate_json(body))
2044
+ temp = tempfile.NamedTemporaryFile(suffix=".epng", delete=False)
2045
+ temp.write(encrypted_image_bytes(image))
2046
+ temp.close()
2047
+ return temp.name
2048
 
2049
 
2050
  def api_health(p=""):
 
2121
  PASSWORD,
2122
  api_name="/generate",
2123
  )
2124
+ return Image.open(BytesIO(stored_bytes(Path(result)))).copy()
2125
 
2126
 
2127
  def queued_matrix_cell(request):
 
2647
  Image.Resampling.LANCZOS,
2648
  )
2649
 
2650
+ return Response(
2651
+ content=encrypted_image_bytes(image),
2652
+ media_type="application/octet-stream",
2653
+ headers={"Content-Disposition": 'attachment; filename="image.epng"'},
2654
+ )
2655
 
2656
 
2657
  @api.post(
 
3091
  api_pass_input = gr.Textbox(visible=False)
3092
  request_input = gr.Textbox(visible=False)
3093
  api_json_output = gr.JSON(visible=False)
3094
+ api_file_output = gr.File(visible=False)
3095
  matrix_output = gr.Textbox(visible=False)
3096
  login_button.click(
3097
  login,
 
3193
  request_input,
3194
  api_pass_input,
3195
  ],
3196
+ api_file_output,
3197
  api_name="generate",
3198
  )
3199