Spaces:
Runtime error
Runtime error
CPU/GPU support, more options
Browse files
app.py
CHANGED
|
@@ -1,26 +1,29 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
from diffusers import LMSDiscreteScheduler
|
| 4 |
from mixdiff import StableDiffusionCanvasPipeline, Text2ImageRegion
|
| 5 |
|
| 6 |
# Creater scheduler and model (similar to StableDiffusionPipeline)
|
| 7 |
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
|
| 8 |
-
pipeline = StableDiffusionCanvasPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=scheduler).to("cuda
|
| 9 |
|
| 10 |
-
def generate(prompt1, prompt2, prompt3, seed):
|
| 11 |
"""Mixture of Diffusers generation"""
|
|
|
|
|
|
|
| 12 |
return pipeline(
|
| 13 |
-
canvas_height=
|
| 14 |
-
canvas_width=
|
| 15 |
regions=[
|
| 16 |
-
Text2ImageRegion(0,
|
| 17 |
prompt=prompt1),
|
| 18 |
-
Text2ImageRegion(0,
|
| 19 |
prompt=prompt2),
|
| 20 |
-
Text2ImageRegion(0,
|
| 21 |
prompt=prompt3),
|
| 22 |
],
|
| 23 |
-
num_inference_steps=
|
| 24 |
seed=seed,
|
| 25 |
)["sample"][0]
|
| 26 |
|
|
@@ -31,6 +34,9 @@ demo = gr.Interface(
|
|
| 31 |
gr.Textbox(lines=2, label="Left region prompt"),
|
| 32 |
gr.Textbox(lines=2, label="Center region prompt"),
|
| 33 |
gr.Textbox(lines=2, label="Right region prompt"),
|
|
|
|
|
|
|
|
|
|
| 34 |
gr.Number(value=12345, precision=0),
|
| 35 |
],
|
| 36 |
outputs="image",
|
|
@@ -39,8 +45,13 @@ demo = gr.Interface(
|
|
| 39 |
"A charming house in the countryside, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
|
| 40 |
"A dirt road in the countryside crossing pastures, by jakub rozalski, sunset lighting, elegant, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
|
| 41 |
"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",
|
|
|
|
|
|
|
|
|
|
| 42 |
7178915308
|
| 43 |
],
|
| 44 |
],
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
demo.launch(server_name="0.0.0.0")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
|
| 4 |
from diffusers import LMSDiscreteScheduler
|
| 5 |
from mixdiff import StableDiffusionCanvasPipeline, Text2ImageRegion
|
| 6 |
|
| 7 |
# Creater scheduler and model (similar to StableDiffusionPipeline)
|
| 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
|
| 15 |
return pipeline(
|
| 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 |
|
|
|
|
| 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",
|
|
|
|
| 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")
|