-
Notifications
You must be signed in to change notification settings - Fork 229
/
gradio_demo.py
46 lines (40 loc) · 2.4 KB
/
gradio_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from pipeline_demofusion_sdxl import DemoFusionSDXLPipeline
from gradio_imageslider import ImageSlider
import torch
def generate_images(prompt, negative_prompt, height, width, num_inference_steps, guidance_scale, cosine_scale_1, cosine_scale_2, cosine_scale_3, sigma, view_batch_size, stride, seed):
model_ckpt = "stabilityai/stable-diffusion-xl-base-1.0"
pipe = DemoFusionSDXLPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
generator = torch.Generator(device='cuda')
generator = generator.manual_seed(int(seed))
images = pipe(prompt, negative_prompt=negative_prompt, generator=generator,
height=int(height), width=int(width), view_batch_size=int(view_batch_size), stride=int(stride),
num_inference_steps=int(num_inference_steps), guidance_scale=guidance_scale,
cosine_scale_1=cosine_scale_1, cosine_scale_2=cosine_scale_2, cosine_scale_3=cosine_scale_3, sigma=sigma,
multi_decoder=True, show_image=False
)
return (images[0], images[-1])
iface = gr.Interface(
fn=generate_images,
inputs=[
gr.Textbox(label="Prompt"),
gr.Textbox(label="Negative Prompt", value="blurry, ugly, duplicate, poorly drawn, deformed, mosaic"),
gr.Slider(minimum=1024, maximum=4096, step=1024, value=2048, label="Height"),
gr.Slider(minimum=1024, maximum=4096, step=1024, value=2048, label="Width"),
gr.Slider(minimum=10, maximum=100, step=1, value=50, label="Num Inference Steps"),
gr.Slider(minimum=1, maximum=20, step=0.1, value=7.5, label="Guidance Scale"),
gr.Slider(minimum=0, maximum=5, step=0.1, value=3, label="Cosine Scale 1"),
gr.Slider(minimum=0, maximum=5, step=0.1, value=1, label="Cosine Scale 2"),
gr.Slider(minimum=0, maximum=5, step=0.1, value=1, label="Cosine Scale 3"),
gr.Slider(minimum=0.1, maximum=1, step=0.1, value=0.8, label="Sigma"),
gr.Slider(minimum=4, maximum=32, step=4, value=16, label="View Batch Size"),
gr.Slider(minimum=8, maximum=96, step=8, value=64, label="Stride"),
gr.Number(label="Seed", value=2013)
],
# outputs=gr.Gallery(label="Generated Images"),
outputs=ImageSlider(label="Comparison of SDXL and DemoFusion"),
title="DemoFusion Gradio Demo",
description="Generate images with the DemoFusion SDXL Pipeline."
)
iface.launch()