Vlad Iliescu commited on
Commit
fb27a76
·
1 Parent(s): b6b3100

feat: allow sending the raw json input

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +18 -2
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
app.py CHANGED
@@ -191,11 +191,20 @@ def generate(
191
  height=1024,
192
  seed=0,
193
  randomize_seed=False,
 
194
  progress=gr.Progress(track_tqdm=True),
195
  ):
196
  if randomize_seed or seed < 0:
197
  seed = random.randint(0, MAX_SEED)
198
 
 
 
 
 
 
 
 
 
199
  # Remote upsample is a network call -> run it here, OFF the GPU. Fall back to local (on-GPU) on failure.
200
  final_prompt, do_local = prompt, True
201
  if upsampler == UPSAMPLERS[0] and IDEOGRAM_API_KEY:
@@ -251,6 +260,13 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="Ideogram 4", css=CSS) as demo:
251
  label="Prompt upsampler",
252
  info="Rewrite into Ideogram's native JSON caption. Remote (Ideogram) preferred; falls back to local.",
253
  )
 
 
 
 
 
 
 
254
  with gr.Row():
255
  width = gr.Slider(512, 2048, value=1024, step=64, label="Width")
256
  height = gr.Slider(512, 2048, value=1024, step=64, label="Height")
@@ -259,7 +275,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="Ideogram 4", css=CSS) as demo:
259
  randomize = gr.Checkbox(label="Randomize seed", value=True)
260
  with gr.Column():
261
  out_image = gr.Image(label="Output", type="pil")
262
- out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)")
263
 
264
  gr.Examples(
265
  examples=[
@@ -276,7 +292,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="Ideogram 4", css=CSS) as demo:
276
 
277
  run.click(
278
  generate,
279
- inputs=[prompt, mode, upsampler, width, height, seed, randomize],
280
  outputs=[out_image, seed, out_caption],
281
  )
282
 
 
191
  height=1024,
192
  seed=0,
193
  randomize_seed=False,
194
+ raw_json_prompt="",
195
  progress=gr.Progress(track_tqdm=True),
196
  ):
197
  if randomize_seed or seed < 0:
198
  seed = random.randint(0, MAX_SEED)
199
 
200
+ raw_json_prompt = (raw_json_prompt or "").strip()
201
+ if raw_json_prompt:
202
+ try:
203
+ final_prompt = json.dumps(json.loads(raw_json_prompt), ensure_ascii=False, separators=(",", ":"))
204
+ except Exception as e:
205
+ raise gr.Error(f"Raw JSON prompt is not valid JSON: {e}")
206
+ return _gpu_generate(final_prompt, mode, width, height, seed, False)
207
+
208
  # Remote upsample is a network call -> run it here, OFF the GPU. Fall back to local (on-GPU) on failure.
209
  final_prompt, do_local = prompt, True
210
  if upsampler == UPSAMPLERS[0] and IDEOGRAM_API_KEY:
 
260
  label="Prompt upsampler",
261
  info="Rewrite into Ideogram's native JSON caption. Remote (Ideogram) preferred; falls back to local.",
262
  )
263
+ raw_json_prompt = gr.Textbox(
264
+ label="Raw JSON prompt (optional)",
265
+ info="Paste a generated JSON caption here to send it directly to the model, skipping prompt upsampling.",
266
+ lines=8,
267
+ placeholder='{"prompt":"a ginger cat wearing a tiny wizard hat reading a spellbook"}',
268
+ buttons=["copy"],
269
+ )
270
  with gr.Row():
271
  width = gr.Slider(512, 2048, value=1024, step=64, label="Width")
272
  height = gr.Slider(512, 2048, value=1024, step=64, label="Height")
 
275
  randomize = gr.Checkbox(label="Randomize seed", value=True)
276
  with gr.Column():
277
  out_image = gr.Image(label="Output", type="pil")
278
+ out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)", buttons=["copy"])
279
 
280
  gr.Examples(
281
  examples=[
 
292
 
293
  run.click(
294
  generate,
295
+ inputs=[prompt, mode, upsampler, width, height, seed, randomize, raw_json_prompt],
296
  outputs=[out_image, seed, out_caption],
297
  )
298