Spaces:
Running
on
Zero
Running
on
Zero
prithivMLmods
commited on
Commit
•
06274a0
1
Parent(s):
5be9ee2
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,10 @@ import gradio as gr
|
|
2 |
import spaces
|
3 |
import numpy as np
|
4 |
import random
|
5 |
-
from diffusers import
|
|
|
|
|
|
|
6 |
import torch
|
7 |
from PIL import Image
|
8 |
|
@@ -11,14 +14,29 @@ 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 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Turbo-HyperRealistic-LoRA", weight_name="SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA.safetensors")
|
18 |
-
trigger_word = "hyper realistic"
|
19 |
pipe.fuse_lora(lora_scale=1.0)
|
20 |
|
21 |
-
MAX_SEED =
|
22 |
MAX_IMAGE_SIZE = 1024
|
23 |
|
24 |
# Define styles
|
@@ -104,6 +122,9 @@ def infer(
|
|
104 |
|
105 |
return grid_img, seed
|
106 |
|
|
|
|
|
|
|
107 |
examples = [
|
108 |
"A tiny astronaut hatching from an egg on the moon, 4k, planet theme",
|
109 |
"An anime illustration of a wiener schnitzel --style raw5, 4K",
|
|
|
2 |
import spaces
|
3 |
import numpy as np
|
4 |
import random
|
5 |
+
from diffusers import (
|
6 |
+
DiffusionPipeline, AutoencoderTiny, AutoencoderKL,
|
7 |
+
AutoPipelineForImage2Image, FluxPipeline, FlowMatchEulerDiscreteScheduler
|
8 |
+
)
|
9 |
import torch
|
10 |
from PIL import Image
|
11 |
|
|
|
14 |
|
15 |
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
16 |
|
17 |
+
# Load primary diffusion model and assign a smaller VAE for faster real-time previewing
|
18 |
+
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=torch_dtype).to(device)
|
19 |
+
good_vae = AutoencoderKL.from_pretrained(model_repo_id, subfolder="vae", torch_dtype=torch_dtype).to(device)
|
20 |
+
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype, vae=taef1).to(device)
|
21 |
+
|
22 |
+
# Set up for image-to-image pipeline with good VAE and smaller encoder for efficient preview
|
23 |
+
pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
|
24 |
+
model_repo_id,
|
25 |
+
vae=good_vae,
|
26 |
+
transformer=pipe.transformer,
|
27 |
+
text_encoder=pipe.text_encoder,
|
28 |
+
tokenizer=pipe.tokenizer,
|
29 |
+
text_encoder_2=pipe.text_encoder_2,
|
30 |
+
tokenizer_2=pipe.tokenizer_2,
|
31 |
+
torch_dtype=torch_dtype
|
32 |
+
)
|
33 |
+
|
34 |
+
# Load LoRA weights and set the scale for "hyper-realistic" prompt style
|
35 |
pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Turbo-HyperRealistic-LoRA", weight_name="SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA.safetensors")
|
36 |
+
trigger_word = "hyper realistic"
|
37 |
pipe.fuse_lora(lora_scale=1.0)
|
38 |
|
39 |
+
MAX_SEED = 2**32 - 1
|
40 |
MAX_IMAGE_SIZE = 1024
|
41 |
|
42 |
# Define styles
|
|
|
122 |
|
123 |
return grid_img, seed
|
124 |
|
125 |
+
# Setup for real-time image generation
|
126 |
+
pipe.flux_pipe_call_that_returns_an_iterable_of_images = pipe.flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
127 |
+
|
128 |
examples = [
|
129 |
"A tiny astronaut hatching from an egg on the moon, 4k, planet theme",
|
130 |
"An anime illustration of a wiener schnitzel --style raw5, 4K",
|