kadirnar commited on
Commit
1359190
1 Parent(s): c5b2c5c
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -7,13 +7,27 @@ os.environ["CUDA_VISIBLE_DEVICES"]="0"
7
  import torch
8
  import gradio as gr
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def stable_diffusion_zoom_out(
12
  repo_id="stabilityai/stable-diffusion-2-inpainting",
13
- original_prompt="a dog",
14
- negative_prompt="a cat",
15
  steps=32,
16
  num_frames=10,
 
 
17
  ):
18
  pipe = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.float16, revision="fp16")
19
  pipe.set_use_memory_efficient_attention_xformers(True)
@@ -21,7 +35,7 @@ def stable_diffusion_zoom_out(
21
  pipe = pipe.to("cuda")
22
  pipe.safety_checker = dummy
23
 
24
- current_image = Image.new(mode="RGBA", size=(512, 512))
25
  mask_image = np.array(current_image)[:,:,3] # assume image has alpha mask (use .mode to check for "RGBA")
26
  mask_image = Image.fromarray(255-mask_image).convert("RGB")
27
  current_image = current_image.convert("RGB")
@@ -38,11 +52,11 @@ def stable_diffusion_zoom_out(
38
 
39
  for i in range(num_frames):
40
  next_image = np.array(current_image.convert("RGBA"))*0
41
- prev_image = current_image.resize((512-2*steps,512-2*steps))
42
  prev_image = prev_image.convert("RGBA")
43
  prev_image = np.array(prev_image)
44
  next_image[:, :, 3] = 1
45
- next_image[steps:512-steps,steps:512-steps,:] = prev_image
46
  prev_image = Image.fromarray(next_image)
47
  current_image = prev_image
48
  mask_image = np.array(current_image)[:,:,3] # assume image has alpha mask (use .mode to check for "RGBA")
@@ -58,12 +72,15 @@ def stable_diffusion_zoom_out(
58
  return save_path
59
 
60
  inputs = [
61
- gr.Dropdown(["stabilityai/stable-diffusion-2-inpainting"], label="Model"),
62
- gr.inputs.Textbox(lines=1, default="a dog", label="Prompt"),
63
- gr.inputs.Textbox(lines=1, default="a cat", label="Negative Prompt"),
64
  gr.inputs.Slider(minimum=1, maximum=64, default=32, label="Steps"),
65
- gr.inputs.Slider(minimum=1, maximum=100, default=10, label="Frames"),
 
 
66
  ]
 
67
  output = gr.outputs.Video()
68
  title = "Stable Diffusion Infinite Zoom Out"
69
 
 
7
  import torch
8
  import gradio as gr
9
 
10
+ best_model_list = [
11
+ "runwayml/stable-diffusion-v1-5",
12
+ "CompVis/stable-diffusion-v1-4",
13
+ "prompthero/openjourney",
14
+ "dreamlike-art/dreamlike-photoreal-2.0",
15
+ "dreamlike-art/dreamlike-diffusion-1.0",
16
+ "stabilityai/stable-diffusion-2-inpainting"
17
+ ]
18
+
19
+ orig_prompt = "Create a relaxing atmosphere with the use of plants and other natural elements. Such as a hanging terrarium or a wall-mounted planter. Include plenty of storage options to keep the space organized and clutter-free. Consider adding a vanity with double sinks and plenty of drawers and cabinets. As well as a wall mounted medicine and towel storage."
20
+ orig_negative_prompt = "lurry, bad art, blurred, text, watermark"
21
+
22
 
23
  def stable_diffusion_zoom_out(
24
  repo_id="stabilityai/stable-diffusion-2-inpainting",
25
+ original_prompt,
26
+ negative_prompt,
27
  steps=32,
28
  num_frames=10,
29
+ image_size=512,
30
+ fps=16
31
  ):
32
  pipe = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.float16, revision="fp16")
33
  pipe.set_use_memory_efficient_attention_xformers(True)
 
35
  pipe = pipe.to("cuda")
36
  pipe.safety_checker = dummy
37
 
38
+ current_image = Image.new(mode="RGBA", size=(image_size,image_size))
39
  mask_image = np.array(current_image)[:,:,3] # assume image has alpha mask (use .mode to check for "RGBA")
40
  mask_image = Image.fromarray(255-mask_image).convert("RGB")
41
  current_image = current_image.convert("RGB")
 
52
 
53
  for i in range(num_frames):
54
  next_image = np.array(current_image.convert("RGBA"))*0
55
+ prev_image = current_image.resize((image_size-2*steps,image_size-2*steps))
56
  prev_image = prev_image.convert("RGBA")
57
  prev_image = np.array(prev_image)
58
  next_image[:, :, 3] = 1
59
+ next_image[steps:image_size-steps,steps:image_size-steps,:] = prev_image
60
  prev_image = Image.fromarray(next_image)
61
  current_image = prev_image
62
  mask_image = np.array(current_image)[:,:,3] # assume image has alpha mask (use .mode to check for "RGBA")
 
72
  return save_path
73
 
74
  inputs = [
75
+ gr.Dropdown(choices=best_model_list,default="stabilityai/stable-diffusion-2-inpainting",label="Model"),
76
+ gr.inputs.Textbox(lines=1, default=orig_prompt, label="Prompt"),
77
+ gr.inputs.Textbox(lines=1, default=orig_negative_prompt, label="Negative Prompt"),
78
  gr.inputs.Slider(minimum=1, maximum=64, default=32, label="Steps"),
79
+ gr.inputs.Slider(minimum=1, maximum=500, default=10, step=10, label="Frames"),
80
+ gr.inputs.Slider(minimum=128, maximum=1024, default=512, step=256, label="Image Size"),
81
+ gr.inputs.Slider(minimum=1, maximum=100, default=16, step=1, label="FPS")
82
  ]
83
+
84
  output = gr.outputs.Video()
85
  title = "Stable Diffusion Infinite Zoom Out"
86