Veda_Sahaja
commited on
Commit
·
005cd62
1
Parent(s):
f11f48a
Update space
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
from diffusers import
|
| 5 |
from safetensors.torch import load_file
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
import torch
|
|
@@ -53,25 +53,16 @@ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str
|
|
| 53 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 54 |
return p.replace("{prompt}", positive), n + negative
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!
|
| 59 |
-
|
| 60 |
-
# Load model.
|
| 61 |
-
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
|
| 62 |
-
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
| 63 |
-
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
| 64 |
-
|
| 65 |
-
# Ensure sampler uses "trailing" timesteps.
|
| 66 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
| 67 |
|
| 68 |
|
| 69 |
MAX_SEED = np.iinfo(np.int32).max
|
| 70 |
MAX_IMAGE_SIZE = 1024
|
| 71 |
|
| 72 |
-
def infer(prompt, negative_prompt, width, height, style_name=None):
|
| 73 |
seed = random.randint(0,4294967295)
|
| 74 |
-
guidance_scale =
|
| 75 |
|
| 76 |
generator = torch.Generator().manual_seed(seed)
|
| 77 |
|
|
@@ -176,7 +167,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 176 |
step=32,
|
| 177 |
value=1024,
|
| 178 |
)
|
|
|
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
gr.Examples(
|
| 181 |
examples = examples,
|
| 182 |
inputs = [prompt]
|
|
@@ -194,7 +193,7 @@ Used Stable Diffusion XL (SDXL) Model by <a href="https://huggingface.co/stabili
|
|
| 194 |
|
| 195 |
run_button.click(
|
| 196 |
fn = infer,
|
| 197 |
-
inputs = [prompt, negative_prompt, width, height, style_selection],
|
| 198 |
outputs = [result]
|
| 199 |
)
|
| 200 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
+
from diffusers import DiffusionPipeline
|
| 5 |
from safetensors.torch import load_file
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
import torch
|
|
|
|
| 53 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 54 |
return p.replace("{prompt}", positive), n + negative
|
| 55 |
|
| 56 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 57 |
+
pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
MAX_SEED = np.iinfo(np.int32).max
|
| 61 |
MAX_IMAGE_SIZE = 1024
|
| 62 |
|
| 63 |
+
def infer(prompt, negative_prompt, width, height, guidance_scale, style_name=None):
|
| 64 |
seed = random.randint(0,4294967295)
|
| 65 |
+
# guidance_scale = 7.5
|
| 66 |
|
| 67 |
generator = torch.Generator().manual_seed(seed)
|
| 68 |
|
|
|
|
| 167 |
step=32,
|
| 168 |
value=1024,
|
| 169 |
)
|
| 170 |
+
with gr.Row():
|
| 171 |
|
| 172 |
+
guidance_scale = gr.Slider(
|
| 173 |
+
label="Guidance scale",
|
| 174 |
+
minimum=0.0,
|
| 175 |
+
maximum=50.0,
|
| 176 |
+
step=0.1,
|
| 177 |
+
value=10,
|
| 178 |
+
)
|
| 179 |
gr.Examples(
|
| 180 |
examples = examples,
|
| 181 |
inputs = [prompt]
|
|
|
|
| 193 |
|
| 194 |
run_button.click(
|
| 195 |
fn = infer,
|
| 196 |
+
inputs = [prompt, negative_prompt, width, height, guidance_scale, style_selection],
|
| 197 |
outputs = [result]
|
| 198 |
)
|
| 199 |
|