Spaces:
Running
on
Zero
Running
on
Zero
prithivMLmods
commited on
Commit
•
4061b41
1
Parent(s):
919cb42
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import spaces
|
3 |
import numpy as np
|
4 |
import random
|
5 |
-
from diffusers import DiffusionPipeline, AutoencoderTiny
|
6 |
import torch
|
7 |
from PIL import Image
|
8 |
|
@@ -10,15 +10,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
10 |
model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
|
11 |
|
12 |
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
13 |
-
|
14 |
-
|
15 |
-
taesd3 = (
|
16 |
-
AutoencoderTiny.from_pretrained("madebyollin/taesd3", torch_dtype=torch.float16)
|
17 |
-
.half()
|
18 |
-
.eval()
|
19 |
-
.requires_grad_(False)
|
20 |
-
.to(device)
|
21 |
-
)
|
22 |
taesd3.decoder.layers = torch.compile(
|
23 |
taesd3.decoder.layers,
|
24 |
fullgraph=True,
|
@@ -26,12 +19,16 @@ taesd3.decoder.layers = torch.compile(
|
|
26 |
mode="max-autotune-no-cudagraphs",
|
27 |
)
|
28 |
|
29 |
-
# Load main Stable Diffusion pipeline
|
30 |
-
pipe =
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
pipe.
|
33 |
-
|
34 |
-
pipe.fuse_lora(lora_scale=1.0)
|
35 |
|
36 |
MAX_SEED = np.iinfo(np.int32).max
|
37 |
MAX_IMAGE_SIZE = 1024
|
@@ -221,29 +218,14 @@ with gr.Blocks(css=css, theme="prithivMLmods/Minecraft-Theme") as demo:
|
|
221 |
value=4,
|
222 |
)
|
223 |
|
224 |
-
gr.Examples(examples=examples,
|
225 |
-
inputs=[prompt],
|
226 |
-
outputs=[result, seed],
|
227 |
-
fn=infer,
|
228 |
-
cache_examples=False)
|
229 |
|
230 |
gr.on(
|
231 |
triggers=[run_button.click, prompt.submit],
|
232 |
fn=infer,
|
233 |
-
inputs=[
|
234 |
-
prompt,
|
235 |
-
negative_prompt,
|
236 |
-
seed,
|
237 |
-
randomize_seed,
|
238 |
-
width,
|
239 |
-
height,
|
240 |
-
guidance_scale,
|
241 |
-
num_inference_steps,
|
242 |
-
style_selection,
|
243 |
-
grid_size_selection,
|
244 |
-
],
|
245 |
outputs=[result, seed],
|
246 |
)
|
247 |
|
248 |
if __name__ == "__main__":
|
249 |
-
demo.launch()
|
|
|
2 |
import spaces
|
3 |
import numpy as np
|
4 |
import random
|
5 |
+
from diffusers import DiffusionPipeline, AutoencoderTiny, StableDiffusion3Pipeline, SD3Transformer2DModel, FlashFlowMatchEulerDiscreteScheduler
|
6 |
import torch
|
7 |
from PIL import Image
|
8 |
|
|
|
10 |
model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
|
11 |
|
12 |
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
13 |
+
# Load Tiny Autoencoder
|
14 |
+
taesd3 = AutoencoderTiny.from_pretrained("madebyollin/taesd3", torch_dtype=torch.float16).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
taesd3.decoder.layers = torch.compile(
|
16 |
taesd3.decoder.layers,
|
17 |
fullgraph=True,
|
|
|
19 |
mode="max-autotune-no-cudagraphs",
|
20 |
)
|
21 |
|
22 |
+
# Load main Stable Diffusion pipeline
|
23 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
24 |
+
model_path,
|
25 |
+
transformer=SD3Transformer2DModel.from_pretrained(model_path, torch_dtype=torch.float16),
|
26 |
+
torch_dtype=torch_dtype,
|
27 |
+
vae=taesd3,
|
28 |
+
).to(device)
|
29 |
|
30 |
+
pipe.scheduler = FlashFlowMatchEulerDiscreteScheduler.from_pretrained(model_path, subfolder="scheduler")
|
31 |
+
pipe.set_progress_bar_config(disable=True)
|
|
|
32 |
|
33 |
MAX_SEED = np.iinfo(np.int32).max
|
34 |
MAX_IMAGE_SIZE = 1024
|
|
|
218 |
value=4,
|
219 |
)
|
220 |
|
221 |
+
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=False)
|
|
|
|
|
|
|
|
|
222 |
|
223 |
gr.on(
|
224 |
triggers=[run_button.click, prompt.submit],
|
225 |
fn=infer,
|
226 |
+
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, style_selection, grid_size_selection],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
outputs=[result, seed],
|
228 |
)
|
229 |
|
230 |
if __name__ == "__main__":
|
231 |
+
demo.launch()
|