Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pipeline_demofusion_sdxl import DemoFusionSDXLPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
import subprocess
|
| 6 |
+
from subprocess import getoutput
|
| 7 |
+
gpu_info = getoutput('nvidia-smi')
|
| 8 |
+
|
| 9 |
+
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):
|
| 10 |
+
if not("A100" in gpu_info):
|
| 11 |
+
raise gr.Error("This demo will only run on A100 GPU upgrade.")
|
| 12 |
+
|
| 13 |
+
model_ckpt = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 14 |
+
pipe = DemoFusionSDXLPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
|
| 15 |
+
pipe = pipe.to("cuda")
|
| 16 |
+
|
| 17 |
+
generator = torch.Generator(device="cuda")
|
| 18 |
+
generator = generator.manual_seed(int(seed))
|
| 19 |
+
|
| 20 |
+
images = pipe(prompt, negative_prompt=negative_prompt, generator=generator,
|
| 21 |
+
height=int(height), width=int(width), view_batch_size=int(view_batch_size), stride=int(stride),
|
| 22 |
+
num_inference_steps=int(num_inference_steps), guidance_scale=guidance_scale,
|
| 23 |
+
cosine_scale_1=cosine_scale_1, cosine_scale_2=cosine_scale_2, cosine_scale_3=cosine_scale_3, sigma=sigma,
|
| 24 |
+
multi_decoder=True, show_image=False
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
return [image for _, image in enumerate(images)]
|
| 28 |
+
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=generate_images,
|
| 31 |
+
inputs=[
|
| 32 |
+
gr.Textbox(label="Prompt"),
|
| 33 |
+
gr.Textbox(label="Negative Prompt", value="blurry, ugly, duplicate, poorly drawn, deformed, mosaic"),
|
| 34 |
+
gr.Slider(minimum=1024, maximum=4096, step=1024, value=2048, label="Height"),
|
| 35 |
+
gr.Slider(minimum=1024, maximum=4096, step=1024, value=2048, label="Width"),
|
| 36 |
+
gr.Slider(minimum=10, maximum=100, step=1, value=50, label="Num Inference Steps"),
|
| 37 |
+
gr.Slider(minimum=1, maximum=20, step=0.1, value=7.5, label="Guidance Scale"),
|
| 38 |
+
gr.Slider(minimum=0, maximum=5, step=0.1, value=3, label="Cosine Scale 1"),
|
| 39 |
+
gr.Slider(minimum=0, maximum=5, step=0.1, value=1, label="Cosine Scale 2"),
|
| 40 |
+
gr.Slider(minimum=0, maximum=5, step=0.1, value=1, label="Cosine Scale 3"),
|
| 41 |
+
gr.Slider(minimum=0.1, maximum=1, step=0.1, value=0.8, label="Sigma"),
|
| 42 |
+
gr.Slider(minimum=4, maximum=32, step=4, value=16, label="View Batch Size"),
|
| 43 |
+
gr.Slider(minimum=8, maximum=96, step=8, value=64, label="Stride"),
|
| 44 |
+
gr.Number(label="Seed", value=2013)
|
| 45 |
+
],
|
| 46 |
+
outputs=gr.Gallery(label="Generated Images"),
|
| 47 |
+
title="DemoFusion Gradio Demo",
|
| 48 |
+
description="Generate images with the DemoFusion SDXL Pipeline. Runs on A100 GPU."
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
iface.launch()
|