Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#path1.0398
|
2 |
import os
|
3 |
import random
|
4 |
import uuid
|
@@ -9,8 +8,7 @@ import numpy as np
|
|
9 |
from PIL import Image
|
10 |
import spaces
|
11 |
import torch
|
12 |
-
from diffusers import
|
13 |
-
from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
|
14 |
from typing import Tuple
|
15 |
|
16 |
# BaseConditions
|
@@ -46,56 +44,46 @@ style_list = [
|
|
46 |
]
|
47 |
|
48 |
collage_style_list = [
|
49 |
-
|
50 |
-
|
51 |
{
|
52 |
"name": "B & W",
|
53 |
"prompt": "black and white collage of {prompt}. monochromatic, timeless, classic, dramatic contrast",
|
54 |
"negative_prompt": "colorful, vibrant, bright, flashy",
|
55 |
},
|
56 |
-
|
57 |
{
|
58 |
"name": "Polaroid",
|
59 |
"prompt": "collage of polaroid photos featuring {prompt}. vintage style, high contrast, nostalgic, instant film aesthetic",
|
60 |
"negative_prompt": "digital, modern, low quality, blurry",
|
61 |
},
|
62 |
-
|
63 |
{
|
64 |
"name": "Watercolor",
|
65 |
"prompt": "watercolor collage of {prompt}. soft edges, translucent colors, painterly effects",
|
66 |
"negative_prompt": "digital, sharp lines, solid colors",
|
67 |
},
|
68 |
-
|
69 |
{
|
70 |
"name": "Cinematic",
|
71 |
"prompt": "cinematic collage of {prompt}. film stills, movie posters, dramatic lighting",
|
72 |
"negative_prompt": "static, lifeless, mundane",
|
73 |
},
|
74 |
-
|
75 |
{
|
76 |
"name": "Nostalgic",
|
77 |
"prompt": "nostalgic collage of {prompt}. retro imagery, vintage objects, sentimental journey",
|
78 |
"negative_prompt": "contemporary, futuristic, forward-looking",
|
79 |
},
|
80 |
-
|
81 |
{
|
82 |
"name": "Vintage",
|
83 |
"prompt": "vintage collage of {prompt}. aged paper, sepia tones, retro imagery, antique vibes",
|
84 |
"negative_prompt": "modern, contemporary, futuristic, high-tech",
|
85 |
},
|
86 |
-
|
87 |
{
|
88 |
"name": "Scrapbook",
|
89 |
"prompt": "scrapbook style collage of {prompt}. mixed media, hand-cut elements, textures, paper, stickers, doodles",
|
90 |
"negative_prompt": "clean, digital, modern, low quality",
|
91 |
},
|
92 |
-
|
93 |
{
|
94 |
"name": "NeoNGlow",
|
95 |
"prompt": "neon glow collage of {prompt}. vibrant colors, glowing effects, futuristic vibes",
|
96 |
"negative_prompt": "dull, muted colors, vintage, retro",
|
97 |
},
|
98 |
-
|
99 |
{
|
100 |
"name": "Geometric",
|
101 |
"prompt": "geometric collage of {prompt}. abstract shapes, colorful, sharp edges, modern design, high quality",
|
@@ -106,14 +94,11 @@ collage_style_list = [
|
|
106 |
"prompt": "thematic collage of {prompt}. cohesive theme, well-organized, matching colors, creative layout",
|
107 |
"negative_prompt": "random, messy, unorganized, clashing colors",
|
108 |
},
|
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 |
-
|
117 |
{
|
118 |
"name": "No Style",
|
119 |
"prompt": "{prompt}",
|
@@ -153,12 +138,11 @@ ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
|
153 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
154 |
|
155 |
if torch.cuda.is_available():
|
156 |
-
|
157 |
-
|
|
|
158 |
torch_dtype=torch.float16,
|
159 |
-
|
160 |
-
add_watermarker=False,
|
161 |
-
variant="fp16"
|
162 |
).to(device)
|
163 |
|
164 |
if ENABLE_CPU_OFFLOAD:
|
@@ -248,10 +232,8 @@ def generate(
|
|
248 |
return [unique_name], seed
|
249 |
|
250 |
examples = [
|
251 |
-
|
252 |
"Portrait of a beautiful woman in a hat, summer outfit, with freckles on her face, in a close up shot, with sunlight, outdoors, in soft light, with a beach background, looking at the camera, with high resolution photography, in the style of Hasselblad X2D50c --ar 85:128 --v 6.0 --style raw",
|
253 |
"Flying food photography with [Two Burgers] as the main subject, Splashes of Toppings and Seasonings, [Rocket Lettuce], [Cheddar Flavored Cheese], [Onion], [Pickles], [Special Sauce], [Sesame Bun], [ sea salt crystals] ::3 Capturing the dynamic splashes of food using high-speed photography , photorealistic, surrealism style, [white background], trending background [clean], Minimalist ::2 [Cuware], [Table], [ Steam], [Smoke], [Vegetable Leaves], [Tomato] ::-0.5 Ad Posters, Pro-Grade Color Grading, Studio Lighting, Rim Lights, [Layered Comps], EOS-1D X Mark III, 500px, Behance, concept art"
|
254 |
-
|
255 |
]
|
256 |
|
257 |
css = '''
|
@@ -407,4 +389,24 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
|
|
407 |
)
|
408 |
|
409 |
if __name__ == "__main__":
|
410 |
-
demo.queue(max_size=20).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import random
|
3 |
import uuid
|
|
|
8 |
from PIL import Image
|
9 |
import spaces
|
10 |
import torch
|
11 |
+
from diffusers import StableDiffusion3Pipeline, FlowMatchEulerDiscreteScheduler
|
|
|
12 |
from typing import Tuple
|
13 |
|
14 |
# BaseConditions
|
|
|
44 |
]
|
45 |
|
46 |
collage_style_list = [
|
|
|
|
|
47 |
{
|
48 |
"name": "B & W",
|
49 |
"prompt": "black and white collage of {prompt}. monochromatic, timeless, classic, dramatic contrast",
|
50 |
"negative_prompt": "colorful, vibrant, bright, flashy",
|
51 |
},
|
|
|
52 |
{
|
53 |
"name": "Polaroid",
|
54 |
"prompt": "collage of polaroid photos featuring {prompt}. vintage style, high contrast, nostalgic, instant film aesthetic",
|
55 |
"negative_prompt": "digital, modern, low quality, blurry",
|
56 |
},
|
|
|
57 |
{
|
58 |
"name": "Watercolor",
|
59 |
"prompt": "watercolor collage of {prompt}. soft edges, translucent colors, painterly effects",
|
60 |
"negative_prompt": "digital, sharp lines, solid colors",
|
61 |
},
|
|
|
62 |
{
|
63 |
"name": "Cinematic",
|
64 |
"prompt": "cinematic collage of {prompt}. film stills, movie posters, dramatic lighting",
|
65 |
"negative_prompt": "static, lifeless, mundane",
|
66 |
},
|
|
|
67 |
{
|
68 |
"name": "Nostalgic",
|
69 |
"prompt": "nostalgic collage of {prompt}. retro imagery, vintage objects, sentimental journey",
|
70 |
"negative_prompt": "contemporary, futuristic, forward-looking",
|
71 |
},
|
|
|
72 |
{
|
73 |
"name": "Vintage",
|
74 |
"prompt": "vintage collage of {prompt}. aged paper, sepia tones, retro imagery, antique vibes",
|
75 |
"negative_prompt": "modern, contemporary, futuristic, high-tech",
|
76 |
},
|
|
|
77 |
{
|
78 |
"name": "Scrapbook",
|
79 |
"prompt": "scrapbook style collage of {prompt}. mixed media, hand-cut elements, textures, paper, stickers, doodles",
|
80 |
"negative_prompt": "clean, digital, modern, low quality",
|
81 |
},
|
|
|
82 |
{
|
83 |
"name": "NeoNGlow",
|
84 |
"prompt": "neon glow collage of {prompt}. vibrant colors, glowing effects, futuristic vibes",
|
85 |
"negative_prompt": "dull, muted colors, vintage, retro",
|
86 |
},
|
|
|
87 |
{
|
88 |
"name": "Geometric",
|
89 |
"prompt": "geometric collage of {prompt}. abstract shapes, colorful, sharp edges, modern design, high quality",
|
|
|
94 |
"prompt": "thematic collage of {prompt}. cohesive theme, well-organized, matching colors, creative layout",
|
95 |
"negative_prompt": "random, messy, unorganized, clashing colors",
|
96 |
},
|
|
|
97 |
{
|
98 |
"name": "Retro Pop",
|
99 |
"prompt": "retro pop art collage of {prompt}. bold colors, comic book style, halftone dots, vintage ads",
|
100 |
"negative_prompt": "subdued colors, minimalist, modern, subtle",
|
101 |
},
|
|
|
|
|
102 |
{
|
103 |
"name": "No Style",
|
104 |
"prompt": "{prompt}",
|
|
|
138 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
139 |
|
140 |
if torch.cuda.is_available():
|
141 |
+
repo = "stabilityai/stable-diffusion-3-medium" # You might want to replace with your specific repo if different
|
142 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
143 |
+
repo,
|
144 |
torch_dtype=torch.float16,
|
145 |
+
revision="refs/pr/26"
|
|
|
|
|
146 |
).to(device)
|
147 |
|
148 |
if ENABLE_CPU_OFFLOAD:
|
|
|
232 |
return [unique_name], seed
|
233 |
|
234 |
examples = [
|
|
|
235 |
"Portrait of a beautiful woman in a hat, summer outfit, with freckles on her face, in a close up shot, with sunlight, outdoors, in soft light, with a beach background, looking at the camera, with high resolution photography, in the style of Hasselblad X2D50c --ar 85:128 --v 6.0 --style raw",
|
236 |
"Flying food photography with [Two Burgers] as the main subject, Splashes of Toppings and Seasonings, [Rocket Lettuce], [Cheddar Flavored Cheese], [Onion], [Pickles], [Special Sauce], [Sesame Bun], [ sea salt crystals] ::3 Capturing the dynamic splashes of food using high-speed photography , photorealistic, surrealism style, [white background], trending background [clean], Minimalist ::2 [Cuware], [Table], [ Steam], [Smoke], [Vegetable Leaves], [Tomato] ::-0.5 Ad Posters, Pro-Grade Color Grading, Studio Lighting, Rim Lights, [Layered Comps], EOS-1D X Mark III, 500px, Behance, concept art"
|
|
|
237 |
]
|
238 |
|
239 |
css = '''
|
|
|
389 |
)
|
390 |
|
391 |
if __name__ == "__main__":
|
392 |
+
demo.queue(max_size=20).launch()
|
393 |
+
|
394 |
+
# Updated inference function
|
395 |
+
@spaces.GPU
|
396 |
+
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
397 |
+
if randomize_seed:
|
398 |
+
seed = random.randint(0, MAX_SEED)
|
399 |
+
|
400 |
+
generator = torch.Generator().manual_seed(seed)
|
401 |
+
|
402 |
+
image = pipe(
|
403 |
+
prompt = prompt,
|
404 |
+
negative_prompt = negative_prompt,
|
405 |
+
guidance_scale = guidance_scale,
|
406 |
+
num_inference_steps = num_inference_steps,
|
407 |
+
width = width,
|
408 |
+
height = height,
|
409 |
+
generator = generator
|
410 |
+
).images[0]
|
411 |
+
|
412 |
+
return image, seed
|