Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import spaces
|
| 3 |
from diffusers import StableDiffusionXLPipeline
|
| 4 |
import numpy as np
|
| 5 |
import math
|
| 6 |
-
import torch
|
| 7 |
import random
|
| 8 |
|
| 9 |
from gradio_imageslider import ImageSlider
|
|
@@ -15,7 +15,8 @@ theme = gr.themes.Base(
|
|
| 15 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 16 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 17 |
custom_pipeline="multimodalart/sdxl_perturbed_attention_guidance",
|
| 18 |
-
torch_dtype=torch.float16
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
device="cuda"
|
|
@@ -28,7 +29,7 @@ def run(prompt, negative_prompt=None, guidance_scale=7.0, pag_scale=3.0, pag_lay
|
|
| 28 |
print(f"Initial seed for prompt `{prompt}`", seed)
|
| 29 |
if(randomize_seed):
|
| 30 |
seed = random.randint(0, 9007199254740991)
|
| 31 |
-
|
| 32 |
if not prompt and not negative_prompt:
|
| 33 |
guidance_scale = 0.0
|
| 34 |
pipe.unfuse_lora()
|
|
@@ -38,8 +39,8 @@ def run(prompt, negative_prompt=None, guidance_scale=7.0, pag_scale=3.0, pag_lay
|
|
| 38 |
pipe.fuse_lora(lora_scale=0.9)
|
| 39 |
print(f"Seed before sending to generator for prompt: `{prompt}`", seed)
|
| 40 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 41 |
-
image_pag = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, pag_scale=pag_scale, pag_applied_layers=pag_layers, generator=generator, num_inference_steps=25).images[0]
|
| 42 |
-
|
| 43 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 44 |
image_normal = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, generator=generator, num_inference_steps=25).images[0]
|
| 45 |
print(f"Seed at the end of generation for prompt: `{prompt}`", seed)
|
|
@@ -80,4 +81,4 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
| 80 |
outputs=[output, seed],
|
| 81 |
)
|
| 82 |
if __name__ == "__main__":
|
| 83 |
-
demo.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
from diffusers import StableDiffusionXLPipeline
|
| 4 |
import numpy as np
|
| 5 |
import math
|
| 6 |
+
import torch
|
| 7 |
import random
|
| 8 |
|
| 9 |
from gradio_imageslider import ImageSlider
|
|
|
|
| 15 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 16 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 17 |
custom_pipeline="multimodalart/sdxl_perturbed_attention_guidance",
|
| 18 |
+
torch_dtype=torch.float16,
|
| 19 |
+
trust_remote_code=True
|
| 20 |
)
|
| 21 |
|
| 22 |
device="cuda"
|
|
|
|
| 29 |
print(f"Initial seed for prompt `{prompt}`", seed)
|
| 30 |
if(randomize_seed):
|
| 31 |
seed = random.randint(0, 9007199254740991)
|
| 32 |
+
|
| 33 |
if not prompt and not negative_prompt:
|
| 34 |
guidance_scale = 0.0
|
| 35 |
pipe.unfuse_lora()
|
|
|
|
| 39 |
pipe.fuse_lora(lora_scale=0.9)
|
| 40 |
print(f"Seed before sending to generator for prompt: `{prompt}`", seed)
|
| 41 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 42 |
+
image_pag = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, pag_scale=pag_scale, pag_applied_layers=pag_layers, generator=generator, num_inference_steps=25).images[0]
|
| 43 |
+
|
| 44 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 45 |
image_normal = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, generator=generator, num_inference_steps=25).images[0]
|
| 46 |
print(f"Seed at the end of generation for prompt: `{prompt}`", seed)
|
|
|
|
| 81 |
outputs=[output, seed],
|
| 82 |
)
|
| 83 |
if __name__ == "__main__":
|
| 84 |
+
demo.launch(share=True)
|