WatchOutForMike commited on
Commit
51c0dc0
·
1 Parent(s): 8e7fb44

D&D CSS Styles

Browse files
Files changed (1) hide show
  1. app.py +195 -63
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
 
4
  import torch
5
  from diffusers import DiffusionPipeline
6
 
7
  # Load the model
8
- dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
11
 
@@ -18,6 +19,177 @@ style_list = [
18
  {"name": "D&D Art", "prompt": "dungeons & dragons style artwork {prompt}. d&d style, key visual, vibrant, studio anime, highly detailed", "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast"},
19
  {"name": "Dark Fantasy", "prompt": "dark and moody dungeons & dragons artwork of {prompt}. gothic ruins, shadowy figures, haunting atmospheres, grim villains, muted colors, intricate textures, sinister undertones", "negative_prompt": "bright, cheerful, cartoonish, lighthearted, futuristic, deformed"},
20
  {"name": "Epic Battle", "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", "negative_prompt": "peaceful, mundane, low energy, modern, sci-fi, simplistic, cartoonish, low contrast"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  {"name": "(No style)", "prompt": "{prompt}", "negative_prompt": ""},
22
  ]
23
 
@@ -31,6 +203,7 @@ def apply_style(style_name: str, positive: str, negative: str = ""):
31
  return p.replace("{prompt}", positive), n + (negative or "")
32
 
33
  # Inference function
 
34
  def infer(
35
  prompt,
36
  style,
@@ -39,35 +212,24 @@ def infer(
39
  width=1024,
40
  height=1024,
41
  num_inference_steps=4,
42
- batch_size=1,
43
- positive_override=None,
44
- negative_override=None,
45
  progress=gr.Progress(track_tqdm=True),
46
  ):
47
  if randomize_seed:
48
  seed = random.randint(0, MAX_SEED)
49
-
50
- images = []
51
- for _ in range(batch_size):
52
- # Apply custom styles if specified
53
- if positive_override and negative_override:
54
- styled_prompt = positive_override.replace("{prompt}", prompt)
55
- negative_prompt = negative_override
56
- else:
57
- styled_prompt, negative_prompt = apply_style(style, prompt)
58
-
59
- generator = torch.manual_seed(seed)
60
- image = pipe(
61
- prompt=styled_prompt,
62
- width=width,
63
- height=height,
64
- num_inference_steps=num_inference_steps,
65
- generator=generator,
66
- guidance_scale=0.0,
67
- negative_prompt=negative_prompt,
68
- ).images[0]
69
- images.append(image)
70
- return images, seed
71
 
72
  # Example prompts
73
  examples = [
@@ -76,14 +238,6 @@ examples = [
76
  ["A ferocious dragon breathing fire in a dark cavern", "Epic Battle"],
77
  ]
78
 
79
- # Predefined previews for styles
80
- style_previews = {
81
- "D&D Art": "https://example.com/dnd_preview.png",
82
- "Dark Fantasy": "https://example.com/dark_fantasy_preview.png",
83
- "Epic Battle": "https://example.com/epic_battle_preview.png",
84
- "(No style)": "https://example.com/no_style_preview.png",
85
- }
86
-
87
  # Custom CSS for a Dungeons & Dragons theme
88
  css = """
89
  body {
@@ -117,11 +271,6 @@ with gr.Blocks(css=css) as demo:
117
  """
118
  )
119
 
120
- # Style previews
121
- with gr.Row():
122
- for name, url in style_previews.items():
123
- gr.Image(value=url, label=name)
124
-
125
  # Prompt input and style selector
126
  with gr.Row():
127
  prompt = gr.Textbox(
@@ -135,21 +284,10 @@ with gr.Blocks(css=css) as demo:
135
  value=DEFAULT_STYLE_NAME,
136
  )
137
 
138
- # Custom style builder
139
- with gr.Accordion("🛠️ Custom Style Builder", open=False):
140
- positive_override = gr.Textbox(
141
- label="Custom Positive Prompt",
142
- placeholder="Enter custom positive prompt. Use '{prompt}' as a placeholder for the main description."
143
- )
144
- negative_override = gr.Textbox(
145
- label="Custom Negative Prompt",
146
- placeholder="Enter custom negative prompt for exclusion criteria."
147
- )
148
-
149
  # Run button and result display
150
  with gr.Row():
151
  run_button = gr.Button("Generate Image")
152
- results = gr.Gallery(label="🖼️ Generated Images")
153
 
154
  # Advanced settings
155
  with gr.Accordion("⚙️ Advanced Settings", open=False):
@@ -185,29 +323,23 @@ with gr.Blocks(css=css) as demo:
185
  step=1,
186
  value=4,
187
  )
188
- batch_size = gr.Slider(
189
- label="Batch Size",
190
- minimum=1,
191
- maximum=10,
192
- step=1,
193
- value=1,
194
- )
195
 
196
  # Examples with styles
197
  gr.Examples(
198
  examples=examples,
199
  inputs=[prompt, style],
200
- outputs=[results],
201
  fn=infer,
202
  cache_examples="lazy",
203
  )
204
 
205
  # Interactivity
206
- run_button.click(
 
207
  fn=infer,
208
- inputs=[prompt, style, seed, randomize_seed, width, height, num_inference_steps, batch_size, positive_override, negative_override],
209
- outputs=[results, seed],
210
  )
211
 
212
  # Launch the demo
213
- demo.launch()
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ import spaces
5
  import torch
6
  from diffusers import DiffusionPipeline
7
 
8
  # Load the model
9
+ dtype = torch.bfloat16
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
12
 
 
19
  {"name": "D&D Art", "prompt": "dungeons & dragons style artwork {prompt}. d&d style, key visual, vibrant, studio anime, highly detailed", "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast"},
20
  {"name": "Dark Fantasy", "prompt": "dark and moody dungeons & dragons artwork of {prompt}. gothic ruins, shadowy figures, haunting atmospheres, grim villains, muted colors, intricate textures, sinister undertones", "negative_prompt": "bright, cheerful, cartoonish, lighthearted, futuristic, deformed"},
21
  {"name": "Epic Battle", "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", "negative_prompt": "peaceful, mundane, low energy, modern, sci-fi, simplistic, cartoonish, low contrast"},
22
+ # Add additional styles as needed
23
+ { "name": "Character Portrait",
24
+ "prompt": "dungeons & dragons character portrait of {prompt}. intricate details, expressive faces, heroic poses, rich textures, elaborate costumes, iconic weapons, fantasy aesthetic, studio-quality rendering",
25
+ "negative_prompt": "generic, overly stylized, blurry, simplistic, futuristic, deformed"
26
+ },
27
+ {
28
+ "name": "Magical Realm",
29
+ "prompt": "mystical dungeons & dragons artwork of {prompt}. enchanted forests, glowing runes, floating islands, otherworldly landscapes, magical auras, vibrant fantasy colors, ultra-detailed",
30
+ "negative_prompt": "urban, dull, realistic, futuristic, lifeless, overly muted, minimalistic"
31
+ },
32
+ {
33
+ "name": "Legendary Creatures",
34
+ "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",
35
+ "negative_prompt": "simplistic, dull, mundane creatures, low-detail, modern animals, cartoony"
36
+ },
37
+
38
+ {
39
+ "name": "Ancient Ruins",
40
+ "prompt": "dungeons & dragons artwork of {prompt}. ancient temples, crumbling ruins, arcane symbols, epic scale, mystical atmosphere, grand designs, dramatic perspective, ultra-detailed",
41
+ "negative_prompt": "modern structures, low-detail, dull, untextured, non-fantasy elements, minimalistic"
42
+ },
43
+
44
+ {
45
+ "name": "Spellcasting Scene",
46
+ "prompt": "dungeons & dragons artwork of {prompt}. dramatic spellcasting, glowing magic effects, dynamic poses, swirling energy, vibrant light contrasts, powerful sorcerers, rich fantasy aesthetic",
47
+ "negative_prompt": "low energy, non-magical, mundane, modern day, generic designs, dull colors"
48
+ },
49
+
50
+ {
51
+ "name": "Tavern Life",
52
+ "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",
53
+ "negative_prompt": "cold, empty, futuristic, lifeless, overly simplistic, boring"
54
+ },
55
+
56
+ {
57
+ "name": "D&D Quest Art",
58
+ "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",
59
+ "negative_prompt": "modern, futuristic, low-detail, overly abstract, mundane settings, simplistic, sci-fi, cartoony, lifeless, uninspired"
60
+ },
61
+
62
+ {
63
+ "name": "D&D Anime Art",
64
+ "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",
65
+ "negative_prompt": "photo-realistic, overly gritty, mundane, futuristic, overly dark, simplistic, deformed"
66
+ },
67
+
68
+ {
69
+ "name": "D&D Map",
70
+ "prompt": "dungeons & dragons map artwork of {prompt}. intricate fantasy map, visable grid layout for gameplay guidance, ancient cartography style, labeled locations, landmarks, topographic textures, rich colors, immersive design",
71
+ "negative_prompt": "modern maps, bland, plain, low detail, futuristic, chaotic, inaccurate grids, unlabeled, minimalist"
72
+ },
73
+ {
74
+ "name": "Arcane Duel",
75
+ "prompt": "dungeons & dragons artwork of {prompt}. two powerful sorcerers battling with swirling magical energy, dramatic lighting, glowing spell effects, mystical atmosphere, ultra-detailed fantasy elements",
76
+ "negative_prompt": "calm, peaceful, dull colors, modern setting, non-fantasy, low-detail"
77
+ },
78
+ {
79
+ "name": "Treasure Hoard",
80
+ "prompt": "dungeons & dragons artwork of {prompt}. a cavern filled with glittering gold coins, ancient relics, glowing gemstones, treasure chests, detailed textures, vibrant fantasy lighting",
81
+ "negative_prompt": "empty, dull, modern day, futuristic, sci-fi, bland atmosphere"
82
+ },
83
+ {
84
+ "name": "Underdark",
85
+ "prompt": "dark and moody dungeons & dragons artwork of {prompt}. sprawling underground caverns, glowing fungi, shadowy creatures, bioluminescent details, ominous tones, intricate fantasy detailing",
86
+ "negative_prompt": "bright and sunny, surface world, futuristic, sci-fi, minimal detail, lifeless"
87
+ },
88
+ {
89
+ "name": "Celestial Realm",
90
+ "prompt": "dungeons & dragons artwork of {prompt}. divine celestial realms, golden light, angelic beings, floating clouds, radiant auras, epic divine architecture, detailed textures",
91
+ "negative_prompt": "dark, demonic, mundane, low-detail, futuristic, simplistic"
92
+ },
93
+ {
94
+ "name": "D&D Heist Scene",
95
+ "prompt": "dungeons & dragons artwork of {prompt}. a group of adventurers sneaking into a heavily guarded treasure vault, dramatic lighting, intricate lock mechanisms, tense atmosphere, ultra-detailed environment",
96
+ "negative_prompt": "carefree, bland setting, modern day, low-detail, simplistic designs, deformed"
97
+ },
98
+ {
99
+ "name": "Enchanted Forest",
100
+ "prompt": "dungeons & dragons artwork of {prompt}. magical forest with glowing flora, towering ancient trees, mystical wildlife, detailed textures, serene but vibrant fantasy tones",
101
+ "negative_prompt": "modern city, mundane, lifeless, futuristic, abstract designs, overly simplistic"
102
+ },
103
+ {
104
+ "name": "Battle at the Gates",
105
+ "prompt": "dungeons & dragons artwork of {prompt}. an epic battle unfolding at massive fortress gates, heavily armored soldiers, dramatic clashes, powerful war machines, intense action, atmospheric lighting",
106
+ "negative_prompt": "peaceful, bland, empty fields, low energy, futuristic, deformed, overly simplistic"
107
+ },
108
+ {
109
+ "name": "Stormy Seas",
110
+ "prompt": "dungeons & dragons artwork of {prompt}. a ship caught in a raging storm, enormous waves, dark clouds, flashes of lightning, detailed ocean textures, dynamic lighting",
111
+ "negative_prompt": "calm water, lifeless, plain scenery, futuristic, minimalist, abstract"
112
+ },
113
+ {
114
+ "name": "Desert Wasteland",
115
+ "prompt": "dungeons & dragons artwork of {prompt}. endless desert landscapes, ruins of ancient civilizations, glowing sun on the horizon, swirling sands, intricate details, mystical atmosphere",
116
+ "negative_prompt": "lush forests, futuristic, cityscapes, low-detail, lifeless"
117
+ },
118
+ {
119
+ "name": "Dwarven Forge",
120
+ "prompt": "dungeons & dragons artwork of {prompt}. a massive underground forge with molten lava streams, glowing furnaces, dwarf blacksmiths, intricate metalworks, rugged and vibrant tones",
121
+ "negative_prompt": "modern machinery, minimalistic, clean, futuristic, deformed"
122
+ },
123
+ {
124
+ "name": "Ethereal Spires",
125
+ "prompt": "dungeons & dragons artwork of {prompt}. floating crystalline towers above the clouds, glowing lights, otherworldly designs, vibrant celestial colors, ultra-detailed mystical atmosphere",
126
+ "negative_prompt": "mundane, low-detail, dark and grim, simplistic, lifeless"
127
+ },
128
+ {
129
+ "name": "Feywild Meadow",
130
+ "prompt": "dungeons & dragons artwork of {prompt}. a surreal and magical meadow filled with sparkling lights, dancing fey creatures, vibrant blooming flowers, whimsical details, fantasy colors",
131
+ "negative_prompt": "plain forest, dark and brooding, lifeless, realistic, dull tones"
132
+ },
133
+ {
134
+ "name": "Dungeon Crawl",
135
+ "prompt": "dungeons & dragons artwork of {prompt}. adventurers exploring a dark dungeon with traps, treasure chests, cobwebbed corners, torch-lit corridors, richly detailed stone textures",
136
+ "negative_prompt": "bright outdoor scenes, futuristic, modern, low detail"
137
+ },
138
+ {
139
+ "name": "Frosted Peaks",
140
+ "prompt": "dungeons & dragons artwork of {prompt}. icy mountaintops, adventurers climbing through harsh snowstorms, frozen castles, glowing icy runes, cold tones with vivid details",
141
+ "negative_prompt": "warm beaches, futuristic, cartoony, deformed, dull colors"
142
+ },
143
+ {
144
+ "name": "Cyberpunk Cityscape",
145
+ "prompt": "futuristic cyberpunk artwork of {prompt}. neon-lit streets, towering skyscrapers, flying vehicles, cybernetic details, vibrant colors, cinematic atmosphere, ultra-detailed",
146
+ "negative_prompt": "fantasy, medieval, dull colors, empty city, overly simplistic, bland"
147
+ },
148
+ {
149
+ "name": "Steampunk World",
150
+ "prompt": "steampunk-style artwork of {prompt}. intricate clockwork mechanisms, steam-powered inventions, Victorian-inspired characters, vibrant but rustic tones, rich textures, detailed environments",
151
+ "negative_prompt": "futuristic, sleek designs, dull, modern cityscapes, simplistic, minimalistic"
152
+ },
153
+ {
154
+ "name": "Wild West Scene",
155
+ "prompt": "cinematic wild west-style artwork of {prompt}. vast desert landscapes, rugged cowboys, wooden saloons, vintage rifles, atmospheric lighting, detailed textures",
156
+ "negative_prompt": "modern vehicles, futuristic elements, overly vibrant, simplistic, low energy"
157
+ },
158
+ {
159
+ "name": "Mythological Greece",
160
+ "prompt": "mythological artwork of {prompt}. ancient Greek gods and heroes, marble temples, epic battles, radiant divine light, ultra-detailed settings, rich classical tones",
161
+ "negative_prompt": "sci-fi, modern city, low-detail, lifeless atmosphere, generic textures"
162
+ },
163
+ {
164
+ "name": "Sci-Fi Space Adventure",
165
+ "prompt": "sci-fi style artwork of {prompt}. massive starships, alien planets, swirling galaxies, futuristic cities, neon highlights, ultra-detailed space themes",
166
+ "negative_prompt": "fantasy elements, medieval setting, dull or muted tones, overly simple designs"
167
+ },
168
+ {
169
+ "name": "Retro Pixel Art",
170
+ "prompt": "8-bit retro-style pixel art of {prompt}. classic video game aesthetics, vibrant and bold pixel colors, stylized backgrounds, clean and defined sprites",
171
+ "negative_prompt": "realistic textures, photorealistic, overly smooth, detailed textures"
172
+ },
173
+ {
174
+ "name": "Pop Art Aesthetic",
175
+ "prompt": "vivid pop art illustration of {prompt}. bold colors, high contrast, retro style, comic book-like details, playful and energetic compositions",
176
+ "negative_prompt": "realism, dull tones, blurred effects, abstract"
177
+ },
178
+ {
179
+ "name": "Noir Detective",
180
+ "prompt": "cinematic noir-style artwork of {prompt}. black and white aesthetics, shadowy figures, fog-filled streets, dramatic lighting, vintage details, atmospheric tension",
181
+ "negative_prompt": "colorful, futuristic, mundane, cheerful, low-detail"
182
+ },
183
+ {
184
+ "name": "Studio Ghibli-Inspired Fantasy",
185
+ "prompt": "anime-style artwork inspired by Studio Ghibli of {prompt}. magical landscapes, intricate details, vibrant colors, fantastical creatures, peaceful yet surreal atmosphere",
186
+ "negative_prompt": "dark and brooding, sci-fi, plain, minimalist, harsh contrasts"
187
+ },
188
+ {
189
+ "name": "Art Deco City",
190
+ "prompt": "art deco-inspired cityscape of {prompt}. geometric designs, golden accents, intricate and modern architecture, glowing lights, detailed and luxurious atmosphere",
191
+ "negative_prompt": "medieval settings, fantasy, low-detail, dull textures, minimalism"
192
+ },
193
  {"name": "(No style)", "prompt": "{prompt}", "negative_prompt": ""},
194
  ]
