Update app.py
Browse files
app.py
CHANGED
@@ -503,15 +503,16 @@ model_path = snapshot_download(
|
|
503 |
token=huggingface_token, # type a new token-id.
|
504 |
)
|
505 |
|
506 |
-
|
507 |
# Load pipeline
|
508 |
controlnet = FluxControlNetModel.from_pretrained(
|
509 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
510 |
).to(device)
|
511 |
-
|
512 |
model_path, controlnet=controlnet, torch_dtype=torch.bfloat16
|
513 |
)
|
514 |
-
|
|
|
|
|
515 |
|
516 |
MAX_SEED = 1000000
|
517 |
|
@@ -548,7 +549,8 @@ def process_input(input_image, upscale_factor):
|
|
548 |
return input_image.resize((w, h)), w_original, h_original, was_resized
|
549 |
|
550 |
MAX_PIXEL_BUDGET = 1024 * 1024
|
551 |
-
|
|
|
552 |
@spaces.GPU
|
553 |
def upscale(input_image, progress=gr.Progress(track_tqdm=True)):
|
554 |
if input_image is None:
|
@@ -563,7 +565,7 @@ def upscale(input_image, progress=gr.Progress(track_tqdm=True)):
|
|
563 |
generator = torch.Generator(device=device).manual_seed(random.randint(0, MAX_SEED))
|
564 |
|
565 |
gr.Info("Upscaling image to 4096x4096...")
|
566 |
-
|
567 |
prompt="",
|
568 |
image=control_image,
|
569 |
controlnet_conditioning_scale=0.6,
|
@@ -574,7 +576,8 @@ def upscale(input_image, progress=gr.Progress(track_tqdm=True)):
|
|
574 |
generator=generator,
|
575 |
).images[0]
|
576 |
|
577 |
-
return
|
|
|
578 |
|
579 |
|
580 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
|
@@ -625,11 +628,18 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as a
|
|
625 |
columns=4,
|
626 |
elem_id="gallery"
|
627 |
)
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
|
634 |
with gr.Row():
|
635 |
with gr.Accordion("Advanced Settings", open=False):
|
@@ -689,6 +699,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as a
|
|
689 |
outputs=history_gallery,
|
690 |
)
|
691 |
|
|
|
692 |
upscale_button.click(
|
693 |
upscale,
|
694 |
inputs=[result],
|
|
|
503 |
token=huggingface_token, # type a new token-id.
|
504 |
)
|
505 |
|
|
|
506 |
# Load pipeline
|
507 |
controlnet = FluxControlNetModel.from_pretrained(
|
508 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
509 |
).to(device)
|
510 |
+
pipe_controlnet = FluxControlNetPipeline.from_pretrained(
|
511 |
model_path, controlnet=controlnet, torch_dtype=torch.bfloat16
|
512 |
)
|
513 |
+
pipe_controlnet.to(device)
|
514 |
+
|
515 |
+
|
516 |
|
517 |
MAX_SEED = 1000000
|
518 |
|
|
|
549 |
return input_image.resize((w, h)), w_original, h_original, was_resized
|
550 |
|
551 |
MAX_PIXEL_BUDGET = 1024 * 1024
|
552 |
+
|
553 |
+
|
554 |
@spaces.GPU
|
555 |
def upscale(input_image, progress=gr.Progress(track_tqdm=True)):
|
556 |
if input_image is None:
|
|
|
565 |
generator = torch.Generator(device=device).manual_seed(random.randint(0, MAX_SEED))
|
566 |
|
567 |
gr.Info("Upscaling image to 4096x4096...")
|
568 |
+
upscaled_image = pipe_controlnet(
|
569 |
prompt="",
|
570 |
image=control_image,
|
571 |
controlnet_conditioning_scale=0.6,
|
|
|
576 |
generator=generator,
|
577 |
).images[0]
|
578 |
|
579 |
+
return [input_image, upscaled_image]
|
580 |
+
|
581 |
|
582 |
|
583 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, delete_cache=(60, 3600)) as app:
|
|
|
628 |
columns=4,
|
629 |
elem_id="gallery"
|
630 |
)
|
631 |
+
with gr.Column():
|
632 |
+
progress_bar = gr.Markdown(elem_id="progress", visible=False)
|
633 |
+
result = ImageSlider(
|
634 |
+
label="Generated Image",
|
635 |
+
minimum=0,
|
636 |
+
maximum=100,
|
637 |
+
step=1,
|
638 |
+
value=50,
|
639 |
+
elem_id="result_slider"
|
640 |
+
)
|
641 |
+
with gr.Accordion("History", open=False):
|
642 |
+
history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", interactive=False)
|
643 |
|
644 |
with gr.Row():
|
645 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
699 |
outputs=history_gallery,
|
700 |
)
|
701 |
|
702 |
+
|
703 |
upscale_button.click(
|
704 |
upscale,
|
705 |
inputs=[result],
|