Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,31 +16,25 @@ sd_2_1_4x = StableDiffusionUpscalePipeline.from_pretrained(model_4x, torch_dtype
|
|
16 |
# Define the function that will be called when the interface is used
|
17 |
|
18 |
def upscale_image(model, input_image):
|
19 |
-
# Convert the image
|
20 |
generator = torch.manual_seed(999999)
|
21 |
input_image = Image.open(input_image).convert("RGB")
|
22 |
-
|
23 |
-
|
24 |
# Upscale the image using the selected model
|
25 |
if model == "SD 2.0 2x Latent Upscaler":
|
26 |
upscaled_image = sd_2_0_2x(prompt="", image=input_image, num_inference_steps=5).images[0]
|
27 |
else:
|
28 |
low_res_img = input_image.resize((128, 128))
|
29 |
upscaled_image = sd_2_1_4x(prompt="", image=low_res_img, num_inference_steps=5).images[0]
|
30 |
-
|
31 |
-
# Convert the upscaled tensor back to a PIL image
|
32 |
-
|
33 |
-
|
34 |
# Return the upscaled image
|
35 |
return upscaled_image
|
36 |
|
37 |
# Define the Gradio interface
|
38 |
iface = gr.Interface(
|
39 |
fn=upscale_image,
|
40 |
-
inputs=[gr.Radio(["SD 2.0 2x Latent Upscaler", "SD 2.1 4x Upscaler"]), gr.Image(type="filepath")],
|
41 |
outputs=gr.Image(type="filepath"),
|
42 |
-
title="Image Upscaler",
|
43 |
-
description="Upscale an image using either the SD 2.0 2x Latent Upscaler or the SD 2.1 4x Upscaler."
|
44 |
)
|
45 |
|
46 |
# Launch the interface
|
|
|
16 |
# Define the function that will be called when the interface is used
|
17 |
|
18 |
def upscale_image(model, input_image):
|
19 |
+
# Convert the image
|
20 |
generator = torch.manual_seed(999999)
|
21 |
input_image = Image.open(input_image).convert("RGB")
|
|
|
|
|
22 |
# Upscale the image using the selected model
|
23 |
if model == "SD 2.0 2x Latent Upscaler":
|
24 |
upscaled_image = sd_2_0_2x(prompt="", image=input_image, num_inference_steps=5).images[0]
|
25 |
else:
|
26 |
low_res_img = input_image.resize((128, 128))
|
27 |
upscaled_image = sd_2_1_4x(prompt="", image=low_res_img, num_inference_steps=5).images[0]
|
|
|
|
|
|
|
|
|
28 |
# Return the upscaled image
|
29 |
return upscaled_image
|
30 |
|
31 |
# Define the Gradio interface
|
32 |
iface = gr.Interface(
|
33 |
fn=upscale_image,
|
34 |
+
inputs=[gr.Radio(["SD 2.0 2x Latent Upscaler", "SD 2.1 4x Upscaler"], label="Models:"), gr.Image(type="filepath")],
|
35 |
outputs=gr.Image(type="filepath"),
|
36 |
+
title="SD Image Upscaler",
|
37 |
+
description="Upscale an image using either the SD 2.0 2x Latent Upscaler or the SD 2.1 4x Upscaler. Use the 4x Upscaler for images lower than 512x512. Use the 2x Upscaler for images 512x512 to 768x768"
|
38 |
)
|
39 |
|
40 |
# Launch the interface
|