Manjushri commited on
Commit
4551a9d
·
1 Parent(s): 1afcf34

Update app.py

Browse files

Adding prompts and sliders

Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -16,23 +16,27 @@ sd_2_1_4x = StableDiffusionUpscalePipeline.from_pretrained(model_4x, torch_dtype
16
 
17
  # Define the function that will be called when the interface is used
18
 
19
- def upscale_image(model, input_image):
20
  # Convert the image
21
  generator = torch.manual_seed(999999)
22
  input_image = Image.open(input_image).convert("RGB")
23
  # Upscale the image using the selected model
24
  if model == "SD 2.1 4x Upscaler":
25
  low_res_img = input_image.resize((128, 128))
26
- upscaled_image = sd_2_1_4x(prompt="Sony A7 IV Camera Photo", negative_prompt='Deformity', image=low_res_img, num_inference_steps=5).images[0]
27
  else:
28
- upscaled_image = sd_2_0_2x(prompt="Sony A7 IV Camera Photo", negative_prompt='Deformity', image=input_image, num_inference_steps=5).images[0]
29
  # Return the upscaled image
30
  return upscaled_image
31
 
32
  # Define the Gradio interface
33
  gr.Interface(
34
  fn=upscale_image,
35
- inputs=[gr.Radio(["SD 2.0 2x Latent Upscaler", "SD 2.1 4x Upscaler"], label="Models:"), gr.Image(type="filepath", label = "Raw Image")],
 
 
 
 
36
  outputs=gr.Image(type="filepath", label = "Upscaled Image"),
37
  title="SD Image Upscaler",
38
  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"
 
16
 
17
  # Define the function that will be called when the interface is used
18
 
19
+ def upscale_image(model, input_image, prompt, negative_prompt, guidance):
20
  # Convert the image
21
  generator = torch.manual_seed(999999)
22
  input_image = Image.open(input_image).convert("RGB")
23
  # Upscale the image using the selected model
24
  if model == "SD 2.1 4x Upscaler":
25
  low_res_img = input_image.resize((128, 128))
26
+ upscaled_image = sd_2_1_4x(prompt, negative_prompt, image=low_res_img, num_inference_steps=5, guidance_scale=guidance).images[0]
27
  else:
28
+ upscaled_image = sd_2_0_2x(prompt, negative_prompt, image=input_image, num_inference_steps=5, guidance_scale=guidance).images[0]
29
  # Return the upscaled image
30
  return upscaled_image
31
 
32
  # Define the Gradio interface
33
  gr.Interface(
34
  fn=upscale_image,
35
+ inputs=[gr.Radio(["SD 2.0 2x Latent Upscaler", "SD 2.1 4x Upscaler"], label="Models:"),
36
+ gr.Image(type="filepath", label = "Raw Image"),
37
+ gr.Textbox(label='Guide the AI Upscaling'),
38
+ gr.Textbox(label='What you do not want AI to generate during Upscaling'),
39
+ gr.Slider(0, 0, 3, label='Guidance Scale')],
40
  outputs=gr.Image(type="filepath", label = "Upscaled Image"),
41
  title="SD Image Upscaler",
42
  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"