195
 
 
203
  return p.replace("{prompt}", positive), n + (negative or "")
204
 
205
  # Inference function
206
+ @spaces.GPU()
207
  def infer(
208
  prompt,
209
  style,
 
212
  width=1024,
213
  height=1024,
214
  num_inference_steps=4,
 
 
 
215
  progress=gr.Progress(track_tqdm=True),
216
  ):
217
  if randomize_seed:
218
  seed = random.randint(0, MAX_SEED)
219
+
220
+ # Apply style to prompt
221
+ styled_prompt, negative_prompt = apply_style(style, prompt)
222
+ generator = torch.Generator().manual_seed(seed)
223
+ image = pipe(
224
+ prompt=styled_prompt,
225
+ width=width,
226
+ height=height,
227
+ num_inference_steps=num_inference_steps,
228
+ generator=generator,
229
+ guidance_scale=0.0,
230
+ negative_prompt=negative_prompt,
231
+ ).images[0]
232
+ return image, seed
 
 
 
 
 
 
 
 
233
 
234
  # Example prompts
235
  examples = [
 
238
  ["A ferocious dragon breathing fire in a dark cavern", "Epic Battle"],
239
  ]
240
 
 
 
 
 
 
 
 
 
241
  # Custom CSS for a Dungeons & Dragons theme
