znchen commited on
Commit
a97032a
1 Parent(s): 5a60a35
Files changed (3) hide show
  1. app.py +43 -90
  2. assets/run_num.txt +1 -1
  3. assets/title.md +1 -1
app.py CHANGED
@@ -16,7 +16,7 @@ from RAG_pipeline_flux import RAG_FluxPipeline
16
 
17
  MAX_SEED = 999999
18
 
19
- pipe = RAG_FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
20
  pipe = pipe.to("cuda")
21
 
22
  global run_nums
@@ -36,15 +36,30 @@ def read_run_num():
36
  return run_num
37
 
38
  def get_box_inputs(prompts):
 
 
 
 
 
 
 
 
 
 
 
39
  box_inputs = []
 
40
  for prompt in prompts:
 
41
  if prompt[2] == 2.0 and prompt[5] == 3.0:
42
  box_inputs.append((prompt[0], prompt[1], prompt[3], prompt[4]))
43
  return box_inputs
44
 
45
  @spaces.GPU
46
  def rag_gen(
47
- box_prompt_image,
 
 
48
  prompt,
49
  coarse_prompt,
50
  detailed_prompt,
@@ -53,8 +68,9 @@ def rag_gen(
53
  num_inference_steps,
54
  guidance_scale,
55
  seed,
56
- randomize_seed):
57
- points, image = box_prompt_image['points'], box_prompt_image['image']
 
58
  print("points", points)
59
  box_inputs = get_box_inputs(points)
60
  # prompt_img_height, prompt_img_width, _ = image.shape
@@ -63,11 +79,6 @@ def rag_gen(
63
  # GREEN = (36, 255, 12)
64
 
65
  HB_prompt_list = coarse_prompt.split("BREAK")
66
- # print("HB_prompt_list",HB_prompt_list)
67
- # for i, box in enumerate(box_inputs):
68
- # x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
69
- # cv2.rectangle(image, (x1, y1), (x2, y2), GREEN, 2)
70
- # cv2.putText(image, HB_prompt_list[i], (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.9, GREEN, 2)
71
 
72
 
73
  HB_m_offset_list, HB_n_offset_list, HB_m_scale_list, HB_n_scale_list, SR_hw_split_ratio = generate_parameters(box_inputs, prompt_img_width, prompt_img_height)
@@ -168,39 +179,31 @@ with gr.Blocks(css=css) as demo:
168
  )
169
 
170
  coarse_prompt = gr.Textbox(
171
- label="Regional Fundamental Prompt(BREAK is a delimiter.)",
172
  placeholder="Enter your prompt",
173
  lines=2
174
  )
175
 
176
  detailed_prompt = gr.Textbox(
177
- label="Regional Highly descriptive Prompt(BREAK is a delimiter.)",
178
  placeholder="Enter your prompt",
179
  lines=2
180
  )
181
 
182
 
183
  with gr.Column(elem_id="col-left"):
184
-
185
- # gr.HTML("""
186
- # <div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
187
- # <div>
188
- # Step 1. First Plot Layout ⬇️
189
- # </div>
190
- # </div>
191
- # <div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 10px;">
192
- # <div>
193
- # Please do not click the 'x' button; otherwise please refresh the webpage.
194
- # </div>
195
- # </div>
196
- # """)
197
 
198
  default_image_path = "assets/images_template.png"
199
- box_prompt_image = BoxPromptableImage(
200
  show_label=False,
201
  interactive=False,
202
  label="Layout",
203
- value={"image": default_image_path})
 
 
 
 
 
204
  # box_prompt_image = gr.Image(label="Layout", show_label=True)
205
 
206
  gr.HTML("""
@@ -277,15 +280,17 @@ with gr.Blocks(css=css) as demo:
277
 
278
  with gr.Row():
279
  button = gr.Button("Run", elem_id="button")
280
-
281
-
282
  gr.on(
283
  triggers=[
284
  button.click,
285
  ],
286
  fn=rag_gen,
 
287
  inputs=[
288
- box_prompt_image,
 
289
  prompt,
290
  coarse_prompt,
291
  detailed_prompt,
@@ -293,7 +298,7 @@ with gr.Blocks(css=css) as demo:
293
  SR_delta,
294
  num_inference_steps,
295
  guidance_scale, seed,
296
- randomize_seed
297
  ],
298
  # outputs=[layout, result, seed, run_nums_box],
299
  outputs=[result, seed, run_nums_box],
@@ -306,8 +311,8 @@ with gr.Blocks(css=css) as demo:
306
  # label="Layout Example (For more complex layouts, please run our code directly.)",
307
  examples=[
308
  [
 
309
  "assets/case1.png",
310
- [[0.05*1024, 0.05*1024, 2.0, (0.05+0.40)*1024, (0.05+0.9)*1024, 3.0], [0.5*1024, 0.05*1024, 2.0, (0.5+0.45)*1024, (0.05+0.9)*1024, 3.0]], # BoxPromptableImage
311
  "a man is holding a bag, a man is talking on a cell phone.", # prompt
312
  "A man holding a bag. BREAK a man holding a cell phone to his ear.", # coarse_prompt
313
  "A man holding a bag, gripping it firmly, with a casual yet purposeful stance. BREAK a man, engaged in conversation, holding a cell phone to his ear.", # detailed_prompt
@@ -319,8 +324,8 @@ with gr.Blocks(css=css) as demo:
319
  False, # randomize_seed
320
  ],
321
  [
 
322
  "assets/case2.png",
323
- [[20.0, 425.0, 2.0, 551.0, 1008.0, 3.0], [615.0, 84.0, 2.0, 1000.0, 389.0, 3.0]], # BoxPromptableImage
324
  "A woman looking at the moon", # prompt
325
  "a woman BREAK a moon", # coarse_prompt
326
  "A woman, standing gracefully, her gaze fixed on the sky with a sense of wonder. BREAK The moon, luminous and full, casting a soft glow across the tranquil night.", # detailed_prompt
@@ -332,8 +337,8 @@ with gr.Blocks(css=css) as demo:
332
  False, # randomize_seed
333
  ],
334
  [
335
- "assets/case3.png",
336
- [[0.2*1024, 0.1*1024, 2.0, (0.2+0.6)*1024, (0.1+0.4)*1024, 3.0],[0.2*1024, 0.6*1024, 2.0, (0.2+0.6)*1024, (0.6+0.35)*1024, 3.0]], # BoxPromptableImage
337
  "a turtle on the bottom of a phone", # prompt
338
  "Phone BREAK Turtle", # coarse_prompt
339
  "The phone, placed above the turtle, potentially with its screen or back visible, its sleek design prominent. BREAK The turtle, below the phone, with its shell textured and detailed, eyes slightly protruding as it looks upward.", # detailed_prompt
@@ -345,8 +350,8 @@ with gr.Blocks(css=css) as demo:
345
  False, # randomize_seed
346
  ],
347
  [
 
348
  "assets/case4.png",
349
- [[9.0, 153.0, 2.0, 343.0, 959.0, 3.0], [376.0, 145.0, 2.0, 692.0, 959.0, 3.0], [715.0, 143.0, 2.0, 1015.0, 956.0, 3.0]], # BoxPromptableImage
350
  "From left to right, a blonde ponytail Europe girl in white shirt, a brown curly hair African girl in blue shirt printed with a bird, an Asian young man with black short hair in suit are walking in the campus happily.", # prompt
351
  "A blonde ponytail European girl in a white shirt BREAK A brown curly hair African girl in a blue shirt printed with a bird BREAK An Asian young man with black short hair in a suit", # coarse_prompt
352
  "A blonde ponytail European girl in a crisp white shirt, walking with a light smile. Her ponytail swings slightly as she enjoys the lively atmosphere of the campus. BREAK A brown curly hair African girl, her vibrant blue shirt adorned with a bird print. Her joyful expression matches her energetic stride as her curls bounce lightly in the breeze. BREAK An Asian young man in a sharp suit, his black short hair neatly styled, walking confidently alongside the two girls. His suit contrasts with the casual campus environment, adding an air of professionalism to the scene.", # detailed_prompt
@@ -357,62 +362,10 @@ with gr.Blocks(css=css) as demo:
357
  1234, # seed
358
  False, # randomize_seed
359
  ],
360
- # [
361
- # {"image": "assets/case1.png", "points": [[0.1*1024, 0.55*1024, 2.0, (0.1+0.8)*1024, (0.55+0.4)*1024, 3.0],[0.1*1024, 0.05*1024, 2.0, (0.1+0.8)*1024, (0.05+0.45)*1024, 3.0]]}, # BoxPromptableImage
362
- # "a balloon on the bottom of a dog", # prompt
363
- # "Balloon BREAK Dog", # coarse_prompt
364
- # "A playful dog, perhaps a golden retriever, with its ears perked up, sitting on the balloon, giving an enthusiastic demeanor. BREAK A colorful balloon floating gently, its string dangling gracefully, just beneath the dog.", # detailed_prompt
365
- # 2, # HB_replace
366
- # 1.0, # SR_delta
367
- # 20, # num_inference_steps
368
- # 3.5, # guidance_scale
369
- # 1234, # seed
370
- # False, # randomize_seed
371
- # ],
372
-
373
- # [
374
- # {
375
- # "image": "assets/images_template.png", "points": [[9.0, 153.0, 2.0, 343.0, 959.0, 3.0], [376.0, 145.0, 2.0, 692.0, 959.0, 3.0], [715.0, 143.0, 2.0, 1015.0, 956.0, 3.0]]}, # BoxPromptableImage
376
- # "From left to right, a blonde ponytail Europe girl in white shirt, a brown curly hair African girl in blue shirt printed with a bird, an Asian young man with black short hair in suit are walking in the campus happily.", # prompt
377
- # "A blonde ponytail European girl in a white shirt BREAK A brown curly hair African girl in a blue shirt printed with a bird BREAK An Asian young man with black short hair in a suit", # coarse_prompt
378
- # "A blonde ponytail European girl in a crisp white shirt, walking with a light smile. Her ponytail swings slightly as she enjoys the lively atmosphere of the campus. BREAK A brown curly hair African girl, her vibrant blue shirt adorned with a bird print. Her joyful expression matches her energetic stride as her curls bounce lightly in the breeze. BREAK An Asian young man in a sharp suit, his black short hair neatly styled, walking confidently alongside the two girls. His suit contrasts with the casual campus environment, adding an air of professionalism to the scene.", # detailed_prompt
379
- # 2, # HB_replace
380
- # 1.0, # SR_delta
381
- # 20, # num_inference_steps
382
- # 3.5, # guidance_scale
383
- # 1234, # seed
384
- # False, # randomize_seed
385
- # ],
386
- # [
387
- # {
388
- # "image": "assets/images_template.png", "points": [[9.0, 153.0, 2.0, 343.0, 959.0, 3.0], [376.0, 145.0, 2.0, 692.0, 959.0, 3.0], [715.0, 143.0, 2.0, 1015.0, 956.0, 3.0]]}, # BoxPromptableImage
389
- # "From left to right, a blonde ponytail Europe girl in white shirt, a brown curly hair African girl in blue shirt printed with a bird, an Asian young man with black short hair in suit are walking in the campus happily.", # prompt
390
- # "A blonde ponytail European girl in a white shirt BREAK A brown curly hair African girl in a blue shirt printed with a bird BREAK An Asian young man with black short hair in a suit", # coarse_prompt
391
- # "A blonde ponytail European girl in a crisp white shirt, walking with a light smile. Her ponytail swings slightly as she enjoys the lively atmosphere of the campus. BREAK A brown curly hair African girl, her vibrant blue shirt adorned with a bird print. Her joyful expression matches her energetic stride as her curls bounce lightly in the breeze. BREAK An Asian young man in a sharp suit, his black short hair neatly styled, walking confidently alongside the two girls. His suit contrasts with the casual campus environment, adding an air of professionalism to the scene.", # detailed_prompt
392
- # 2, # HB_replace
393
- # 1.0, # SR_delta
394
- # 20, # num_inference_steps
395
- # 3.5, # guidance_scale
396
- # 1234, # seed
397
- # False, # randomize_seed
398
- # ],
399
- # [
400
- # {
401
- # "image": "assets/case1.png", "points": [[0.02*1024, 0.1*1024, 2.0, (0.02+0.21)*1024, (0.1+0.8)*1024, 3.0], [0.27*1024, 0.1*1024, 2.0, (0.27+0.21)*1024, (0.1+0.8)*1024, 3.0], [0.51*1024, 0.1*1024, 2.0, (0.51+0.21)*1024, (0.1+0.8)*1024, 3.0], [0.77*1024, 0.1*1024, 2.0, (0.77+0.21)*1024, (0.1+0.8)*1024, 3.0]]}, # BoxPromptableImage
402
- # "From left to right, Pink blossoming trees, Green sycamore trees, Golden maples and Snow-blanketed pines", # prompt
403
- # "Pink blossoming trees BREAK Green sycamore trees BREAK Golden maples BREAK Snow-blanketed pines", # coarse_prompt
404
- # "Pink blossoming trees fill the atmosphere with a delicate charm, their petals creating a soft carpet beneath them. BREAK Green sycamore trees stand tall and sturdy, their broad leaves casting a lush shade over the ground. BREAK Golden maples display a vibrant hue, their leaves shimmering like gold coins under the sun. BREAK Snow-blanketed pines offer a serene contrast, their branches heavy with snow, creating an image of winter quietude.", # detailed_prompt
405
- # 2, # HB_replace
406
- # 1.0, # SR_delta
407
- # 20, # num_inference_steps
408
- # 3.5, # guidance_scale
409
- # 1236, # seed
410
- # False, # randomize_seed
411
- # ],
412
  ],
413
  inputs=[
414
- box_prompt_image.image,
415
- box_prompt_image.points,
416
  prompt,
417
  coarse_prompt,
418
  detailed_prompt,
@@ -424,7 +377,7 @@ with gr.Blocks(css=css) as demo:
424
  randomize_seed
425
  ],
426
  outputs=None,
427
- fn=None,
428
  cache_examples=False,
429
  )
430
 
 
16
 
17
  MAX_SEED = 999999
18
 
19
+ pipe = RAG_FluxPipeline.from_pretrained("/nasdata/znchen/nju_reseach/FLUX.1-dev/", torch_dtype=torch.bfloat16)
20
  pipe = pipe.to("cuda")
21
 
22
  global run_nums
 
36
  return run_num
37
 
38
  def get_box_inputs(prompts):
39
+
40
+ # if isinstance(prompts, str):
41
+ # prompts = json.loads(prompts)
42
+ if prompts=="layout1":
43
+ prompts=[[0.05*1024, 0.05*1024, 2.0, (0.05+0.40)*1024, (0.05+0.9)*1024, 3.0], [0.5*1024, 0.05*1024, 2.0, (0.5+0.45)*1024, (0.05+0.9)*1024, 3.0]]
44
+ elif prompts=="layout2":
45
+ prompts=[[20.0, 425.0, 2.0, 551.0, 1008.0, 3.0], [615.0, 84.0, 2.0, 1000.0, 389.0, 3.0]]
46
+ elif prompts=="layout3":
47
+ prompts=[[0.2*1024, 0.1*1024, 2.0, (0.2+0.6)*1024, (0.1+0.4)*1024, 3.0],[0.2*1024, 0.6*1024, 2.0, (0.2+0.6)*1024, (0.6+0.35)*1024, 3.0]]
48
+ elif prompts=="layout4":
49
+ prompts=[[9.0, 153.0, 2.0, 343.0, 959.0, 3.0], [376.0, 145.0, 2.0, 692.0, 959.0, 3.0], [715.0, 143.0, 2.0, 1015.0, 956.0, 3.0]]
50
  box_inputs = []
51
+
52
  for prompt in prompts:
53
+ # print("prompt",prompt)
54
  if prompt[2] == 2.0 and prompt[5] == 3.0:
55
  box_inputs.append((prompt[0], prompt[1], prompt[3], prompt[4]))
56
  return box_inputs
57
 
58
  @spaces.GPU
59
  def rag_gen(
60
+ # box_prompt_image,
61
+ box_point,
62
+ box_image,
63
  prompt,
64
  coarse_prompt,
65
  detailed_prompt,
 
68
  num_inference_steps,
69
  guidance_scale,
70
  seed,
71
+ randomize_seed,
72
+ ):
73
+ points, image = box_point, box_image
74
  print("points", points)
75
  box_inputs = get_box_inputs(points)
76
  # prompt_img_height, prompt_img_width, _ = image.shape
 
79
  # GREEN = (36, 255, 12)
80
 
81
  HB_prompt_list = coarse_prompt.split("BREAK")
 
 
 
 
 
82
 
83
 
84
  HB_m_offset_list, HB_n_offset_list, HB_m_scale_list, HB_n_scale_list, SR_hw_split_ratio = generate_parameters(box_inputs, prompt_img_width, prompt_img_height)
 
179
  )
180
 
181
  coarse_prompt = gr.Textbox(
182
+ label="Regional Fundamental Prompt(BREAK is a delimiter).",
183
  placeholder="Enter your prompt",
184
  lines=2
185
  )
186
 
187
  detailed_prompt = gr.Textbox(
188
+ label="Regional Highly descriptive Prompt(BREAK is a delimiter).",
189
  placeholder="Enter your prompt",
190
  lines=2
191
  )
192
 
193
 
194
  with gr.Column(elem_id="col-left"):
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  default_image_path = "assets/images_template.png"
197
+ box_image = gr.Image(
198
  show_label=False,
199
  interactive=False,
200
  label="Layout",
201
+ value=default_image_path)
202
+ # box_prompt_image = BoxPromptableImage(
203
+ # show_label=False,
204
+ # interactive=False,
205
+ # label="Layout",
206
+ # value={"image": default_image_path})
207
  # box_prompt_image = gr.Image(label="Layout", show_label=True)
208
 
209
  gr.HTML("""
 
280
 
281
  with gr.Row():
282
  button = gr.Button("Run", elem_id="button")
283
+
284
+ box_point = gr.Textbox(visible=False)
285
  gr.on(
286
  triggers=[
287
  button.click,
288
  ],
289
  fn=rag_gen,
290
+ # fn=lambda *args: rag_gen(*args,[]),
291
  inputs=[
292
+ box_point,
293
+ box_image,
294
  prompt,
295
  coarse_prompt,
296
  detailed_prompt,
 
298
  SR_delta,
299
  num_inference_steps,
300
  guidance_scale, seed,
301
+ randomize_seed,
302
  ],
303
  # outputs=[layout, result, seed, run_nums_box],
304
  outputs=[result, seed, run_nums_box],
 
311
  # label="Layout Example (For more complex layouts, please run our code directly.)",
312
  examples=[
313
  [
314
+ "layout1",
315
  "assets/case1.png",
 
316
  "a man is holding a bag, a man is talking on a cell phone.", # prompt
317
  "A man holding a bag. BREAK a man holding a cell phone to his ear.", # coarse_prompt
318
  "A man holding a bag, gripping it firmly, with a casual yet purposeful stance. BREAK a man, engaged in conversation, holding a cell phone to his ear.", # detailed_prompt
 
324
  False, # randomize_seed
325
  ],
326
  [
327
+ "layout2",
328
  "assets/case2.png",
 
329
  "A woman looking at the moon", # prompt
330
  "a woman BREAK a moon", # coarse_prompt
331
  "A woman, standing gracefully, her gaze fixed on the sky with a sense of wonder. BREAK The moon, luminous and full, casting a soft glow across the tranquil night.", # detailed_prompt
 
337
  False, # randomize_seed
338
  ],
339
  [
340
+ "layout3",
341
+ "assets/case3.png",
342
  "a turtle on the bottom of a phone", # prompt
343
  "Phone BREAK Turtle", # coarse_prompt
344
  "The phone, placed above the turtle, potentially with its screen or back visible, its sleek design prominent. BREAK The turtle, below the phone, with its shell textured and detailed, eyes slightly protruding as it looks upward.", # detailed_prompt
 
350
  False, # randomize_seed
351
  ],
352
  [
353
+ "layout4",
354
  "assets/case4.png",
 
355
  "From left to right, a blonde ponytail Europe girl in white shirt, a brown curly hair African girl in blue shirt printed with a bird, an Asian young man with black short hair in suit are walking in the campus happily.", # prompt
356
  "A blonde ponytail European girl in a white shirt BREAK A brown curly hair African girl in a blue shirt printed with a bird BREAK An Asian young man with black short hair in a suit", # coarse_prompt
357
  "A blonde ponytail European girl in a crisp white shirt, walking with a light smile. Her ponytail swings slightly as she enjoys the lively atmosphere of the campus. BREAK A brown curly hair African girl, her vibrant blue shirt adorned with a bird print. Her joyful expression matches her energetic stride as her curls bounce lightly in the breeze. BREAK An Asian young man in a sharp suit, his black short hair neatly styled, walking confidently alongside the two girls. His suit contrasts with the casual campus environment, adding an air of professionalism to the scene.", # detailed_prompt
 
362
  1234, # seed
363
  False, # randomize_seed
364
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  ],
366
  inputs=[
367
+ box_point,
368
+ box_image,
369
  prompt,
370
  coarse_prompt,
371
  detailed_prompt,
 
377
  randomize_seed
378
  ],
379
  outputs=None,
380
+ fn=rag_gen,
381
  cache_examples=False,
382
  )
383
 
assets/run_num.txt CHANGED
@@ -1 +1 @@
1
- 267
 
1
+ 302
assets/title.md CHANGED
@@ -11,7 +11,7 @@
11
  </div>
12
  <br>
13
  <div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 18px;">
14
- <strong style="color: blue; font-weight: bold;">Note: </strong>A simplified demo of our RAG-Diffusion (For more complex layouts, please run our code directly.)
15
  <!-- currently featuring text-to-image functionality. -->
16
  <!-- Stay tuned for the upcoming repainting feature. -->
17
  </div>
 
11
  </div>
12
  <br>
13
  <div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 18px;">
14
+ <strong style="color: blue; font-weight: bold;">Note: </strong>A simplified demo of our RAG-Diffusion (For more complex layouts, please run our code directly).
15
  <!-- currently featuring text-to-image functionality. -->
16
  <!-- Stay tuned for the upcoming repainting feature. -->
17
  </div>