kasper-boy commited on
Commit
1e96315
1 Parent(s): 79c2d61

Upload 3 files

Browse files
Files changed (3) hide show
  1. Duotone.txt +77 -0
  2. app.py +628 -0
  3. requirements.txt +11 -0
Duotone.txt ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ duotone_styles = [
2
+ {
3
+ "name": "No Tone",
4
+ "prompt": "{prompt}",
5
+ "negative_prompt": "",
6
+ },
7
+ {
8
+ "name": "Cherry",
9
+ "prompt": "Duotone style Cherry applied to {prompt}",
10
+ "negative_prompt": "",
11
+ },
12
+ {
13
+ "name": "Fuchsia",
14
+ "prompt": "Duotone style Fuchsia applied to {prompt}",
15
+ "negative_prompt": "",
16
+ },
17
+ {
18
+ "name": "Pop",
19
+ "prompt": "Duotone style Pop applied to {prompt}",
20
+ "negative_prompt": "",
21
+ },
22
+ {
23
+ "name": "Violet",
24
+ "prompt": "Duotone style Violet applied to {prompt}",
25
+ "negative_prompt": "",
26
+ },
27
+ {
28
+ "name": "Sea Blue",
29
+ "prompt": "Duotone style Sea Blue applied to {prompt}",
30
+ "negative_prompt": "",
31
+ },
32
+ {
33
+ "name": "Sea Green",
34
+ "prompt": "Duotone style Sea Green applied to {prompt}",
35
+ "negative_prompt": "",
36
+ },
37
+ {
38
+ "name": "Mustard",
39
+ "prompt": "Duotone style Mustard applied to {prompt}",
40
+ "negative_prompt": "",
41
+ },
42
+ {
43
+ "name": "Amber",
44
+ "prompt": "Duotone style Amber applied to {prompt}",
45
+ "negative_prompt": "",
46
+ },
47
+ {
48
+ "name": "Pomelo",
49
+ "prompt": "Duotone style Pomelo applied to {prompt}",
50
+ "negative_prompt": "",
51
+ },
52
+ {
53
+ "name": "Blush",
54
+ "prompt": "Duotone style Blush applied to {prompt}",
55
+ "negative_prompt": "",
56
+ },
57
+ {
58
+ "name": "Peppermint",
59
+ "prompt": "Duotone style Peppermint applied to {prompt}",
60
+ "negative_prompt": "",
61
+ },
62
+ {
63
+ "name": "Mystic",
64
+ "prompt": "Duotone style Mystic applied to {prompt}",
65
+ "negative_prompt": "",
66
+ },
67
+ {
68
+ "name": "Pastel",
69
+ "prompt": "Duotone style Pastel applied to {prompt}",
70
+ "negative_prompt": "",
71
+ },
72
+ {
73
+ "name": "Coral",
74
+ "prompt": "Duotone style Coral applied to {prompt}",
75
+ "negative_prompt": "",
76
+ }
77
+ ]
app.py ADDED
@@ -0,0 +1,628 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #patch 3.0 ()
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # ...
11
+ import os
12
+ import random
13
+ import uuid
14
+ import json
15
+
16
+ import gradio as gr
17
+ import numpy as np
18
+ from PIL import Image
19
+ import spaces
20
+ import torch
21
+ from diffusers import DiffusionPipeline, StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
22
+ from typing import Tuple
23
+
24
+ #BaseConditions--
25
+ bad_words = json.loads(os.getenv('BAD_WORDS', "[]"))
26
+ bad_words_negative = json.loads(os.getenv('BAD_WORDS_NEGATIVE', "[]"))
27
+ default_negative = os.getenv("default_negative","")
28
+
29
+ def check_text(prompt, negative=""):
30
+ for i in bad_words:
31
+ if i in prompt:
32
+ return True
33
+ for i in bad_words_negative:
34
+ if i in negative:
35
+ return True
36
+ return False
37
+
38
+ #Quality/Style-----------------------------------------------------------------------------------------------------------------------------------------------------------Quality/Style
39
+
40
+ style_list = [
41
+ {
42
+ "name": "3840 x 2160",
43
+ "prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
44
+ "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
45
+ },
46
+ {
47
+ "name": "2560 x 1440",
48
+ "prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
49
+ "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
50
+ },
51
+
52
+ {
53
+ "name": "HD+",
54
+ "prompt": "hyper-realistic 2K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
55
+ "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
56
+ },
57
+
58
+ {
59
+ "name": "Style Zero",
60
+ "prompt": "{prompt}",
61
+ "negative_prompt": "",
62
+ },
63
+
64
+ ]
65
+
66
+ #Clgstyle--------------------------------------------------------------------------------------------------------------------------------------------------------------Clgstyle
67
+
68
+ collage_style_list = [
69
+ {
70
+ "name": "Hi-Res",
71
+ "prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
72
+ "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
73
+ },
74
+ {
75
+ "name": "B & W",
76
+ "prompt": "black and white collage of {prompt}. monochromatic, timeless, classic, dramatic contrast",
77
+ "negative_prompt": "colorful, vibrant, bright, flashy",
78
+ },
79
+ {
80
+ "name": "Polaroid",
81
+ "prompt": "collage of polaroid photos featuring {prompt}. vintage style, high contrast, nostalgic, instant film aesthetic",
82
+ "negative_prompt": "digital, modern, low quality, blurry",
83
+ },
84
+ {
85
+ "name": "Watercolor",
86
+ "prompt": "watercolor collage of {prompt}. soft edges, translucent colors, painterly effects",
87
+ "negative_prompt": "digital, sharp lines, solid colors",
88
+ },
89
+ {
90
+ "name": "Cinematic",
91
+ "prompt": "cinematic collage of {prompt}. film stills, movie posters, dramatic lighting",
92
+ "negative_prompt": "static, lifeless, mundane",
93
+ },
94
+ {
95
+ "name": "Nostalgic",
96
+ "prompt": "nostalgic collage of {prompt}. retro imagery, vintage objects, sentimental journey",
97
+ "negative_prompt": "contemporary, futuristic, forward-looking",
98
+ },
99
+ {
100
+ "name": "Vintage",
101
+ "prompt": "vintage collage of {prompt}. aged paper, sepia tones, retro imagery, antique vibes",
102
+ "negative_prompt": "modern, contemporary, futuristic, high-tech",
103
+ },
104
+ {
105
+ "name": "Scrapbook",
106
+ "prompt": "scrapbook style collage of {prompt}. mixed media, hand-cut elements, textures, paper, stickers, doodles",
107
+ "negative_prompt": "clean, digital, modern, low quality",
108
+ },
109
+ {
110
+ "name": "NeoNGlow",
111
+ "prompt": "neon glow collage of {prompt}. vibrant colors, glowing effects, futuristic vibes",
112
+ "negative_prompt": "dull, muted colors, vintage, retro",
113
+ },
114
+ {
115
+ "name": "Geometric",
116
+ "prompt": "geometric collage of {prompt}. abstract shapes, colorful, sharp edges, modern design, high quality",
117
+ "negative_prompt": "blurry, low quality, traditional, dull",
118
+ },
119
+ {
120
+ "name": "Thematic",
121
+ "prompt": "thematic collage of {prompt}. cohesive theme, well-organized, matching colors, creative layout",
122
+ "negative_prompt": "random, messy, unorganized, clashing colors",
123
+ },
124
+
125
+ #DuoTones by Canva --------------------------------------------------------------------------------------------------------------- Alters only the i++ Part / not Zero Tones
126
+
127
+ {
128
+ "name": "Cherry",
129
+ "prompt": "Duotone style Cherry tone applied to {prompt}",
130
+ "negative_prompt": "",
131
+ },
132
+ {
133
+ "name": "Fuchsia",
134
+ "prompt": "Duotone style Fuchsia tone applied to {prompt}",
135
+ "negative_prompt": "",
136
+ },
137
+ {
138
+ "name": "Pop",
139
+ "prompt": "Duotone style Pop tone applied to {prompt}",
140
+ "negative_prompt": "",
141
+ },
142
+ {
143
+ "name": "Violet",
144
+ "prompt": "Duotone style Violet applied to {prompt}",
145
+ "negative_prompt": "",
146
+ },
147
+ {
148
+ "name": "Sea Blue",
149
+ "prompt": "Duotone style Sea Blue applied to {prompt}",
150
+ "negative_prompt": "",
151
+ },
152
+ {
153
+ "name": "Sea Green",
154
+ "prompt": "Duotone style Sea Green applied to {prompt}",
155
+ "negative_prompt": "",
156
+ },
157
+ {
158
+ "name": "Mustard",
159
+ "prompt": "Duotone style Mustard applied to {prompt}",
160
+ "negative_prompt": "",
161
+ },
162
+ {
163
+ "name": "Amber",
164
+ "prompt": "Duotone style Amber applied to {prompt}",
165
+ "negative_prompt": "",
166
+ },
167
+ {
168
+ "name": "Pomelo",
169
+ "prompt": "Duotone style Pomelo applied to {prompt}",
170
+ "negative_prompt": "",
171
+ },
172
+ {
173
+ "name": "Peppermint",
174
+ "prompt": "Duotone style Peppermint applied to {prompt}",
175
+ "negative_prompt": "",
176
+ },
177
+ {
178
+ "name": "Mystic",
179
+ "prompt": "Duotone style Mystic tone applied to {prompt}",
180
+ "negative_prompt": "",
181
+ },
182
+ {
183
+ "name": "Pastel",
184
+ "prompt": "Duotone style Pastel applied to {prompt}",
185
+ "negative_prompt": "",
186
+ },
187
+ {
188
+ "name": "Coral",
189
+ "prompt": "Duotone style Coral applied to {prompt}",
190
+ "negative_prompt": "",
191
+ },
192
+ {
193
+ "name": "No Style",
194
+ "prompt": "{prompt}",
195
+ "negative_prompt": "",
196
+ },
197
+
198
+ ]
199
+
200
+ #filters------------------------------------------------------------------------------------------------------------------------------------------------filters
201
+
202
+ filters = {
203
+ "Vivid": {
204
+ "prompt": "extra vivid {prompt}",
205
+ "negative_prompt": "washed out, dull"
206
+ },
207
+ "Playa": {
208
+ "prompt": "{prompt} set in a vast playa",
209
+ "negative_prompt": "forest, mountains"
210
+ },
211
+ "Desert": {
212
+ "prompt": "{prompt} set in a desert landscape",
213
+ "negative_prompt": "ocean, city"
214
+ },
215
+ "West": {
216
+ "prompt": "{prompt} with a western theme",
217
+ "negative_prompt": "eastern, modern"
218
+ },
219
+ "Blush": {
220
+ "prompt": "{prompt} with a soft blush color palette",
221
+ "negative_prompt": "harsh colors, neon"
222
+ },
223
+ "Minimalist": {
224
+ "prompt": "{prompt} with a minimalist design",
225
+ "negative_prompt": "cluttered, ornate"
226
+ },
227
+
228
+ "Zero filter": {
229
+ "prompt": "{prompt}",
230
+ "negative_prompt": ""
231
+ },
232
+
233
+
234
+ }
235
+
236
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
237
+ collage_styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in collage_style_list}
238
+ filter_styles = {k: (v["prompt"], v["negative_prompt"]) for k, v in filters.items()}
239
+
240
+ STYLE_NAMES = list(styles.keys())
241
+ COLLAGE_STYLE_NAMES = list(collage_styles.keys())
242
+ FILTER_NAMES = list(filters.keys())
243
+ DEFAULT_STYLE_NAME = "3840 x 2160"
244
+ DEFAULT_COLLAGE_STYLE_NAME = "Hi-Res"
245
+ DEFAULT_FILTER_NAME = "Zero filter"
246
+
247
+ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
248
+ if style_name in styles:
249
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
250
+ elif style_name in collage_styles:
251
+ p, n = collage_styles.get(style_name, collage_styles[DEFAULT_COLLAGE_STYLE_NAME])
252
+ elif style_name in filter_styles:
253
+ p, n = filter_styles.get(style_name, filter_styles[DEFAULT_FILTER_NAME])
254
+ else:
255
+ p, n = styles[DEFAULT_STYLE_NAME]
256
+
257
+ if not negative:
258
+ negative = ""
259
+ return p.replace("{prompt}", positive), n + negative
260
+
261
+
262
+
263
+ DESCRIPTION = """## IMAGINEO 4K 🏞️
264
+
265
+
266
+ """
267
+
268
+ DESCRIPTIONy = """
269
+ <p align="left">
270
+ <a title="Github" href="https://github.com/PRITHIVSAKTHIUR/Imagineo-4K" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
271
+ <img src="https://img.shields.io/github/stars/PRITHIVSAKTHIUR/Imagineo-4K?label=GitHub%20%E2%98%85&logo=github&color=C8C" alt="badge-github-stars">
272
+ </a>
273
+ </p>
274
+ """
275
+
276
+
277
+ if not torch.cuda.is_available():
278
+ DESCRIPTION += "\n<p>⚠️Running on CPU, This may not work on CPU.</p>"
279
+
280
+ MAX_SEED = np.iinfo(np.int32).max
281
+ CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
282
+ MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "2048"))
283
+ USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
284
+ ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
285
+
286
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
287
+ #Compile
288
+ if torch.cuda.is_available():
289
+ pipe = StableDiffusionXLPipeline.from_pretrained(
290
+ "SG161222/RealVisXL_V4.0_Lightning", #(or) use --- SG161222/RealVisXL_V4.0 / SG161222/RealVisXL_V4.0_Lightning --- for better results.
291
+ torch_dtype=torch.float16,
292
+ use_safetensors=True,
293
+ add_watermarker=False,
294
+ variant="fp16"
295
+ ).to(device)
296
+
297
+ if ENABLE_CPU_OFFLOAD:
298
+ pipe.enable_model_cpu_offload()
299
+ else:
300
+ pipe.to(device)
301
+ print("Loaded on Device!")
302
+
303
+ if USE_TORCH_COMPILE:
304
+ pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
305
+ print("Model Compiled!")
306
+
307
+ def save_image(img, path):
308
+ img.save(path)
309
+ #seeding
310
+ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
311
+ if randomize_seed:
312
+ seed = random.randint(0, MAX_SEED)
313
+ return seed
314
+
315
+ #Load the HTML content
316
+ #html_file_url = "https://prithivmlmods-hamster-static.static.hf.space/index.html"
317
+ #html_content = f'<iframe src="{html_file_url}" style="width:100%; height:180px; border:none;"></iframe>'
318
+ #html_file_url = "https://prithivmlmods-static-loading-theme.static.hf.space/index.html"
319
+ #html_file_url = ""
320
+ #html_content = f'<iframe src="{html_file_url}" style="width:100%; height:400px; border:none"></iframe>'
321
+
322
+
323
+ #js_func = """
324
+
325
+ #<script>
326
+ #(function() {
327
+ # const url = new URL(window.location);
328
+ # const currentTheme = url.searchParams.get('__theme');
329
+
330
+ # if (currentTheme !== 'dark') {
331
+ # url.searchParams.set('__theme', 'dark');
332
+ # history.pushState({}, '', url.href);
333
+ # applyDarkTheme();
334
+ # }
335
+ #})();
336
+
337
+ #function applyDarkTheme() {
338
+ # // Example: Apply dark theme styles to body or specific elements
339
+ # document.body.classList.add('dark-theme');
340
+ # // Additional logic as needed
341
+ #}
342
+ #</script>
343
+ #"""
344
+
345
+ @spaces.GPU(enable_queue=True)
346
+ def generate(
347
+ prompt: str,
348
+ negative_prompt: str = "",
349
+ use_negative_prompt: bool = False,
350
+ style: str = DEFAULT_STYLE_NAME,
351
+ collage_style: str = DEFAULT_COLLAGE_STYLE_NAME,
352
+ filter_name: str = DEFAULT_FILTER_NAME,
353
+ grid_size: str = "2x2",
354
+ seed: int = 0,
355
+ width: int = 1024,
356
+ height: int = 1024,
357
+ guidance_scale: float = 3,
358
+ randomize_seed: bool = False,
359
+ use_resolution_binning: bool = True,
360
+ progress=gr.Progress(track_tqdm=True),
361
+ ):
362
+ if check_text(prompt, negative_prompt):
363
+ raise ValueError("Prompt contains restricted words.")
364
+
365
+ if collage_style != "No Style":
366
+ prompt, negative_prompt = apply_style(collage_style, prompt, negative_prompt)
367
+ elif filter_name != "No Filter":
368
+ prompt, negative_prompt = apply_style(filter_name, prompt, negative_prompt)
369
+ else:
370
+ prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
371
+
372
+ seed = int(randomize_seed_fn(seed, randomize_seed))
373
+ generator = torch.Generator().manual_seed(seed)
374
+
375
+ if not use_negative_prompt:
376
+ negative_prompt = "" # type: ignore
377
+ negative_prompt += default_negative
378
+
379
+ grid_sizes = {
380
+ "2x1": (2, 1),
381
+ "1x2": (1, 2),
382
+ "2x2": (2, 2),
383
+ "2x3": (2, 3),
384
+ "3x2": (3, 2),
385
+ "1x1": (1, 1)
386
+ }
387
+
388
+ grid_size_x, grid_size_y = grid_sizes.get(grid_size, (2, 2))
389
+ num_images = grid_size_x * grid_size_y
390
+
391
+ options = {
392
+ "prompt": prompt,
393
+ "negative_prompt": negative_prompt,
394
+ "width": width,
395
+ "height": height,
396
+ "guidance_scale": guidance_scale,
397
+ "num_inference_steps": 20,
398
+ "generator": generator,
399
+ "num_images_per_prompt": num_images,
400
+ "use_resolution_binning": use_resolution_binning,
401
+ "output_type": "pil",
402
+ }
403
+
404
+ torch.cuda.empty_cache() # Clear GPU memory
405
+ images = pipe(**options).images
406
+
407
+ grid_img = Image.new('RGB', (width * grid_size_x, height * grid_size_y))
408
+
409
+ for i, img in enumerate(images[:num_images]):
410
+ grid_img.paste(img, (i % grid_size_x * width, i // grid_size_x * height))
411
+
412
+ unique_name = str(uuid.uuid4()) + ".png"
413
+ save_image(grid_img, unique_name)
414
+ return [unique_name], seed
415
+
416
+ def load_predefined_images1():
417
+ predefined_images1 = [
418
+ "Tones/1.png",
419
+ "Tones/2.png",
420
+ "Tones/3.png",
421
+ "Tones/4.png",
422
+ "Tones/5.png",
423
+ "Tones/6.png",
424
+ "Tones/7.png",
425
+ "Tones/8.png",
426
+ "Tones/9.png",
427
+ ]
428
+ return predefined_images1
429
+
430
+ def load_predefined_images():
431
+ predefined_images = [
432
+ "assets/11.png",
433
+ "assets/22.png",
434
+ "assets/33.png",
435
+ "assets/44.png",
436
+ "assets/55.png",
437
+ "assets/66.png",
438
+ "assets/77.png",
439
+ "assets/88.png",
440
+ "assets/99.png",
441
+ ]
442
+ return predefined_images
443
+
444
+ examples = [
445
+
446
+ "Chocolate dripping from a donut against a yellow background, in the style of brocore, hyper-realistic oil --ar 2:3 --q 2 --s 750 --v 5 --ar 2:3 --q 2 --s 750 --v 5",
447
+ "3d image, cute girl, in the style of Pixar --ar 1:2 --stylize 750, 4K resolution highlights, Sharp focus, octane render, ray tracing, Ultra-High-Definition, 8k, UHD, HDR, (Masterpiece:1.5), (best quality:1.5)",
448
+ "Cold coffee in a cup bokeh --ar 85:128 --v 6.0 --style raw5, 4K, Photo-Realistic",
449
+ "Food photography of a milk shake with flying strawberrys against a pink background, professionally studio shot with cinematic lighting. The image is in the style of a professional studio shot --ar 85:128 --v 6.0 --style raw"
450
+
451
+ ]
452
+
453
+ css = '''
454
+ .gradio-container{max-width: 600px !important}
455
+ h1{text-align:center}
456
+ '''
457
+
458
+ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
459
+ gr.Markdown(DESCRIPTION)
460
+ gr.DuplicateButton(
461
+ value="Duplicate Space for private use",
462
+ elem_id="duplicate-button",
463
+ visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
464
+ )
465
+ with gr.Group():
466
+ with gr.Row():
467
+ prompt = gr.Text(
468
+ label="Prompt",
469
+ show_label=False,
470
+ max_lines=1,
471
+ placeholder="Enter your prompt",
472
+ container=False,
473
+ )
474
+ run_button = gr.Button("Run")
475
+ result = gr.Gallery(label="Grid", columns=1, preview=True)
476
+
477
+
478
+ with gr.Row(visible=True):
479
+ grid_size_selection = gr.Dropdown(
480
+ choices=["2x1", "1x2", "2x2", "2x3", "3x2", "1x1"],
481
+ value="1x1",
482
+ label="Grid Size"
483
+ )
484
+
485
+ with gr.Row(visible=True):
486
+ filter_selection = gr.Radio(
487
+ show_label=True,
488
+ container=True,
489
+ interactive=True,
490
+ choices=FILTER_NAMES,
491
+ value=DEFAULT_FILTER_NAME,
492
+ label="Filter Type",
493
+ )
494
+
495
+ with gr.Row(visible=True):
496
+ collage_style_selection = gr.Radio(
497
+ show_label=True,
498
+ container=True,
499
+ interactive=True,
500
+ choices=COLLAGE_STYLE_NAMES,
501
+ value=DEFAULT_COLLAGE_STYLE_NAME,
502
+ label="Collage Template + Duotone Canvas",
503
+ )
504
+
505
+ with gr.Row(visible=True):
506
+ style_selection = gr.Radio(
507
+ show_label=True,
508
+ container=True,
509
+ interactive=True,
510
+ choices=STYLE_NAMES,
511
+ value=DEFAULT_STYLE_NAME,
512
+ label="Quality Style",
513
+ )
514
+
515
+ with gr.Accordion("Advanced options", open=False):
516
+ use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True, visible=True)
517
+ negative_prompt = gr.Text(
518
+ label="Negative prompt",
519
+ max_lines=1,
520
+ placeholder="Enter a negative prompt",
521
+ value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
522
+ visible=True,
523
+ )
524
+ with gr.Row():
525
+ num_inference_steps = gr.Slider(
526
+ label="Steps",
527
+ minimum=10,
528
+ maximum=30,
529
+ step=1,
530
+ value=15,
531
+ )
532
+ with gr.Row():
533
+ num_images_per_prompt = gr.Slider(
534
+ label="Images",
535
+ minimum=1,
536
+ maximum=5,
537
+ step=1,
538
+ value=2,
539
+ )
540
+ seed = gr.Slider(
541
+ label="Seed",
542
+ minimum=0,
543
+ maximum=MAX_SEED,
544
+ step=1,
545
+ value=0,
546
+ visible=True
547
+ )
548
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
549
+
550
+ with gr.Row(visible=True):
551
+ width = gr.Slider(
552
+ label="Width",
553
+ minimum=512,
554
+ maximum=2048,
555
+ step=8,
556
+ value=1024,
557
+ )
558
+ height = gr.Slider(
559
+ label="Height",
560
+ minimum=512,
561
+ maximum=2048,
562
+ step=8,
563
+ value=1024,
564
+ )
565
+
566
+ with gr.Row():
567
+ guidance_scale = gr.Slider(
568
+ label="Guidance Scale",
569
+ minimum=0.1,
570
+ maximum=20.0,
571
+ step=0.1,
572
+ value=6,
573
+ )
574
+
575
+ gr.Examples(
576
+ examples=examples,
577
+ inputs=prompt,
578
+ outputs=[result, seed],
579
+ fn=generate,
580
+ #cache_examples=True,
581
+ cache_examples=CACHE_EXAMPLES,
582
+ )
583
+
584
+ use_negative_prompt.change(
585
+ fn=lambda x: gr.update(visible=x),
586
+ inputs=use_negative_prompt,
587
+ outputs=negative_prompt,
588
+ api_name=False,
589
+ )
590
+
591
+ gr.on(
592
+ triggers=[
593
+ prompt.submit,
594
+ negative_prompt.submit,
595
+ run_button.click,
596
+ ],
597
+ fn=generate,
598
+ inputs=[
599
+ prompt,
600
+ negative_prompt,
601
+ use_negative_prompt,
602
+ style_selection,
603
+ collage_style_selection,
604
+ filter_selection,
605
+ grid_size_selection,
606
+ seed,
607
+ width,
608
+ height,
609
+ guidance_scale,
610
+ randomize_seed,
611
+ ],
612
+ outputs=[result, seed],
613
+ api_name="run",
614
+ )
615
+
616
+ gr.Markdown("### Duotone Canvas")
617
+ predefined_gallery = gr.Gallery(label="Duotone Canvas", columns=3, show_label=False, value=load_predefined_images1())
618
+
619
+ gr.Markdown("### Image Gallery")
620
+ predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())
621
+
622
+ gr.Markdown(DESCRIPTIONy)
623
+ gr.Markdown("**Disclaimer/Note:**")
624
+ gr.Markdown("This is the demo space for generating images using Stable Diffusion with grids, filters, templates, quality styles, and types. Try the sample prompts to generate higher quality images. Try the sample prompts for generating higher quality images.<a href='https://huggingface.co/kasper-boy' target='_blank'>Try prompts</a>.")
625
+ #gr.HTML(html_content)
626
+
627
+ if __name__ == "__main__":
628
+ demo.queue(max_size=40).launch()
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diffusers
2
+ torch
3
+ torchvision
4
+ pipeline
5
+ transformers
6
+ accelerate
7
+ safetensors
8
+ spaces
9
+ peft
10
+ gradio
11
+ pillow==10.4.0