242
  css = """
243
  body {
 
271
  """
272
  )
273
 
 
 
 
 
 
274
  # Prompt input and style selector
275
  with gr.Row():
276
  prompt = gr.Textbox(
 
284
  value=DEFAULT_STYLE_NAME,
285
  )
286
 
 
 
 
 
 
 
 
 
 
 
 
287
  # Run button and result display
288
  with gr.Row():
289
  run_button = gr.Button("Generate Image")
290
+ result = gr.Image(label="🖼️ Your Legendary Vision")
291
 
292
  # Advanced settings
293
  with gr.Accordion("⚙️ Advanced Settings", open=False):
 
323
  step=1,
324
  value=4,
325
  )
 
 
 
 
 
 
 
326
 
327
  # Examples with styles
328
  gr.Examples(
329
  examples=examples,
330
  inputs=[prompt, style],
331
+ outputs=[result],
332
  fn=infer,
333
  cache_examples="lazy",
334
  )
335
 
336
  # Interactivity
337
+ gr.on(
338
+ triggers=[run_button.click, prompt.submit],
339
  fn=infer,
340
+ inputs=[prompt, style, seed, randomize_seed, width, height, num_inference_steps],
341
+ outputs=[result, seed],
342
  )
343
 
344
  # Launch the demo
345
+ demo.launch()