Spaces:
Sleeping
Sleeping
Commit
ยท
34db193
1
Parent(s):
fbec511
CSS v2
Browse files
app.py
CHANGED
@@ -1,113 +1,414 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
}
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
.
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
"""
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
import uuid
|
6 |
+
import json
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import numpy as np
|
10 |
+
from PIL import Image
|
11 |
+
import spaces
|
12 |
+
import torch
|
13 |
+
from diffusers import DiffusionPipeline
|
14 |
+
from typing import Tuple
|
15 |
+
|
16 |
+
# Check for the Model Base..
|
17 |
+
|
18 |
+
bad_words = json.loads(os.getenv('BAD_WORDS', "[]"))
|
19 |
+
bad_words_negative = json.loads(os.getenv('BAD_WORDS_NEGATIVE', "[]"))
|
20 |
+
default_negative = os.getenv("default_negative","")
|
21 |
+
|
22 |
+
def check_text(prompt, negative=""):
|
23 |
+
for i in bad_words:
|
24 |
+
if i in prompt:
|
25 |
+
return True
|
26 |
+
for i in bad_words_negative:
|
27 |
+
if i in negative:
|
28 |
+
return True
|
29 |
+
return False
|
30 |
+
|
31 |
+
style_list = [
|
32 |
+
{
|
33 |
+
"name": "D&D Art",
|
34 |
+
"prompt": "dungeons & dragons style artwork {prompt}. d&d style, key visual, vibrant, studio anime, highly detailed",
|
35 |
+
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast"
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"name": "2560 x 1440",
|
39 |
+
"prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic, fantastical environments, epic scenery, rich textures",
|
40 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, sci-fi, modern cityscapes, deformed, ugly"
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"name": "Photo",
|
44 |
+
"prompt": "cinematic photo of {prompt}. 35mm photograph, fantasy style, atmospheric lighting, magical elements, bokeh, professional, 4k, highly detailed",
|
45 |
+
"negative_prompt": "modern day, sci-fi, minimalistic, noisy, blurry, overly dark, soft, deformed, low fantasy"
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"name": "Epic Battle",
|
49 |
+
"prompt": "dynamic dungeons & dragons artwork of {prompt}. epic battle scene, legendary heroes, fierce monsters, intense action, dramatic lighting, high-detail environment, magical effects, vibrant colors",
|
50 |
+
"negative_prompt": "peaceful, mundane, low energy, modern, sci-fi, simplistic, cartoonish, low contrast"
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"name": "Character Portrait",
|
54 |
+
"prompt": "dungeons & dragons character portrait of {prompt}. intricate details, expressive faces, heroic poses, rich textures, elaborate costumes, iconic weapons, fantasy aesthetic, studio-quality rendering",
|
55 |
+
"negative_prompt": "generic, overly stylized, blurry, simplistic, futuristic, deformed"
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"name": "Magical Realm",
|
59 |
+
"prompt": "mystical dungeons & dragons artwork of {prompt}. enchanted forests, glowing runes, floating islands, otherworldly landscapes, magical auras, vibrant fantasy colors, ultra-detailed",
|
60 |
+
"negative_prompt": "urban, dull, realistic, futuristic, lifeless, overly muted, minimalistic"
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"name": "Dark Fantasy",
|
64 |
+
"prompt": "dark and moody dungeons & dragons artwork of {prompt}. gothic ruins, shadowy figures, haunting atmospheres, grim villains, cursed relics, muted colors, intricate textures, sinister undertones",
|
65 |
+
"negative_prompt": "bright, cheerful, cartoonish, lighthearted, futuristic, deformed"
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"name": "Legendary Creatures",
|
69 |
+
"prompt": "dungeons & dragons artwork of legendary creatures {prompt}. awe-inspiring dragons, ferocious beasts, mythical monsters, intricate scales, detailed textures, dynamic poses, magical auras, cinematic quality",
|
70 |
+
"negative_prompt": "simplistic, dull, mundane creatures, low-detail, modern animals, cartoony"
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"name": "Ancient Ruins",
|
74 |
+
"prompt": "dungeons & dragons artwork of {prompt}. ancient temples, crumbling ruins, arcane symbols, epic scale, mystical atmosphere, grand designs, dramatic perspective, ultra-detailed",
|
75 |
+
"negative_prompt": "modern structures, low-detail, dull, untextured, non-fantasy elements, minimalistic"
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"name": "Spellcasting Scene",
|
79 |
+
"prompt": "dungeons & dragons artwork of {prompt}. dramatic spellcasting, glowing magic effects, dynamic poses, swirling energy, vibrant light contrasts, powerful sorcerers, rich fantasy aesthetic",
|
80 |
+
"negative_prompt": "low energy, non-magical, mundane, modern day, generic designs, dull colors"
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"name": "Tavern Life",
|
84 |
+
"prompt": "dungeons & dragons artwork of {prompt}. lively medieval tavern scene, detailed character interactions, warm firelight, wooden interiors, mugs of ale, bard performances, rich textures, inviting atmosphere",
|
85 |
+
"negative_prompt": "cold, empty, futuristic, lifeless, overly simplistic, boring"
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"name": "D&D Quest Art",
|
89 |
+
"prompt": "dungeons & dragons quest artwork of {prompt}. heroic adventurers, perilous journeys, hidden treasures, legendary quests, immersive fantasy landscapes, intricate details, atmospheric lighting, grand scale, narrative-driven composition",
|
90 |
+
"negative_prompt": "modern, futuristic, low-detail, overly abstract, mundane settings, simplistic, sci-fi, cartoony, lifeless, uninspired"
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"name": "D&D Anime Art",
|
94 |
+
"prompt": "dungeons & dragons anime-style artwork of {prompt}. stylized characters, vibrant colors, expressive designs, dynamic action poses, magical effects, intricate fantasy backgrounds, studio-quality anime detailing",
|
95 |
+
"negative_prompt": "photo-realistic, overly gritty, mundane, futuristic, overly dark, simplistic, deformed"
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"name": "D&D Map",
|
99 |
+
"prompt": "dungeons & dragons map artwork of {prompt}. intricate fantasy map, visible grid layout for gameplay guidance, ancient cartography style, labeled locations, landmarks, topographic textures, rich colors, immersive design",
|
100 |
+
"negative_prompt": "modern maps, bland, plain, low detail, futuristic, chaotic, inaccurate grids, unlabeled, minimalist"
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"name": "3D Model",
|
104 |
+
"prompt": "professional 3D model of {prompt}. stylized fantasy character, legendary creatures, intricate armor, magical weapons, dynamic poses, volumetric lighting, epic fantasy feel, octane render, highly detailed",
|
105 |
+
"negative_prompt": "low poly, blurry, noisy, simplistic, overly realistic, mundane objects, low effort"
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"name": "(No style)",
|
109 |
+
"prompt": "{prompt}",
|
110 |
+
"negative_prompt": "",
|
111 |
+
},
|
112 |
+
]
|
113 |
+
|
114 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
115 |
+
STYLE_NAMES = list(styles.keys())
|
116 |
+
DEFAULT_STYLE_NAME = "D&D Quest Art"
|
117 |
+
|
118 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
119 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
120 |
+
if not negative:
|
121 |
+
negative = ""
|
122 |
+
return p.replace("{prompt}", positive), n + negative
|
123 |
+
|
124 |
+
DESCRIPTION = """## ChatDnD.net Dungeons & Dragons Fantasy Creator
|
125 |
+
Forge your own epic adventures and legendary heroes. Generate custom artwork for characters, quests, and magical landscapes to bring your campaigns to life. Finetuned by <a href='https://chatdnd.net'>ChatDnD</a>. To support me, <a href='https://buymeacoffee.com/watchoutformike'>Buy me a coffee</a>
|
126 |
"""
|
127 |
|
128 |
+
if not torch.cuda.is_available():
|
129 |
+
DESCRIPTION += "\n<p>โ ๏ธRunning on CPU, This may not work on CPU.</p>"
|
130 |
+
|
131 |
+
MAX_SEED = np.iinfo(np.int32).max
|
132 |
+
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
133 |
+
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "2048"))
|
134 |
+
USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
|
135 |
+
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
136 |
+
|
137 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
138 |
+
|
139 |
+
NUM_IMAGES_PER_PROMPT = 1
|
140 |
+
|
141 |
+
if torch.cuda.is_available():
|
142 |
+
pipe = DiffusionPipeline.from_pretrained(
|
143 |
+
"SG161222/RealVisXL_V3.0_Turbo",
|
144 |
+
torch_dtype=torch.float16,
|
145 |
+
use_safetensors=True,
|
146 |
+
add_watermarker=False,
|
147 |
+
variant="fp16"
|
148 |
+
)
|
149 |
+
pipe2 = DiffusionPipeline.from_pretrained(
|
150 |
+
"SG161222/RealVisXL_V2.02_Turbo",
|
151 |
+
torch_dtype=torch.float16,
|
152 |
+
use_safetensors=True,
|
153 |
+
add_watermarker=False,
|
154 |
+
variant="fp16"
|
155 |
+
)
|
156 |
+
if ENABLE_CPU_OFFLOAD:
|
157 |
+
pipe.enable_model_cpu_offload()
|
158 |
+
pipe2.enable_model_cpu_offload()
|
159 |
+
else:
|
160 |
+
pipe.to(device)
|
161 |
+
pipe2.to(device)
|
162 |
+
print("Loaded on Device!")
|
163 |
+
|
164 |
+
if USE_TORCH_COMPILE:
|
165 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
166 |
+
pipe2.unet = torch.compile(pipe2.unet, mode="reduce-overhead", fullgraph=True)
|
167 |
+
print("Model Compiled!")
|
168 |
+
|
169 |
+
def save_image(img):
|
170 |
+
unique_name = str(uuid.uuid4()) + ".png"
|
171 |
+
img.save(unique_name)
|
172 |
+
return unique_name
|
173 |
+
|
174 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
175 |
+
if randomize_seed:
|
176 |
+
seed = random.randint(0, MAX_SEED)
|
177 |
+
return seed
|
178 |
+
|
179 |
+
@spaces.GPU(enable_queue=True)
|
180 |
+
def generate(
|
181 |
+
prompt: str,
|
182 |
+
negative_prompt: str = "",
|
183 |
+
use_negative_prompt: bool = False,
|
184 |
+
style: str = DEFAULT_STYLE_NAME,
|
185 |
+
seed: int = 0,
|
186 |
+
width: int = 1024,
|
187 |
+
height: int = 1024,
|
188 |
+
guidance_scale: float = 3,
|
189 |
+
randomize_seed: bool = False,
|
190 |
+
use_resolution_binning: bool = True,
|
191 |
+
progress=gr.Progress(track_tqdm=True),
|
192 |
+
):
|
193 |
+
if check_text(prompt, negative_prompt):
|
194 |
+
raise ValueError("Prompt contains restricted words.")
|
195 |
+
|
196 |
+
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
197 |
+
seed = int(randomize_seed_fn(seed, randomize_seed))
|
198 |
+
generator = torch.Generator().manual_seed(seed)
|
199 |
+
|
200 |
+
if not use_negative_prompt:
|
201 |
+
negative_prompt = "" # type: ignore
|
202 |
+
negative_prompt += default_negative
|
203 |
+
|
204 |
+
options = {
|
205 |
+
"prompt": prompt,
|
206 |
+
"negative_prompt": negative_prompt,
|
207 |
+
"width": width,
|
208 |
+
"height": height,
|
209 |
+
"guidance_scale": guidance_scale,
|
210 |
+
"num_inference_steps": 25,
|
211 |
+
"generator": generator,
|
212 |
+
"num_images_per_prompt": NUM_IMAGES_PER_PROMPT,
|
213 |
+
"use_resolution_binning": use_resolution_binning,
|
214 |
+
"output_type": "pil",
|
215 |
+
}
|
216 |
+
|
217 |
+
images = pipe(**options).images + pipe2(**options).images
|
218 |
+
|
219 |
+
image_paths = [save_image(img) for img in images]
|
220 |
+
return image_paths, seed
|
221 |
+
|
222 |
+
examples = [
|
223 |
+
"A grand Dungeons & Dragons quest scene: A heroic party of adventurers standing at the entrance of a towering, ancient stone castle covered in vines, under a sky lit by the fading orange hues of a setting sun. The characters include a fierce elven warrior in ornate armor, a wise wizard with a glowing staff, a stealthy halfling rogue with a bow, and a mighty dwarf cleric with a shining warhammer. In the background, a dark forest looms, and mist begins to rise from the ground. The ground around the castle is scattered with enchanted symbols and ancient runes. The atmosphere is tense and filled with magic, adventure, and mystery."
|
224 |
+
]
|
225 |
+
|
226 |
+
css = '''
|
227 |
+
body {
|
228 |
+
background-color: #231f20;
|
229 |
+
color: #f5f5f5;
|
230 |
+
font-family: 'Arial', sans-serif;
|
231 |
+
}
|
232 |
+
|
233 |
+
.gradio-container {
|
234 |
+
max-width: 900px !important; /* Increase width for a spacious layout */
|
235 |
+
background: linear-gradient(180deg, #1a2332 0%, #08141e 100%);
|
236 |
+
border-radius: 15px;
|
237 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
|
238 |
+
color: #d4e6f9;
|
239 |
+
font-family: 'Roboto', sans-serif;
|
240 |
+
padding: 20px;
|
241 |
+
}
|
242 |
+
|
243 |
+
h1, h2, h3 {
|
244 |
+
color: #f4a261;
|
245 |
+
font-family: 'Cinzel', serif; /* Give a medieval vibe */
|
246 |
+
text-align: center;
|
247 |
+
letter-spacing: 2px;
|
248 |
+
}
|
249 |
+
|
250 |
+
.gradio-slider {
|
251 |
+
background-color: #0f1d29;
|
252 |
+
border: 1px solid #3a506b;
|
253 |
+
color: #d4e6f9;
|
254 |
+
}
|
255 |
+
|
256 |
+
.gr-checkbox label {
|
257 |
+
color: #d4e6f9;
|
258 |
+
}
|
259 |
+
|
260 |
+
.gr-radio label {
|
261 |
+
color: #f4a261;
|
262 |
+
font-family: 'Cinzel', serif;
|
263 |
+
}
|
264 |
+
|
265 |
+
.gradio-button {
|
266 |
+
background: #f4a261;
|
267 |
+
color: #2a2a40;
|
268 |
+
border-radius: 8px;
|
269 |
+
box-shadow: 0 2px 10px rgba(244, 162, 97, 0.4);
|
270 |
+
font-weight: bold;
|
271 |
+
}
|
272 |
+
|
273 |
+
.gradio-button:hover {
|
274 |
+
background: #e76f51;
|
275 |
+
}
|
276 |
+
|
277 |
+
.gradio-gallery .label {
|
278 |
+
color: #f4a261;
|
279 |
+
font-family: 'Cinzel', serif;
|
280 |
+
font-size: 1.2rem;
|
281 |
+
}
|
282 |
+
|
283 |
+
.accordion-content {
|
284 |
+
background: #08141e;
|
285 |
+
border: 1px solid #3a506b;
|
286 |
+
padding: 15px;
|
287 |
+
}
|
288 |
+
|
289 |
+
.gr-row, .gr-column, .gr-group {
|
290 |
+
border-radius: 10px;
|
291 |
+
}
|
292 |
+
'''
|
293 |
+
|
294 |
+
with gr.Blocks(css=css) as demo:
|
295 |
+
gr.Markdown(f"""
|
296 |
+
# โ๏ธ Dungeons & Dragons Fantasy Generator โ๏ธ
|
297 |
+
**Unleash Your Imagination!** Create heroes, maps, quests, and epic scenes to bring your campaigns to life. Tailored for adventurers seeking inspiration or Dungeon Masters constructing their next grand story. <br>
|
298 |
+
[Visit Our Website](https://chatdnd.net) | [Support Us](https://buymeacoffee.com/watchoutformike)
|
299 |
+
*Roll for initiative and dive in!*
|
300 |
+
""")
|
301 |
+
with gr.Group():
|
302 |
+
with gr.Row():
|
303 |
+
prompt = gr.Text(
|
304 |
+
label="๐ฎ Your Prompt",
|
305 |
+
show_label=True,
|
306 |
+
max_lines=1,
|
307 |
+
placeholder="Describe your vision (e.g., 'Elven Archer battling a hydra')",
|
308 |
+
container=False,
|
309 |
+
)
|
310 |
+
run_button = gr.Button("Generate ๐จ")
|
311 |
+
result = gr.Gallery(label="Your Results", columns=2, preview=True)
|
312 |
+
with gr.Accordion("๐ Advanced Options", open=False):
|
313 |
+
use_negative_prompt = gr.Checkbox(label="๐ป Use Negative Prompt", value=True, visible=True)
|
314 |
+
negative_prompt = gr.Text(
|
315 |
+
label="Negative Prompt",
|
316 |
+
max_lines=2,
|
317 |
+
placeholder="Describe what to avoid (e.g., blurry, modern style)",
|
318 |
+
value="",
|
319 |
+
visible=True,
|
320 |
+
)
|
321 |
+
with gr.Row():
|
322 |
+
num_inference_steps = gr.Slider(
|
323 |
+
label="โ๏ธ Steps",
|
324 |
+
minimum=10,
|
325 |
+
maximum=60,
|
326 |
+
step=1,
|
327 |
+
value=30,
|
328 |
+
)
|
329 |
+
with gr.Row():
|
330 |
+
num_images_per_prompt = gr.Slider(
|
331 |
+
label="๐ผ๏ธ Images Per Prompt",
|
332 |
+
minimum=1,
|
333 |
+
maximum=4,
|
334 |
+
step=1,
|
335 |
+
value=2,
|
336 |
+
)
|
337 |
+
seed = gr.Slider(
|
338 |
+
label="๐ฒ Random Seed",
|
339 |
+
minimum=0,
|
340 |
+
maximum=10000,
|
341 |
+
step=1,
|
342 |
+
value=42,
|
343 |
+
visible=True
|
344 |
+
)
|
345 |
+
randomize_seed = gr.Checkbox(label="๐ Randomize Seed", value=True)
|
346 |
+
with gr.Row(visible=True):
|
347 |
+
width = gr.Slider(
|
348 |
+
label="Width (px)",
|
349 |
+
minimum=512,
|
350 |
+
maximum=2048,
|
351 |
+
step=8,
|
352 |
+
value=1024,
|
353 |
+
)
|
354 |
+
height = gr.Slider(
|
355 |
+
label="Height (px)",
|
356 |
+
minimum=512,
|
357 |
+
maximum=2048,
|
358 |
+
step=8,
|
359 |
+
value=1024,
|
360 |
+
)
|
361 |
+
with gr.Row():
|
362 |
+
guidance_scale = gr.Slider(
|
363 |
+
label="๐จ Guidance Scale",
|
364 |
+
minimum=1.0,
|
365 |
+
maximum=20.0,
|
366 |
+
step=0.5,
|
367 |
+
value=7.5,
|
368 |
+
)
|
369 |
+
with gr.Row(visible=True):
|
370 |
+
style_selection = gr.Radio(
|
371 |
+
label="๐ญ Select Your Style",
|
372 |
+
choices=STYLE_NAMES,
|
373 |
+
value=DEFAULT_STYLE_NAME,
|
374 |
+
container=True,
|
375 |
+
)
|
376 |
+
gr.Examples(
|
377 |
+
examples=examples,
|
378 |
+
inputs=prompt,
|
379 |
+
outputs=[result, seed],
|
380 |
+
fn=generate,
|
381 |
+
cache_examples=CACHE_EXAMPLES,
|
382 |
+
)
|
383 |
+
|
384 |
+
use_negative_prompt.change(
|
385 |
+
fn=lambda x: gr.update(visible=x),
|
386 |
+
inputs=use_negative_prompt,
|
387 |
+
outputs=negative_prompt,
|
388 |
+
api_name=False,
|
389 |
+
)
|
390 |
+
|
391 |
+
gr.on(
|
392 |
+
triggers=[
|
393 |
+
prompt.submit,
|
394 |
+
negative_prompt.submit,
|
395 |
+
run_button.click,
|
396 |
+
],
|
397 |
+
fn=generate,
|
398 |
+
inputs=[
|
399 |
+
prompt,
|
400 |
+
negative_prompt,
|
401 |
+
use_negative_prompt,
|
402 |
+
style_selection,
|
403 |
+
seed,
|
404 |
+
width,
|
405 |
+
height,
|
406 |
+
guidance_scale,
|
407 |
+
randomize_seed,
|
408 |
+
],
|
409 |
+
outputs=[result, seed],
|
410 |
+
api_name="run",
|
411 |
+
)
|
412 |
+
|
413 |
+
if __name__ == "__main__":
|
414 |
+
demo.queue(max_size=20).launch()
|