Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,18 @@ import spaces
|
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
model_repo_id = "stabilityai/stable-diffusion-3.5-large"
|
11 |
|
@@ -17,6 +29,26 @@ else:
|
|
17 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
pipe = pipe.to(device)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def adjust_to_nearest_multiple(value, divisor=8):
|
21 |
"""
|
22 |
Adjusts the input value to the nearest multiple of the divisor.
|
@@ -68,6 +100,7 @@ def infer(
|
|
68 |
num_inference_steps=40,
|
69 |
progress=gr.Progress(track_tqdm=True),
|
70 |
):
|
|
|
71 |
if randomize_seed:
|
72 |
seed = random.randint(0, MAX_SEED)
|
73 |
|
@@ -77,15 +110,24 @@ def infer(
|
|
77 |
|
78 |
generator = torch.Generator().manual_seed(seed)
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
return image, seed
|
91 |
|
|
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
9 |
+
|
10 |
+
import numpy as np
|
11 |
+
import random
|
12 |
+
import spaces
|
13 |
+
import torch
|
14 |
+
import time
|
15 |
+
from diffusers import DiffusionPipeline, AutoencoderTiny
|
16 |
+
from diffusers.models.attention_processor import AttnProcessor2_0
|
17 |
+
from custom_pipeline import FluxWithCFGPipeline
|
18 |
+
|
19 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
20 |
+
|
21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
model_repo_id = "stabilityai/stable-diffusion-3.5-large"
|
23 |
|
|
|
29 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
30 |
pipe = pipe.to(device)
|
31 |
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
dtype = torch.float16
|
37 |
+
pipe2 = FluxWithCFGPipeline.from_pretrained(
|
38 |
+
"black-forest-labs/FLUX.1-schnell", torch_dtype=dtype
|
39 |
+
)
|
40 |
+
pipe2.vae = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype)
|
41 |
+
pipe2.to("cuda")
|
42 |
+
pipe2.load_lora_weights('hugovntr/flux-schnell-realism', weight_name='schnell-realism_v2.3.safetensors', adapter_name="better")
|
43 |
+
pipe2.set_adapters(["better"], adapter_weights=[1.0])
|
44 |
+
pipe2.fuse_lora(adapter_name=["better"], lora_scale=1.0)
|
45 |
+
pipe2.unload_lora_weights()
|
46 |
+
|
47 |
+
torch.cuda.empty_cache()
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
def adjust_to_nearest_multiple(value, divisor=8):
|
53 |
"""
|
54 |
Adjusts the input value to the nearest multiple of the divisor.
|
|
|
100 |
num_inference_steps=40,
|
101 |
progress=gr.Progress(track_tqdm=True),
|
102 |
):
|
103 |
+
|
104 |
if randomize_seed:
|
105 |
seed = random.randint(0, MAX_SEED)
|
106 |
|
|
|
110 |
|
111 |
generator = torch.Generator().manual_seed(seed)
|
112 |
|
113 |
+
if num_inference_steps<=10:
|
114 |
+
image = pipe(
|
115 |
+
prompt=prompt,
|
116 |
+
negative_prompt=negative_prompt,
|
117 |
+
guidance_scale=guidance_scale,
|
118 |
+
num_inference_steps=num_inference_steps,
|
119 |
+
width=width,
|
120 |
+
height=height,
|
121 |
+
generator=generator,
|
122 |
+
).images[0]
|
123 |
+
else:
|
124 |
+
img = pipe2.generate_images(
|
125 |
+
prompt=prompt,
|
126 |
+
width=width,
|
127 |
+
height=height,
|
128 |
+
num_inference_steps=num_inference_steps,
|
129 |
+
generator=generator
|
130 |
+
)
|
131 |
|
132 |
return image, seed
|
133 |
|