vis
Browse files
app.py
CHANGED
@@ -233,9 +233,22 @@ def infer(
|
|
233 |
|
234 |
samples = unpreprocess(image_unprocessed).contiguous()
|
235 |
|
|
|
236 |
to_pil = ToPILImage()
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
return pil_image, seed
|
241 |
|
@@ -256,11 +269,10 @@ css = """
|
|
256 |
max-width: 640px;
|
257 |
}
|
258 |
"""
|
259 |
-
|
260 |
with gr.Blocks(css=css) as demo:
|
261 |
with gr.Column(elem_id="col-container"):
|
262 |
-
gr.Markdown("
|
263 |
-
gr.Markdown("
|
264 |
|
265 |
with gr.Row():
|
266 |
prompt1 = gr.Text(
|
@@ -283,7 +295,10 @@ with gr.Blocks(css=css) as demo:
|
|
283 |
with gr.Row():
|
284 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
285 |
|
286 |
-
|
|
|
|
|
|
|
287 |
|
288 |
with gr.Accordion("Advanced Settings", open=False):
|
289 |
seed = gr.Slider(
|
@@ -306,7 +321,7 @@ with gr.Blocks(css=css) as demo:
|
|
306 |
)
|
307 |
with gr.Row():
|
308 |
num_inference_steps = gr.Slider(
|
309 |
-
label="Number of inference steps",
|
310 |
minimum=1,
|
311 |
maximum=50,
|
312 |
step=1,
|
@@ -334,8 +349,88 @@ with gr.Blocks(css=css) as demo:
|
|
334 |
num_inference_steps,
|
335 |
num_of_interpolation,
|
336 |
],
|
337 |
-
outputs=[
|
338 |
)
|
339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
if __name__ == "__main__":
|
341 |
demo.launch()
|
|
|
233 |
|
234 |
samples = unpreprocess(image_unprocessed).contiguous()
|
235 |
|
236 |
+
|
237 |
to_pil = ToPILImage()
|
238 |
+
pil_images = [to_pil(img) for img in samples]
|
239 |
+
|
240 |
+
# Get the first and last images
|
241 |
+
first_image = pil_images[0]
|
242 |
+
last_image = pil_images[-1]
|
243 |
+
|
244 |
+
# Create an animated GIF from all the PIL images
|
245 |
+
gif_buffer = io.BytesIO()
|
246 |
+
# duration: adjust duration (ms) between frames as needed
|
247 |
+
pil_images[0].save(gif_buffer, format="GIF", save_all=True, append_images=pil_images[1:], duration=10, loop=0)
|
248 |
+
gif_buffer.seek(0)
|
249 |
+
gif_bytes = gif_buffer.read()
|
250 |
+
|
251 |
+
return first_image, last_image, gif_bytes, seed
|
252 |
|
253 |
return pil_image, seed
|
254 |
|
|
|
269 |
max-width: 640px;
|
270 |
}
|
271 |
"""
|
|
|
272 |
with gr.Blocks(css=css) as demo:
|
273 |
with gr.Column(elem_id="col-container"):
|
274 |
+
gr.Markdown("# CrossFlow")
|
275 |
+
gr.Markdown("CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
|
276 |
|
277 |
with gr.Row():
|
278 |
prompt1 = gr.Text(
|
|
|
295 |
with gr.Row():
|
296 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
297 |
|
298 |
+
# Create separate outputs for the first image, last image, and the animated GIF
|
299 |
+
first_image_output = gr.Image(label="Image if the first prompt", show_label=True)
|
300 |
+
last_image_output = gr.Image(label="Image if the second prompt", show_label=True)
|
301 |
+
gif_output = gr.Image(label="Linear interpolation", show_label=True)
|
302 |
|
303 |
with gr.Accordion("Advanced Settings", open=False):
|
304 |
seed = gr.Slider(
|
|
|
321 |
)
|
322 |
with gr.Row():
|
323 |
num_inference_steps = gr.Slider(
|
324 |
+
label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
|
325 |
minimum=1,
|
326 |
maximum=50,
|
327 |
step=1,
|
|
|
349 |
num_inference_steps,
|
350 |
num_of_interpolation,
|
351 |
],
|
352 |
+
outputs=[first_image_output, last_image_output, gif_output, seed],
|
353 |
)
|
354 |
|
355 |
+
# with gr.Blocks(css=css) as demo:
|
356 |
+
# with gr.Column(elem_id="col-container"):
|
357 |
+
# gr.Markdown(" # CrossFlow")
|
358 |
+
# gr.Markdown(" CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
|
359 |
+
|
360 |
+
# with gr.Row():
|
361 |
+
# prompt1 = gr.Text(
|
362 |
+
# label="Prompt_1",
|
363 |
+
# show_label=False,
|
364 |
+
# max_lines=1,
|
365 |
+
# placeholder="Enter your prompt for the first image",
|
366 |
+
# container=False,
|
367 |
+
# )
|
368 |
+
|
369 |
+
# with gr.Row():
|
370 |
+
# prompt2 = gr.Text(
|
371 |
+
# label="Prompt_2",
|
372 |
+
# show_label=False,
|
373 |
+
# max_lines=1,
|
374 |
+
# placeholder="Enter your prompt for the second image",
|
375 |
+
# container=False,
|
376 |
+
# )
|
377 |
+
|
378 |
+
# with gr.Row():
|
379 |
+
# run_button = gr.Button("Run", scale=0, variant="primary")
|
380 |
+
|
381 |
+
# result = gr.Image(label="Result", show_label=False)
|
382 |
+
|
383 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
384 |
+
# seed = gr.Slider(
|
385 |
+
# label="Seed",
|
386 |
+
# minimum=0,
|
387 |
+
# maximum=MAX_SEED,
|
388 |
+
# step=1,
|
389 |
+
# value=0,
|
390 |
+
# )
|
391 |
+
|
392 |
+
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
393 |
+
|
394 |
+
# with gr.Row():
|
395 |
+
# guidance_scale = gr.Slider(
|
396 |
+
# label="Guidance scale",
|
397 |
+
# minimum=0.0,
|
398 |
+
# maximum=10.0,
|
399 |
+
# step=0.1,
|
400 |
+
# value=7.0, # Replace with defaults that work for your model
|
401 |
+
# )
|
402 |
+
# with gr.Row():
|
403 |
+
# num_inference_steps = gr.Slider(
|
404 |
+
# label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
|
405 |
+
# minimum=1,
|
406 |
+
# maximum=50,
|
407 |
+
# step=1,
|
408 |
+
# value=50, # Replace with defaults that work for your model
|
409 |
+
# )
|
410 |
+
# with gr.Row():
|
411 |
+
# num_of_interpolation = gr.Slider(
|
412 |
+
# label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
|
413 |
+
# minimum=5,
|
414 |
+
# maximum=50,
|
415 |
+
# step=1,
|
416 |
+
# value=10, # Replace with defaults that work for your model
|
417 |
+
# )
|
418 |
+
|
419 |
+
# gr.Examples(examples=examples, inputs=[prompt1, prompt2])
|
420 |
+
# gr.on(
|
421 |
+
# triggers=[run_button.click, prompt1.submit, prompt2.submit],
|
422 |
+
# fn=infer,
|
423 |
+
# inputs=[
|
424 |
+
# prompt1,
|
425 |
+
# prompt2,
|
426 |
+
# seed,
|
427 |
+
# randomize_seed,
|
428 |
+
# guidance_scale,
|
429 |
+
# num_inference_steps,
|
430 |
+
# num_of_interpolation,
|
431 |
+
# ],
|
432 |
+
# outputs=[result, seed],
|
433 |
+
# )
|
434 |
+
|
435 |
if __name__ == "__main__":
|
436 |
demo.launch()
|