albarji commited on
Commit
9119c1f
1 Parent(s): 0aae4be

Changed interface to blocks

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +56 -31
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_cached_examples
app.py CHANGED
@@ -8,7 +8,7 @@ from mixdiff import StableDiffusionCanvasPipeline, Text2ImageRegion
8
  scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
9
  pipeline = StableDiffusionCanvasPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=scheduler).to("cuda" if torch.cuda.is_available() else "cpu")
10
 
11
- def generate(prompt1, prompt2, prompt3, overlap, guidance_scale, steps, seed):
12
  """Mixture of Diffusers generation"""
13
  tile_width = 640
14
  tile_height = 640
@@ -16,42 +16,67 @@ def generate(prompt1, prompt2, prompt3, overlap, guidance_scale, steps, seed):
16
  canvas_height=tile_height,
17
  canvas_width=tile_width + (tile_width - overlap) * 2,
18
  regions=[
19
- Text2ImageRegion(0, tile_height, 0, tile_width, guidance_scale=guidance_scale,
20
  prompt=prompt1),
21
- Text2ImageRegion(0, tile_height, tile_width - overlap, tile_width - overlap + tile_width, guidance_scale=guidance_scale,
22
  prompt=prompt2),
23
- Text2ImageRegion(0, tile_height, (tile_width - overlap) * 2, (tile_width - overlap) * 2 + tile_width, guidance_scale=guidance_scale,
24
  prompt=prompt3),
25
  ],
26
  num_inference_steps=steps,
27
  seed=seed,
28
  )["sample"][0]
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- demo = gr.Interface(
32
- fn=generate,
33
- inputs=[
34
- gr.Textbox(lines=2, label="Left region prompt"),
35
- gr.Textbox(lines=2, label="Center region prompt"),
36
- gr.Textbox(lines=2, label="Right region prompt"),
37
- gr.Slider(minimum=128, maximum=320, value=256, step=8, label="Overlap between diffusion regions"),
38
- gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Global guidance scale"),
39
- gr.Slider(minimum=1, maximum=50, value=15, step=1, label="Number of diffusion steps"),
40
- gr.Number(value=12345, precision=0),
41
- ],
42
- outputs="image",
43
- examples=[
44
- [
45
- "A charming house in the countryside, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
46
- "A dirt road in the countryside crossing pastures, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
47
- "An old and rusty giant robot lying on a dirt road, by jakub rozalski, dark sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
48
- 256,
49
- 8,
50
- 50,
51
- 7178915308
52
- ],
53
- ],
54
- title="Mixture of Diffusers",
55
- article="",
56
- )
57
- demo.launch(server_name="0.0.0.0")
 
8
  scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
9
  pipeline = StableDiffusionCanvasPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=scheduler).to("cuda" if torch.cuda.is_available() else "cpu")
10
 
11
+ def generate(prompt1, prompt2, prompt3, gc1, gc2, gc3, overlap, steps, seed):
12
  """Mixture of Diffusers generation"""
13
  tile_width = 640
14
  tile_height = 640
 
16
  canvas_height=tile_height,
17
  canvas_width=tile_width + (tile_width - overlap) * 2,
18
  regions=[
19
+ Text2ImageRegion(0, tile_height, 0, tile_width, guidance_scale=gc1,
20
  prompt=prompt1),
21
+ Text2ImageRegion(0, tile_height, tile_width - overlap, tile_width - overlap + tile_width, guidance_scale=gc2,
22
  prompt=prompt2),
23
+ Text2ImageRegion(0, tile_height, (tile_width - overlap) * 2, (tile_width - overlap) * 2 + tile_width, guidance_scale=gc3,
24
  prompt=prompt3),
25
  ],
26
  num_inference_steps=steps,
27
  seed=seed,
28
  )["sample"][0]
29
 
30
+ with gr.Blocks(title="Mixture of Diffusers") as demo:
31
+ gr.Markdown("# Mixture of Diffusers")
32
+ with gr.Row():
33
+ with gr.Column(scale=1):
34
+ gr.Markdown("### Left region")
35
+ left_prompt = gr.Textbox(lines=2, label="Prompt")
36
+ left_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
37
+ with gr.Column(scale=1):
38
+ gr.Markdown("### Center region")
39
+ center_prompt = gr.Textbox(lines=2, label="Prompt")
40
+ center_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
41
+ with gr.Column(scale=1):
42
+ gr.Markdown("### Right region")
43
+ right_prompt = gr.Textbox(lines=2, label="Prompt")
44
+ right_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
45
+ gr.Markdown("### General parameters")
46
+ with gr.Row():
47
+ with gr.Column(scale=1):
48
+ overlap = gr.Slider(minimum=128, maximum=320, value=256, step=8, label="Overlap between diffusion regions")
49
+ with gr.Column(scale=1):
50
+ steps = gr.Slider(minimum=1, maximum=50, value=15, step=1, label="Number of diffusion steps")
51
+ with gr.Column(scale=1):
52
+ seed = gr.Number(value=12345, precision=0, label="Random seed")
53
+ with gr.Row():
54
+ button = gr.Button(value="Generate")
55
+ with gr.Row():
56
+ output = gr.Image(label="Generated image")
57
+ with gr.Row():
58
+ gr.Examples(
59
+ examples=[
60
+ [
61
+ "A charming house in the countryside, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
62
+ "A dirt road in the countryside crossing pastures, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
63
+ "An old and rusty giant robot lying on a dirt road, by jakub rozalski, dark sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
64
+ 8, 8, 8,
65
+ 256,
66
+ 50,
67
+ 7178915308
68
+ ],
69
+ ],
70
+ inputs=[left_prompt, center_prompt, right_prompt, left_gs, center_gs, right_gs, overlap, steps, seed],
71
+ # outputs=output,
72
+ # fn=generate,
73
+ # cache_examples=True
74
+ )
75
+
76
+ button.click(
77
+ generate,
78
+ inputs=[left_prompt, center_prompt, right_prompt, left_gs, center_gs, right_gs, overlap, steps, seed],
79
+ outputs=output
80
+ )
81
 
82
+ demo.launch(server_name="0.0.0.0")