SpaceMonkey8-cloud commited on
Commit
8796918
ยท
1 Parent(s): 2b27000

Initial commit: Game Character Generator with DreamShaper 8

Browse files
Files changed (4) hide show
  1. .gitignore +11 -0
  2. README.md +4 -6
  3. app.py +345 -0
  4. requirements.txt +10 -0
.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.so
4
+ .Python
5
+ *.egg-info/
6
+ flagged/
7
+ gradio_cached_examples/
8
+ .DS_Store
9
+ *.png
10
+ *.jpg
11
+ *.jpeg
README.md CHANGED
@@ -1,13 +1,11 @@
1
  ---
2
  title: Game Character Generator
3
- emoji: ๐Ÿ”ฅ
4
- colorFrom: blue
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Game Character Generator
3
+ emoji: ๐ŸŽฎ
4
+ colorFrom: purple
5
+ colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 4.19.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
 
 
app.py ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cat > app.py << 'ENDOFFILE'
2
+ """
3
+ Game Character Generator
4
+ Generate characters for video games in multiple styles
5
+ """
6
+
7
+ import gradio as gr
8
+ import torch
9
+ from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
10
+ import random
11
+
12
+ print("๐ŸŽฎ Loading Game Character Generator...")
13
+
14
+ # Modello ottimizzato per character design
15
+ MODEL_ID = "Lykon/dreamshaper-8"
16
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
17
+
18
+ pipe = StableDiffusionPipeline.from_pretrained(
19
+ MODEL_ID,
20
+ torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32,
21
+ safety_checker=None,
22
+ )
23
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
24
+ pipe.to(DEVICE)
25
+
26
+ if DEVICE == "cuda":
27
+ pipe.enable_model_cpu_offload()
28
+ pipe.enable_vae_slicing()
29
+
30
+ print(f"โœ… Model loaded on {DEVICE}")
31
+
32
+ # Preset per diversi stili di gioco
33
+ GAME_STYLES = {
34
+ "RPG Fantasy": "fantasy rpg character, detailed armor, character sheet, concept art, white background",
35
+ "Anime JRPG": "anime style character, vibrant colors, jrpg aesthetic, character design, official art",
36
+ "Pixel Art Retro": "pixel art character sprite, 16-bit style, retro game, clean pixel art",
37
+ "3D Realistic": "3d character render, realistic, game character, unreal engine, highly detailed",
38
+ "Cartoon Mobile": "cute cartoon character, mobile game style, colorful, simple design",
39
+ "Dark Souls": "dark fantasy character, souls-like, detailed armor, dramatic lighting",
40
+ "Cyberpunk": "cyberpunk character, neon lights, futuristic, sci-fi game character",
41
+ "Platformer": "platformer game character, mascot, fun design, action pose"
42
+ }
43
+
44
+ NEGATIVE_BASE = "blurry, low quality, distorted, ugly, bad anatomy, extra limbs, text, watermark, signature"
45
+
46
+ def generate_character(
47
+ character_description,
48
+ game_style,
49
+ character_type,
50
+ custom_prompt="",
51
+ width=512,
52
+ height=768,
53
+ steps=30,
54
+ guidance=7.5,
55
+ seed=-1,
56
+ progress=gr.Progress()
57
+ ):
58
+ """Genera un personaggio da videogioco"""
59
+
60
+ if not character_description or len(character_description.strip()) == 0:
61
+ return None, "โŒ Please describe your character!"
62
+
63
+ try:
64
+ progress(0, desc="๐ŸŽจ Preparing...")
65
+
66
+ # Costruisci prompt completo
67
+ style_suffix = GAME_STYLES.get(game_style, "")
68
+
69
+ full_prompt = f"{character_description}, {character_type}, {style_suffix}"
70
+ if custom_prompt:
71
+ full_prompt += f", {custom_prompt}"
72
+
73
+ negative = NEGATIVE_BASE
74
+
75
+ if seed == -1:
76
+ seed = random.randint(0, 999999)
77
+
78
+ generator = torch.Generator(DEVICE).manual_seed(seed)
79
+
80
+ print(f"๐ŸŽจ Generating: {full_prompt[:80]}...")
81
+
82
+ progress(0.3, desc="๐Ÿ–ผ๏ธ Generating character...")
83
+
84
+ result = pipe(
85
+ prompt=full_prompt,
86
+ negative_prompt=negative,
87
+ num_inference_steps=steps,
88
+ guidance_scale=guidance,
89
+ width=width,
90
+ height=height,
91
+ generator=generator,
92
+ )
93
+
94
+ progress(1.0, desc="โœ… Complete!")
95
+
96
+ info = f"""
97
+ โœ… **Character Generated Successfully!**
98
+
99
+ ๐Ÿ“Š **Details:**
100
+ - **Style:** {game_style}
101
+ - **Type:** {character_type}
102
+ - **Seed:** {seed}
103
+ - **Resolution:** {width}x{height}
104
+ - **Steps:** {steps}
105
+
106
+ ๐Ÿ“ **Prompt Used:**
107
+ {full_prompt}
108
+
109
+ ๐Ÿ’ก **Tip:** Save the seed to recreate similar characters!
110
+ """
111
+
112
+ return result.images[0], info
113
+
114
+ except Exception as e:
115
+ error_msg = f"""
116
+ โŒ **Generation Failed**
117
+
118
+ **Error:** {str(e)}
119
+
120
+ ๐Ÿ’ก **Try:**
121
+ - Simplify the description
122
+ - Reduce image size
123
+ - Lower quality steps
124
+ """
125
+ print(f"Error: {e}")
126
+ return None, error_msg
127
+
128
+
129
+ # Character type presets
130
+ CHARACTER_TYPES = [
131
+ "full body character",
132
+ "character portrait",
133
+ "character turnaround",
134
+ "action pose",
135
+ "idle stance",
136
+ "character sheet",
137
+ "battle stance"
138
+ ]
139
+
140
+ # UI Gradio
141
+ with gr.Blocks(
142
+ title="๐ŸŽฎ Game Character Generator",
143
+ theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink")
144
+ ) as demo:
145
+
146
+ gr.Markdown("""
147
+ # ๐ŸŽฎ Game Character Generator
148
+ ### Create Professional Characters for Your Video Game
149
+
150
+ Generate high-quality character designs for RPGs, platformers, mobile games, and more!
151
+ Powered by **DreamShaper 8** - optimized for game character creation.
152
+ """)
153
+
154
+ with gr.Row():
155
+ # Left column - Input
156
+ with gr.Column(scale=1):
157
+ gr.Markdown("### ๐ŸŽจ Character Design")
158
+
159
+ character_desc = gr.Textbox(
160
+ label="๐Ÿ’ฌ Character Description",
161
+ placeholder="Example: female warrior with red hair and golden armor",
162
+ lines=3,
163
+ value="knight with silver armor"
164
+ )
165
+
166
+ game_style = gr.Dropdown(
167
+ choices=list(GAME_STYLES.keys()),
168
+ value="RPG Fantasy",
169
+ label="๐ŸŽฎ Game Style"
170
+ )
171
+
172
+ character_type = gr.Dropdown(
173
+ choices=CHARACTER_TYPES,
174
+ value="full body character",
175
+ label="๐Ÿ“ Character View"
176
+ )
177
+
178
+ custom_prompt = gr.Textbox(
179
+ label="โœจ Additional Details (optional)",
180
+ placeholder="Example: holding magic sword, blue cape, heroic",
181
+ lines=2
182
+ )
183
+
184
+ with gr.Accordion("โš™๏ธ Advanced Settings", open=False):
185
+ with gr.Row():
186
+ width = gr.Slider(256, 768, 512, step=64, label="Width")
187
+ height = gr.Slider(256, 1024, 768, step=64, label="Height")
188
+
189
+ steps = gr.Slider(15, 50, 30, step=5, label="Quality Steps")
190
+ guidance = gr.Slider(5, 15, 7.5, step=0.5, label="Guidance")
191
+ seed = gr.Number(value=-1, label="Seed (-1 = random)")
192
+
193
+ generate_btn = gr.Button(
194
+ "๐ŸŽจ Generate Character",
195
+ variant="primary",
196
+ size="lg"
197
+ )
198
+
199
+ gr.Markdown("""
200
+ ### ๐Ÿ’ก Tips for Best Results
201
+
202
+ โœ… **Do:**
203
+ - Be specific: "elf archer" not "character"
204
+ - Mention colors, clothing, weapons
205
+ - Try different game styles
206
+ - Use portrait for faces
207
+
208
+ โŒ **Avoid:**
209
+ - Vague descriptions
210
+ - Too many details in one prompt
211
+ - Multiple characters in one image
212
+ """)
213
+
214
+ # Right column - Output
215
+ with gr.Column(scale=1):
216
+ output_image = gr.Image(
217
+ label="๐ŸŽฎ Generated Character",
218
+ height=600
219
+ )
220
+ output_info = gr.Markdown(
221
+ "๐Ÿ‘† Describe your character and click Generate!"
222
+ )
223
+
224
+ # Examples
225
+ gr.Markdown("### ๐ŸŽจ Example Characters - Click to Try")
226
+
227
+ gr.Examples(
228
+ examples=[
229
+ [
230
+ "knight with silver armor and red cape",
231
+ "RPG Fantasy",
232
+ "full body character",
233
+ "holding sword, heroic pose",
234
+ 512, 768, 30, 7.5, 42
235
+ ],
236
+ [
237
+ "cute anime girl with twin tails and pink hair",
238
+ "Anime JRPG",
239
+ "character portrait",
240
+ "school uniform, smiling, cheerful",
241
+ 512, 512, 30, 8.0, 123
242
+ ],
243
+ [
244
+ "cyberpunk hacker with neon visor",
245
+ "Cyberpunk",
246
+ "full body character",
247
+ "tech gear, standing pose, glowing",
248
+ 512, 768, 30, 7.5, 456
249
+ ],
250
+ [
251
+ "dwarf warrior with battle axe",
252
+ "RPG Fantasy",
253
+ "full body character",
254
+ "red beard, heavy armor, tough",
255
+ 512, 768, 30, 7.5, 789
256
+ ],
257
+ [
258
+ "space marine in power armor",
259
+ "3D Realistic",
260
+ "full body character",
261
+ "futuristic, detailed, epic",
262
+ 512, 768, 35, 7.5, 999
263
+ ],
264
+ ],
265
+ inputs=[
266
+ character_desc,
267
+ game_style,
268
+ character_type,
269
+ custom_prompt,
270
+ width,
271
+ height,
272
+ steps,
273
+ guidance,
274
+ seed
275
+ ],
276
+ outputs=[output_image, output_info],
277
+ fn=generate_character,
278
+ cache_examples=False
279
+ )
280
+
281
+ # Event handler
282
+ generate_btn.click(
283
+ fn=generate_character,
284
+ inputs=[
285
+ character_desc,
286
+ game_style,
287
+ character_type,
288
+ custom_prompt,
289
+ width,
290
+ height,
291
+ steps,
292
+ guidance,
293
+ seed
294
+ ],
295
+ outputs=[output_image, output_info]
296
+ )
297
+
298
+ # Footer
299
+ gr.Markdown("""
300
+ ---
301
+ ### ๐ŸŽฎ Game Style Guide
302
+
303
+ | Style | Best For | Description |
304
+ |-------|----------|-------------|
305
+ | **RPG Fantasy** | D&D, Medieval | Classic fantasy with armor and weapons |
306
+ | **Anime JRPG** | Japanese RPG | Colorful anime aesthetic, vibrant |
307
+ | **Pixel Art Retro** | Indie Games | 8-bit/16-bit nostalgic style |
308
+ | **3D Realistic** | AAA Games | Photorealistic, detailed renders |
309
+ | **Cartoon Mobile** | Casual Games | Cute, simple, friendly characters |
310
+ | **Dark Souls** | Action RPG | Gothic, dark fantasy, dramatic |
311
+ | **Cyberpunk** | Sci-Fi | Neon, futuristic, high-tech |
312
+ | **Platformer** | Action Games | Mascot-style, fun and dynamic |
313
+
314
+ ### ๐Ÿ“ Character View Types
315
+
316
+ - **Full Body**: Complete character from head to toe
317
+ - **Portrait**: Face and shoulders closeup
318
+ - **Turnaround**: Multiple angle views
319
+ - **Action Pose**: Dynamic fighting stance
320
+ - **Idle Stance**: Neutral standing position
321
+ - **Character Sheet**: Reference with details
322
+ - **Battle Stance**: Ready for combat
323
+
324
+ ### ๐ŸŽฏ Performance Tips
325
+
326
+ - **CPU Mode**: Use 512x768, 20-25 steps (~2-3 min)
327
+ - **GPU Mode**: Use 512x768, 30-35 steps (~30 sec)
328
+ - **High Quality**: 768x1024, 40 steps (slow but best)
329
+
330
+ ---
331
+
332
+ **Model:** DreamShaper 8 | **Framework:** Diffusers | **UI:** Gradio
333
+
334
+ Perfect for game developers, concept artists, and indie creators! ๐ŸŽฎโœจ
335
+ """)
336
+
337
+ # Launch
338
+ demo.queue(max_size=20).launch(
339
+ server_name="0.0.0.0",
340
+ port=7860,
341
+ share=False
342
+ )
343
+ ENDOFFILE
344
+
345
+ echo "โœ… app.py created!"
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ diffusers==0.27.2
2
+ transformers==4.38.1
3
+ accelerate==0.27.2
4
+ torch==2.2.0
5
+ torchvision==0.17.0
6
+ gradio==4.19.2
7
+ pillow==10.2.0
8
+ numpy==1.26.4
9
+ safetensors==0.4.2
10
+ huggingface-hub==0.21.4