Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,245 @@ import spaces
|
|
11 |
import torch
|
12 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
DESCRIPTION = """
|
15 |
-
#
|
16 |
"""
|
17 |
|
18 |
def save_image(img):
|
@@ -28,7 +265,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
28 |
MAX_SEED = np.iinfo(np.int32).max
|
29 |
|
30 |
if not torch.cuda.is_available():
|
31 |
-
DESCRIPTION += "\n<p
|
32 |
|
33 |
MAX_SEED = np.iinfo(np.int32).max
|
34 |
|
@@ -96,7 +333,7 @@ examples = [
|
|
96 |
]
|
97 |
|
98 |
css = '''
|
99 |
-
.gradio-container{max-width:
|
100 |
h1{text-align:center}
|
101 |
footer {
|
102 |
visibility: hidden
|
@@ -116,10 +353,10 @@ with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
|
|
116 |
label="Prompt",
|
117 |
show_label=False,
|
118 |
max_lines=1,
|
119 |
-
placeholder="
|
120 |
container=False,
|
121 |
)
|
122 |
-
run_button = gr.Button("
|
123 |
result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
|
124 |
with gr.Accordion("Advanced options", open=False):
|
125 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
|
|
11 |
import torch
|
12 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
13 |
|
14 |
+
#BaseConditions--
|
15 |
+
bad_words = json.loads(os.getenv('BAD_WORDS', "[]"))
|
16 |
+
bad_words_negative = json.loads(os.getenv('BAD_WORDS_NEGATIVE', "[]"))
|
17 |
+
default_negative = os.getenv("default_negative","")
|
18 |
+
|
19 |
+
def check_text(prompt, negative=""):
|
20 |
+
for i in bad_words:
|
21 |
+
if i in prompt:
|
22 |
+
return True
|
23 |
+
for i in bad_words_negative:
|
24 |
+
if i in negative:
|
25 |
+
return True
|
26 |
+
return False
|
27 |
+
|
28 |
+
#Quality/Style-----------------------------------------------------------------------------------------------------------------------------------------------------------Quality/Style
|
29 |
+
|
30 |
+
style_list = [
|
31 |
+
{
|
32 |
+
"name": "3840 x 2160",
|
33 |
+
"prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
34 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"name": "2560 x 1440",
|
38 |
+
"prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
39 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
40 |
+
},
|
41 |
+
|
42 |
+
{
|
43 |
+
"name": "HD+",
|
44 |
+
"prompt": "hyper-realistic 2K 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 |
+
{
|
49 |
+
"name": "Style Zero",
|
50 |
+
"prompt": "{prompt}",
|
51 |
+
"negative_prompt": "",
|
52 |
+
},
|
53 |
+
|
54 |
+
]
|
55 |
+
|
56 |
+
#Clgstyle--------------------------------------------------------------------------------------------------------------------------------------------------------------Clgstyle
|
57 |
+
|
58 |
+
collage_style_list = [
|
59 |
+
{
|
60 |
+
"name": "Hi-Res",
|
61 |
+
"prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
62 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"name": "B & W",
|
66 |
+
"prompt": "black and white collage of {prompt}. monochromatic, timeless, classic, dramatic contrast",
|
67 |
+
"negative_prompt": "colorful, vibrant, bright, flashy",
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"name": "Polaroid",
|
71 |
+
"prompt": "collage of polaroid photos featuring {prompt}. vintage style, high contrast, nostalgic, instant film aesthetic",
|
72 |
+
"negative_prompt": "digital, modern, low quality, blurry",
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"name": "Watercolor",
|
76 |
+
"prompt": "watercolor collage of {prompt}. soft edges, translucent colors, painterly effects",
|
77 |
+
"negative_prompt": "digital, sharp lines, solid colors",
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"name": "Cinematic",
|
81 |
+
"prompt": "cinematic collage of {prompt}. film stills, movie posters, dramatic lighting",
|
82 |
+
"negative_prompt": "static, lifeless, mundane",
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"name": "Nostalgic",
|
86 |
+
"prompt": "nostalgic collage of {prompt}. retro imagery, vintage objects, sentimental journey",
|
87 |
+
"negative_prompt": "contemporary, futuristic, forward-looking",
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"name": "Vintage",
|
91 |
+
"prompt": "vintage collage of {prompt}. aged paper, sepia tones, retro imagery, antique vibes",
|
92 |
+
"negative_prompt": "modern, contemporary, futuristic, high-tech",
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"name": "Scrapbook",
|
96 |
+
"prompt": "scrapbook style collage of {prompt}. mixed media, hand-cut elements, textures, paper, stickers, doodles",
|
97 |
+
"negative_prompt": "clean, digital, modern, low quality",
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"name": "NeoNGlow",
|
101 |
+
"prompt": "neon glow collage of {prompt}. vibrant colors, glowing effects, futuristic vibes",
|
102 |
+
"negative_prompt": "dull, muted colors, vintage, retro",
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"name": "Geometric",
|
106 |
+
"prompt": "geometric collage of {prompt}. abstract shapes, colorful, sharp edges, modern design, high quality",
|
107 |
+
"negative_prompt": "blurry, low quality, traditional, dull",
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"name": "Thematic",
|
111 |
+
"prompt": "thematic collage of {prompt}. cohesive theme, well-organized, matching colors, creative layout",
|
112 |
+
"negative_prompt": "random, messy, unorganized, clashing colors",
|
113 |
+
},
|
114 |
+
|
115 |
+
#DuoTones by Canva --------------------------------------------------------------------------------------------------------------- Alters only the i++ Part / not Zero Tones
|
116 |
+
|
117 |
+
{
|
118 |
+
"name": "Cherry",
|
119 |
+
"prompt": "Duotone style Cherry tone applied to {prompt}",
|
120 |
+
"negative_prompt": "",
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"name": "Fuchsia",
|
124 |
+
"prompt": "Duotone style Fuchsia tone applied to {prompt}",
|
125 |
+
"negative_prompt": "",
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"name": "Pop",
|
129 |
+
"prompt": "Duotone style Pop tone applied to {prompt}",
|
130 |
+
"negative_prompt": "",
|
131 |
+
},
|
132 |
+
{
|
133 |
+
"name": "Violet",
|
134 |
+
"prompt": "Duotone style Violet applied to {prompt}",
|
135 |
+
"negative_prompt": "",
|
136 |
+
},
|
137 |
+
{
|
138 |
+
"name": "Sea Blue",
|
139 |
+
"prompt": "Duotone style Sea Blue applied to {prompt}",
|
140 |
+
"negative_prompt": "",
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"name": "Sea Green",
|
144 |
+
"prompt": "Duotone style Sea Green applied to {prompt}",
|
145 |
+
"negative_prompt": "",
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"name": "Mustard",
|
149 |
+
"prompt": "Duotone style Mustard applied to {prompt}",
|
150 |
+
"negative_prompt": "",
|
151 |
+
},
|
152 |
+
{
|
153 |
+
"name": "Amber",
|
154 |
+
"prompt": "Duotone style Amber applied to {prompt}",
|
155 |
+
"negative_prompt": "",
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"name": "Pomelo",
|
159 |
+
"prompt": "Duotone style Pomelo applied to {prompt}",
|
160 |
+
"negative_prompt": "",
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"name": "Peppermint",
|
164 |
+
"prompt": "Duotone style Peppermint applied to {prompt}",
|
165 |
+
"negative_prompt": "",
|
166 |
+
},
|
167 |
+
{
|
168 |
+
"name": "Mystic",
|
169 |
+
"prompt": "Duotone style Mystic tone applied to {prompt}",
|
170 |
+
"negative_prompt": "",
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"name": "Pastel",
|
174 |
+
"prompt": "Duotone style Pastel applied to {prompt}",
|
175 |
+
"negative_prompt": "",
|
176 |
+
},
|
177 |
+
{
|
178 |
+
"name": "Coral",
|
179 |
+
"prompt": "Duotone style Coral applied to {prompt}",
|
180 |
+
"negative_prompt": "",
|
181 |
+
},
|
182 |
+
{
|
183 |
+
"name": "No Style",
|
184 |
+
"prompt": "{prompt}",
|
185 |
+
"negative_prompt": "",
|
186 |
+
},
|
187 |
+
|
188 |
+
]
|
189 |
+
|
190 |
+
#filters------------------------------------------------------------------------------------------------------------------------------------------------filters
|
191 |
+
|
192 |
+
filters = {
|
193 |
+
"Vivid": {
|
194 |
+
"prompt": "extra vivid {prompt}",
|
195 |
+
"negative_prompt": "washed out, dull"
|
196 |
+
},
|
197 |
+
"Playa": {
|
198 |
+
"prompt": "{prompt} set in a vast playa",
|
199 |
+
"negative_prompt": "forest, mountains"
|
200 |
+
},
|
201 |
+
"Desert": {
|
202 |
+
"prompt": "{prompt} set in a desert landscape",
|
203 |
+
"negative_prompt": "ocean, city"
|
204 |
+
},
|
205 |
+
"West": {
|
206 |
+
"prompt": "{prompt} with a western theme",
|
207 |
+
"negative_prompt": "eastern, modern"
|
208 |
+
},
|
209 |
+
"Blush": {
|
210 |
+
"prompt": "{prompt} with a soft blush color palette",
|
211 |
+
"negative_prompt": "harsh colors, neon"
|
212 |
+
},
|
213 |
+
"Minimalist": {
|
214 |
+
"prompt": "{prompt} with a minimalist design",
|
215 |
+
"negative_prompt": "cluttered, ornate"
|
216 |
+
},
|
217 |
+
|
218 |
+
"Zero filter": {
|
219 |
+
"prompt": "{prompt}",
|
220 |
+
"negative_prompt": ""
|
221 |
+
},
|
222 |
+
|
223 |
+
|
224 |
+
}
|
225 |
+
|
226 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
227 |
+
collage_styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in collage_style_list}
|
228 |
+
filter_styles = {k: (v["prompt"], v["negative_prompt"]) for k, v in filters.items()}
|
229 |
+
|
230 |
+
STYLE_NAMES = list(styles.keys())
|
231 |
+
COLLAGE_STYLE_NAMES = list(collage_styles.keys())
|
232 |
+
FILTER_NAMES = list(filters.keys())
|
233 |
+
DEFAULT_STYLE_NAME = "3840 x 2160"
|
234 |
+
DEFAULT_COLLAGE_STYLE_NAME = "Hi-Res"
|
235 |
+
DEFAULT_FILTER_NAME = "Zero filter"
|
236 |
+
|
237 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
238 |
+
if style_name in styles:
|
239 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
240 |
+
elif style_name in collage_styles:
|
241 |
+
p, n = collage_styles.get(style_name, collage_styles[DEFAULT_COLLAGE_STYLE_NAME])
|
242 |
+
elif style_name in filter_styles:
|
243 |
+
p, n = filter_styles.get(style_name, filter_styles[DEFAULT_FILTER_NAME])
|
244 |
+
else:
|
245 |
+
p, n = styles[DEFAULT_STYLE_NAME]
|
246 |
+
|
247 |
+
if not negative:
|
248 |
+
negative = ""
|
249 |
+
return p.replace("{prompt}", positive), n + negative
|
250 |
+
|
251 |
DESCRIPTION = """
|
252 |
+
# Midjourney Free on <a href='https://gpt-chatbot.ru/' target='_blank'>GPT-ChatBot.ru</a>
|
253 |
"""
|
254 |
|
255 |
def save_image(img):
|
|
|
265 |
MAX_SEED = np.iinfo(np.int32).max
|
266 |
|
267 |
if not torch.cuda.is_available():
|
268 |
+
DESCRIPTION += "\n<p>Начинаем генерировать</p>"
|
269 |
|
270 |
MAX_SEED = np.iinfo(np.int32).max
|
271 |
|
|
|
333 |
]
|
334 |
|
335 |
css = '''
|
336 |
+
.gradio-container{max-width: 100% !important}
|
337 |
h1{text-align:center}
|
338 |
footer {
|
339 |
visibility: hidden
|
|
|
353 |
label="Prompt",
|
354 |
show_label=False,
|
355 |
max_lines=1,
|
356 |
+
placeholder="Введите ваш промпт",
|
357 |
container=False,
|
358 |
)
|
359 |
+
run_button = gr.Button("Генерировать", scale=0)
|
360 |
result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
|
361 |
with gr.Accordion("Advanced options", open=False):
|
362 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|