Spaces:
Running
on
Zero
Running
on
Zero
prithivMLmods
commited on
Commit
•
c9c6564
1
Parent(s):
7a5a9f7
Update app.py
Browse files
app.py
CHANGED
@@ -6,23 +6,18 @@ from diffusers import DiffusionPipeline
|
|
6 |
import torch
|
7 |
from PIL import Image
|
8 |
|
9 |
-
# Device configuration
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
|
12 |
|
13 |
-
# Set data type based on device availability
|
14 |
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
15 |
|
16 |
-
# Load the pipeline
|
17 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
pipe = pipe.to(device)
|
19 |
|
20 |
-
# Load LoRA weights
|
21 |
pipe.load_lora_weights("prithivMLmods/SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA", weight_name="SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA.safetensors")
|
22 |
trigger_word = "hyper realistic" # Specify trigger word for LoRA
|
23 |
pipe.fuse_lora(lora_scale=1.0)
|
24 |
|
25 |
-
# Constants
|
26 |
MAX_SEED = np.iinfo(np.int32).max
|
27 |
MAX_IMAGE_SIZE = 1024
|
28 |
|
@@ -71,12 +66,11 @@ def infer(
|
|
71 |
width=1024,
|
72 |
height=1024,
|
73 |
guidance_scale=7.5,
|
74 |
-
num_inference_steps=
|
75 |
style="Style Zero",
|
76 |
grid_size="1x1",
|
77 |
progress=gr.Progress(track_tqdm=True),
|
78 |
):
|
79 |
-
# Apply selected style
|
80 |
selected_style = next(s for s in style_list if s["name"] == style)
|
81 |
styled_prompt = selected_style["prompt"].format(prompt=prompt)
|
82 |
styled_negative_prompt = selected_style["negative_prompt"]
|
@@ -86,11 +80,9 @@ def infer(
|
|
86 |
|
87 |
generator = torch.Generator().manual_seed(seed)
|
88 |
|
89 |
-
# Get grid size
|
90 |
grid_size_x, grid_size_y = grid_sizes.get(grid_size, (1, 1))
|
91 |
num_images = grid_size_x * grid_size_y
|
92 |
|
93 |
-
# Generate multiple images
|
94 |
options = {
|
95 |
"prompt": styled_prompt,
|
96 |
"negative_prompt": styled_negative_prompt,
|
@@ -105,10 +97,8 @@ def infer(
|
|
105 |
torch.cuda.empty_cache() # Clear GPU memory
|
106 |
result = pipe(**options)
|
107 |
|
108 |
-
# Create grid image
|
109 |
grid_img = Image.new('RGB', (width * grid_size_x, height * grid_size_y))
|
110 |
|
111 |
-
# Paste images into the grid
|
112 |
for i, img in enumerate(result.images[:num_images]):
|
113 |
grid_img.paste(img, (i % grid_size_x * width, i // grid_size_x * height))
|
114 |
|
@@ -213,7 +203,7 @@ with gr.Blocks(css=css, theme="prithivMLmods/Minecraft-Theme") as demo:
|
|
213 |
minimum=1,
|
214 |
maximum=50,
|
215 |
step=1,
|
216 |
-
value=
|
217 |
)
|
218 |
|
219 |
gr.Examples(examples=examples,
|
|
|
6 |
import torch
|
7 |
from PIL import Image
|
8 |
|
|
|
9 |
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 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
15 |
pipe = pipe.to(device)
|
16 |
|
|
|
17 |
pipe.load_lora_weights("prithivMLmods/SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA", weight_name="SD3.5-4Step-Large-Turbo-HyperRealistic-LoRA.safetensors")
|
18 |
trigger_word = "hyper realistic" # Specify trigger word for LoRA
|
19 |
pipe.fuse_lora(lora_scale=1.0)
|
20 |
|
|
|
21 |
MAX_SEED = np.iinfo(np.int32).max
|
22 |
MAX_IMAGE_SIZE = 1024
|
23 |
|
|
|
66 |
width=1024,
|
67 |
height=1024,
|
68 |
guidance_scale=7.5,
|
69 |
+
num_inference_steps=8,
|
70 |
style="Style Zero",
|
71 |
grid_size="1x1",
|
72 |
progress=gr.Progress(track_tqdm=True),
|
73 |
):
|
|
|
74 |
selected_style = next(s for s in style_list if s["name"] == style)
|
75 |
styled_prompt = selected_style["prompt"].format(prompt=prompt)
|
76 |
styled_negative_prompt = selected_style["negative_prompt"]
|
|
|
80 |
|
81 |
generator = torch.Generator().manual_seed(seed)
|
82 |
|
|
|
83 |
grid_size_x, grid_size_y = grid_sizes.get(grid_size, (1, 1))
|
84 |
num_images = grid_size_x * grid_size_y
|
85 |
|
|
|
86 |
options = {
|
87 |
"prompt": styled_prompt,
|
88 |
"negative_prompt": styled_negative_prompt,
|
|
|
97 |
torch.cuda.empty_cache() # Clear GPU memory
|
98 |
result = pipe(**options)
|
99 |
|
|
|
100 |
grid_img = Image.new('RGB', (width * grid_size_x, height * grid_size_y))
|
101 |
|
|
|
102 |
for i, img in enumerate(result.images[:num_images]):
|
103 |
grid_img.paste(img, (i % grid_size_x * width, i // grid_size_x * height))
|
104 |
|
|
|
203 |
minimum=1,
|
204 |
maximum=50,
|
205 |
step=1,
|
206 |
+
value=8,
|
207 |
)
|
208 |
|
209 |
gr.Examples(examples=examples,
|