Spaces:
Sleeping
Sleeping
Commit
·
f7ea271
1
Parent(s):
966167e
update
Browse files
app.py
CHANGED
@@ -285,6 +285,7 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
285 |
except:
|
286 |
prompt = caption_ids
|
287 |
|
|
|
288 |
composed_prompt = tokenizer.decode(prompt)
|
289 |
|
290 |
else:
|
@@ -310,13 +311,16 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
310 |
text_str = ' '.join([f'[{c}]' for c in list(text)])
|
311 |
user_prompt += f'<|startoftext|> l{x0} t{y0} r{x1} b{y1} {text_str} <|endoftext|>'
|
312 |
|
313 |
-
composed_prompt = user_prompt
|
314 |
prompt = tokenizer.encode(user_prompt)
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
if radio == 'TextDiffuser-2':
|
317 |
-
|
318 |
-
while len(prompt) < 77:
|
319 |
-
prompt.append(tokenizer.pad_token_id)
|
320 |
prompts_cond = prompt
|
321 |
prompts_nocond = [tokenizer.pad_token_id]*77
|
322 |
|
@@ -371,8 +375,9 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
371 |
# negative_prompt=negative_prompt,
|
372 |
num_inference_steps=slider_step,
|
373 |
guidance_scale=1,
|
374 |
-
|
375 |
-
|
|
|
376 |
|
377 |
with gr.Blocks() as demo:
|
378 |
|
@@ -434,7 +439,7 @@ with gr.Blocks() as demo:
|
|
434 |
|
435 |
radio = gr.Radio(["TextDiffuser-2", "TextDiffuser-2-LCM"], label="Choices of models", value="TextDiffuser-2")
|
436 |
slider_step = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Sampling step", info="The sampling step for TextDiffuser-2.")
|
437 |
-
slider_guidance = gr.Slider(minimum=1, maximum=9, value=7.5, step=0.5, label="Scale of classifier-free guidance", info="The scale of
|
438 |
slider_batch = gr.Slider(minimum=1, maximum=4, value=4, step=1, label="Batch size", info="The number of images to be sampled.")
|
439 |
slider_temperature = gr.Slider(minimum=0.1, maximum=2, value=0.7, step=0.1, label="Temperature", info="Control the diversity of layout planner. Higher value indicates more diversity.")
|
440 |
slider_natural = gr.Checkbox(label="Natural image generation", value=False, info="The text position and content info will not be incorporated.")
|
|
|
285 |
except:
|
286 |
prompt = caption_ids
|
287 |
|
288 |
+
user_prompt = tokenizer.decode(prompt)
|
289 |
composed_prompt = tokenizer.decode(prompt)
|
290 |
|
291 |
else:
|
|
|
311 |
text_str = ' '.join([f'[{c}]' for c in list(text)])
|
312 |
user_prompt += f'<|startoftext|> l{x0} t{y0} r{x1} b{y1} {text_str} <|endoftext|>'
|
313 |
|
314 |
+
# composed_prompt = user_prompt
|
315 |
prompt = tokenizer.encode(user_prompt)
|
316 |
+
composed_prompt = tokenizer.decode(prompt)
|
317 |
+
|
318 |
+
prompt = prompt[:77]
|
319 |
+
while len(prompt) < 77:
|
320 |
+
prompt.append(tokenizer.pad_token_id)
|
321 |
|
322 |
if radio == 'TextDiffuser-2':
|
323 |
+
|
|
|
|
|
324 |
prompts_cond = prompt
|
325 |
prompts_nocond = [tokenizer.pad_token_id]*77
|
326 |
|
|
|
375 |
# negative_prompt=negative_prompt,
|
376 |
num_inference_steps=slider_step,
|
377 |
guidance_scale=1,
|
378 |
+
num_images_per_prompt=slider_batch,
|
379 |
+
).images
|
380 |
+
return tuple(image), composed_prompt
|
381 |
|
382 |
with gr.Blocks() as demo:
|
383 |
|
|
|
439 |
|
440 |
radio = gr.Radio(["TextDiffuser-2", "TextDiffuser-2-LCM"], label="Choices of models", value="TextDiffuser-2")
|
441 |
slider_step = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Sampling step", info="The sampling step for TextDiffuser-2.")
|
442 |
+
slider_guidance = gr.Slider(minimum=1, maximum=9, value=7.5, step=0.5, label="Scale of classifier-free guidance", info="The scale of cfg and is set to 7.5 in default. When using LCM, cfg is set to 1.")
|
443 |
slider_batch = gr.Slider(minimum=1, maximum=4, value=4, step=1, label="Batch size", info="The number of images to be sampled.")
|
444 |
slider_temperature = gr.Slider(minimum=0.1, maximum=2, value=0.7, step=0.1, label="Temperature", info="Control the diversity of layout planner. Higher value indicates more diversity.")
|
445 |
slider_natural = gr.Checkbox(label="Natural image generation", value=False, info="The text position and content info will not be incorporated.")
|