Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
#patch 0.01yle(collage_style, prompt, negative_prompt)
|
3 |
import os
|
4 |
import random
|
5 |
import uuid
|
@@ -18,10 +16,10 @@ model_path = snapshot_download(
|
|
18 |
repo_id="stabilityai/stable-diffusion-3-medium",
|
19 |
revision="refs/pr/26",
|
20 |
repo_type="model",
|
21 |
-
ignore_patterns=["*.md", "
|
22 |
local_dir="stable-diffusion-3-medium",
|
23 |
token=huggingface_token, # yeni bir token-id yazın.
|
24 |
-
)
|
25 |
|
26 |
DESCRIPTION = """# Stable Diffusion 3"""
|
27 |
if not torch.cuda.is_available():
|
@@ -36,125 +34,25 @@ ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
|
36 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
37 |
|
38 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16)
|
39 |
-
|
40 |
-
# Define styles and collage templates
|
41 |
-
style_list = [
|
42 |
-
{
|
43 |
-
"name": "3840 x 2160",
|
44 |
-
"prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
45 |
-
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
46 |
-
},
|
47 |
-
{
|
48 |
-
"name": "2560 x 1440",
|
49 |
-
"prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
50 |
-
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
51 |
-
},
|
52 |
-
{
|
53 |
-
"name": "3D Model",
|
54 |
-
"prompt": "professional 3d model {prompt}. octane render, highly detailed, volumetric, dramatic lighting",
|
55 |
-
"negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
|
56 |
-
},
|
57 |
-
]
|
58 |
-
|
59 |
-
collage_style_list = [
|
60 |
-
{
|
61 |
-
"name": "B & W",
|
62 |
-
"prompt": "black and white collage of {prompt}. monochromatic, timeless, classic, dramatic contrast",
|
63 |
-
"negative_prompt": "colorful, vibrant, bright, flashy",
|
64 |
-
},
|
65 |
-
{
|
66 |
-
"name": "Polaroid",
|
67 |
-
"prompt": "collage of polaroid photos featuring {prompt}. vintage style, high contrast, nostalgic, instant film aesthetic",
|
68 |
-
"negative_prompt": "digital, modern, low quality, blurry",
|
69 |
-
},
|
70 |
-
{
|
71 |
-
"name": "Watercolor",
|
72 |
-
"prompt": "watercolor collage of {prompt}. soft edges, translucent colors, painterly effects",
|
73 |
-
"negative_prompt": "digital, sharp lines, solid colors",
|
74 |
-
},
|
75 |
-
{
|
76 |
-
"name": "Cinematic",
|
77 |
-
"prompt": "cinematic collage of {prompt}. film stills, movie posters, dramatic lighting",
|
78 |
-
"negative_prompt": "static, lifeless, mundane",
|
79 |
-
},
|
80 |
-
{
|
81 |
-
"name": "Nostalgic",
|
82 |
-
"prompt": "nostalgic collage of {prompt}. retro imagery, vintage objects, sentimental journey",
|
83 |
-
"negative_prompt": "contemporary, futuristic, forward-looking",
|
84 |
-
},
|
85 |
-
{
|
86 |
-
"name": "Vintage",
|
87 |
-
"prompt": "vintage collage of {prompt}. aged paper, sepia tones, retro imagery, antique vibes",
|
88 |
-
"negative_prompt": "modern, contemporary, futuristic, high-tech",
|
89 |
-
},
|
90 |
-
{
|
91 |
-
"name": "Scrapbook",
|
92 |
-
"prompt": "scrapbook style collage of {prompt}. mixed media, hand-cut elements, textures, paper, stickers, doodles",
|
93 |
-
"negative_prompt": "clean, digital, modern, low quality",
|
94 |
-
},
|
95 |
-
{
|
96 |
-
"name": "NeoNGlow",
|
97 |
-
"prompt": "neon glow collage of {prompt}. vibrant colors, glowing effects, futuristic vibes",
|
98 |
-
"negative_prompt": "dull, muted colors, vintage, retro",
|
99 |
-
},
|
100 |
-
{
|
101 |
-
"name": "Geometric",
|
102 |
-
"prompt": "geometric collage of {prompt}. abstract shapes, colorful, sharp edges, modern design, high quality",
|
103 |
-
"negative_prompt": "blurry, low quality, traditional, dull",
|
104 |
-
},
|
105 |
-
{
|
106 |
-
"name": "Thematic",
|
107 |
-
"prompt": "thematic collage of {prompt}. cohesive theme, well-organized, matching colors, creative layout",
|
108 |
-
"negative_prompt": "random, messy, unorganized, clashing colors",
|
109 |
-
},
|
110 |
-
{
|
111 |
-
"name": "Retro Pop",
|
112 |
-
"prompt": "retro pop art collage of {prompt}. bold colors, comic book style, halftone dots, vintage ads",
|
113 |
-
"negative_prompt": "subdued colors, minimalist, modern, subtle",
|
114 |
-
},
|
115 |
-
{
|
116 |
-
"name": "No Style",
|
117 |
-
"prompt": "{prompt}",
|
118 |
-
"negative_prompt": "",
|
119 |
-
},
|
120 |
-
]
|
121 |
-
|
122 |
-
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
123 |
-
collage_styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in collage_style_list}
|
124 |
-
STYLE_NAMES = list(styles.keys())
|
125 |
-
COLLAGE_STYLE_NAMES = list(collage_styles.keys())
|
126 |
-
DEFAULT_STYLE_NAME = "3840 x 2160"
|
127 |
-
DEFAULT_COLLAGE_STYLE_NAME = "B & W"
|
128 |
-
|
129 |
-
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
130 |
-
if style_name in styles:
|
131 |
-
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
132 |
-
elif style_name in collage_styles:
|
133 |
-
p, n = collage_styles.get(style_name, collage_styles[DEFAULT_COLLAGE_STYLE_NAME])
|
134 |
-
else:
|
135 |
-
p, n = styles[DEFAULT_STYLE_NAME]
|
136 |
|
137 |
-
if not negative:
|
138 |
-
negative = ""
|
139 |
-
return p.replace("{prompt}", positive), n + negative
|
140 |
|
141 |
def save_image(img):
|
142 |
unique_name = str(uuid.uuid4()) + ".png"
|
143 |
img.save(unique_name)
|
144 |
return unique_name
|
145 |
|
|
|
146 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
147 |
if randomize_seed:
|
148 |
seed = random.randint(0, MAX_SEED)
|
149 |
return seed
|
150 |
|
151 |
-
|
|
|
152 |
def generate(
|
153 |
prompt: str,
|
154 |
negative_prompt: str = "",
|
155 |
use_negative_prompt: bool = False,
|
156 |
-
style: str = DEFAULT_STYLE_NAME,
|
157 |
-
collage_style: str = DEFAULT_COLLAGE_STYLE_NAME,
|
158 |
seed: int = 0,
|
159 |
width: int = 1024,
|
160 |
height: int = 1024,
|
@@ -169,10 +67,7 @@ def generate(
|
|
169 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
170 |
generator = torch.Generator().manual_seed(seed)
|
171 |
|
172 |
-
|
173 |
-
prompt, negative_prompt = apply_style(collage_style, prompt, negative_prompt)
|
174 |
-
else:
|
175 |
-
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
176 |
|
177 |
if not use_negative_prompt:
|
178 |
negative_prompt = None # type: ignore
|
@@ -191,20 +86,14 @@ def generate(
|
|
191 |
|
192 |
return output
|
193 |
|
|
|
194 |
examples = [
|
195 |
-
"
|
196 |
-
"
|
197 |
-
"
|
198 |
-
"
|
199 |
-
"
|
200 |
-
"
|
201 |
-
"Portrait photograph of an anthropomorphic tortoise seated on a New York City subway train.",
|
202 |
-
"Batman, cute modern Disney style, Pixar 3d portrait, ultra detailed, gorgeous, 3d zbrush, trending on dribbble, 8k render.",
|
203 |
-
"Cinnamon bun on the plate, watercolor painting, detailed, brush strokes, light palette, light, cozy.",
|
204 |
-
"A lion, colorful, low-poly, cyan and orange eyes, poly-hd, 3d, low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition.",
|
205 |
-
"Long exposure photo of Tokyo street, blurred motion, streaks of light, surreal, dreamy, ghosting effect, highly detailed.",
|
206 |
-
"A glamorous digital magazine photoshoot, a fashionable model wearing avant-garde clothing, set in a futuristic cyberpunk roof-top environment, with a neon-lit city background, intricate high fashion details, backlit by vibrant city glow, Vogue fashion photography.",
|
207 |
-
"Masterpiece, best quality, girl, collarbone, wavy hair, looking at viewer, blurry foreground, upper body, necklace, contemporary, plain pants, intricate, print, pattern, ponytail, freckles, red hair, dappled sunlight, smile, happy."
|
208 |
]
|
209 |
|
210 |
css = '''
|
@@ -217,13 +106,16 @@ with gr.Blocks(css=css) as demo:
|
|
217 |
gr.HTML(
|
218 |
"""
|
219 |
<h1 style='text-align: center'>
|
220 |
-
Stable Diffusion 3
|
221 |
</h1>
|
222 |
"""
|
223 |
)
|
224 |
gr.HTML(
|
225 |
"""
|
226 |
-
|
|
|
|
|
|
|
227 |
"""
|
228 |
)
|
229 |
with gr.Group():
|
@@ -246,16 +138,6 @@ with gr.Blocks(css=css) as demo:
|
|
246 |
value = "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
|
247 |
visible=True,
|
248 |
)
|
249 |
-
style_selection = gr.Dropdown(
|
250 |
-
label="Style",
|
251 |
-
choices=STYLE_NAMES,
|
252 |
-
value=DEFAULT_STYLE_NAME,
|
253 |
-
)
|
254 |
-
collage_style_selection = gr.Dropdown(
|
255 |
-
label="Collage Template",
|
256 |
-
choices=COLLAGE_STYLE_NAMES,
|
257 |
-
value=DEFAULT_COLLAGE_STYLE_NAME,
|
258 |
-
)
|
259 |
seed = gr.Slider(
|
260 |
label="Seed",
|
261 |
minimum=0,
|
@@ -263,19 +145,20 @@ with gr.Blocks(css=css) as demo:
|
|
263 |
step=1,
|
264 |
value=0,
|
265 |
)
|
|
|
266 |
steps = gr.Slider(
|
267 |
label="Steps",
|
268 |
minimum=0,
|
269 |
maximum=60,
|
270 |
step=1,
|
271 |
-
value=
|
272 |
)
|
273 |
number_image = gr.Slider(
|
274 |
label="Number of Image",
|
275 |
minimum=1,
|
276 |
maximum=4,
|
277 |
step=1,
|
278 |
-
value=
|
279 |
)
|
280 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
281 |
with gr.Row(visible=True):
|
@@ -328,8 +211,6 @@ with gr.Blocks(css=css) as demo:
|
|
328 |
prompt,
|
329 |
negative_prompt,
|
330 |
use_negative_prompt,
|
331 |
-
style_selection,
|
332 |
-
collage_style_selection,
|
333 |
seed,
|
334 |
width,
|
335 |
height,
|
|
|
|
|
|
|
1 |
import os
|
2 |
import random
|
3 |
import uuid
|
|
|
16 |
repo_id="stabilityai/stable-diffusion-3-medium",
|
17 |
revision="refs/pr/26",
|
18 |
repo_type="model",
|
19 |
+
ignore_patterns=["*.md", "*..gitattributes"],
|
20 |
local_dir="stable-diffusion-3-medium",
|
21 |
token=huggingface_token, # yeni bir token-id yazın.
|
22 |
+
)
|
23 |
|
24 |
DESCRIPTION = """# Stable Diffusion 3"""
|
25 |
if not torch.cuda.is_available():
|
|
|
34 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
35 |
|
36 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
38 |
|
39 |
def save_image(img):
|
40 |
unique_name = str(uuid.uuid4()) + ".png"
|
41 |
img.save(unique_name)
|
42 |
return unique_name
|
43 |
|
44 |
+
|
45 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
46 |
if randomize_seed:
|
47 |
seed = random.randint(0, MAX_SEED)
|
48 |
return seed
|
49 |
|
50 |
+
|
51 |
+
@spaces.GPU(duration=30,enable_queue=True)
|
52 |
def generate(
|
53 |
prompt: str,
|
54 |
negative_prompt: str = "",
|
55 |
use_negative_prompt: bool = False,
|
|
|
|
|
56 |
seed: int = 0,
|
57 |
width: int = 1024,
|
58 |
height: int = 1024,
|
|
|
67 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
68 |
generator = torch.Generator().manual_seed(seed)
|
69 |
|
70 |
+
#pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
71 |
|
72 |
if not use_negative_prompt:
|
73 |
negative_prompt = None # type: ignore
|
|
|
86 |
|
87 |
return output
|
88 |
|
89 |
+
|
90 |
examples = [
|
91 |
+
"neon holography crystal cat",
|
92 |
+
"a cat eating a piece of cheese",
|
93 |
+
"an astronaut riding a horse in space",
|
94 |
+
"a cartoon of a boy playing with a tiger",
|
95 |
+
"a cute robot artist painting on an easel, concept art",
|
96 |
+
"a close up of a woman wearing a transparent, prismatic, elaborate nemeses headdress, over the should pose, brown skin-tone"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
]
|
98 |
|
99 |
css = '''
|
|
|
106 |
gr.HTML(
|
107 |
"""
|
108 |
<h1 style='text-align: center'>
|
109 |
+
Stable Diffusion 3
|
110 |
</h1>
|
111 |
"""
|
112 |
)
|
113 |
gr.HTML(
|
114 |
"""
|
115 |
+
<h3 style='text-align: center'>
|
116 |
+
Follow me for more!
|
117 |
+
<a href='https://twitter.com/sot_data' target='_blank'>Twitter</a> | <a href='https://github.com/sourceoftruthdata' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/danielwcovarrubias/' target='_blank'>Linkedin</a>
|
118 |
+
</h3>
|
119 |
"""
|
120 |
)
|
121 |
with gr.Group():
|
|
|
138 |
value = "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
|
139 |
visible=True,
|
140 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
seed = gr.Slider(
|
142 |
label="Seed",
|
143 |
minimum=0,
|
|
|
145 |
step=1,
|
146 |
value=0,
|
147 |
)
|
148 |
+
|
149 |
steps = gr.Slider(
|
150 |
label="Steps",
|
151 |
minimum=0,
|
152 |
maximum=60,
|
153 |
step=1,
|
154 |
+
value=25,
|
155 |
)
|
156 |
number_image = gr.Slider(
|
157 |
label="Number of Image",
|
158 |
minimum=1,
|
159 |
maximum=4,
|
160 |
step=1,
|
161 |
+
value=1,
|
162 |
)
|
163 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
164 |
with gr.Row(visible=True):
|
|
|
211 |
prompt,
|
212 |
negative_prompt,
|
213 |
use_negative_prompt,
|
|
|
|
|
214 |
seed,
|
215 |
width,
|
216 |
height,
|