Update app.py
Browse files
app.py
CHANGED
|
@@ -1,421 +1,186 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
import torch
|
| 5 |
-
from diffusers import DiffusionPipeline
|
| 6 |
-
import spaces
|
| 7 |
-
# κΈ°λ³Έ μ€μ
|
| 8 |
-
dtype = torch.bfloat16
|
| 9 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
-
|
| 11 |
-
# λͺ¨λΈ λ‘λ
|
| 12 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 13 |
-
"black-forest-labs/FLUX.1-schnell",
|
| 14 |
-
torch_dtype=dtype
|
| 15 |
-
).to(device)
|
| 16 |
-
|
| 17 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 18 |
-
MAX_IMAGE_SIZE = 2048
|
| 19 |
-
|
| 20 |
-
# Enhanced examples with more detailed prompts and specific styling
|
| 21 |
-
EXAMPLES = [
|
| 22 |
-
{
|
| 23 |
-
"title": "Knowledge Tree",
|
| 24 |
-
"prompt": """A handrawn colorful mind map diagram, educational style, vibrant colors, clear hierarchy, golden ratio layout.
|
| 25 |
-
KNOWLEDGE
|
| 26 |
-
βββ ACQUISITION [Brain with Lightning ~60px]
|
| 27 |
-
β βββ READING [Open Book with Glow]
|
| 28 |
-
β βββ PRACTICE [Hands-on Tools]
|
| 29 |
-
β βββ OBSERVATION [Eye with Magnifier]
|
| 30 |
-
βββ PROCESSING [Gear Network ~50px]
|
| 31 |
-
β βββ ANALYSIS [Graph Trending Up]
|
| 32 |
-
β βββ SYNTHESIS [Puzzle Pieces]
|
| 33 |
-
βββ RETENTION [Memory Chip ~45px]
|
| 34 |
-
β βββ SHORT-TERM [Quick Flash]
|
| 35 |
-
β βββ LONG-TERM [Solid Archive]
|
| 36 |
-
βββ APPLICATION
|
| 37 |
-
βββ CREATION [Artist Palette]
|
| 38 |
-
βββ INNOVATION [Lightbulb Constellation]""",
|
| 39 |
-
"width": 1024,
|
| 40 |
-
"height": 1024
|
| 41 |
-
},
|
| 42 |
-
{
|
| 43 |
-
"title": "Digital Transformation",
|
| 44 |
-
"prompt": """A handrawn colorful mind map diagram, tech-focused style, neon accents, circuit board patterns.
|
| 45 |
-
DIGITAL TRANSFORM
|
| 46 |
-
βββ CLOUD [Cloud with Data Rain ~55px]
|
| 47 |
-
β βββ STORAGE [Database Cluster]
|
| 48 |
-
β βββ COMPUTING [Server Array]
|
| 49 |
-
βββ AUTOMATION [Robot Arm ~50px]
|
| 50 |
-
β βββ WORKFLOWS [Flowchart]
|
| 51 |
-
β βββ AI/ML [Neural Network]
|
| 52 |
-
βββ SECURITY [Shield Matrix ~45px]
|
| 53 |
-
β βββ ENCRYPTION [Lock Code]
|
| 54 |
-
β βββ MONITORING [Radar Screen]
|
| 55 |
-
βββ INTEGRATION
|
| 56 |
-
βββ APIS [Puzzle Connect]
|
| 57 |
-
βββ MICROSERVICES [Building Blocks]""",
|
| 58 |
-
"width": 1024,
|
| 59 |
-
"height": 1024
|
| 60 |
-
},
|
| 61 |
-
{
|
| 62 |
-
"title": "Creative Process",
|
| 63 |
-
"prompt": """A handrawn colorful mind map diagram, artistic style, watercolor effects, flowing connections.
|
| 64 |
-
CREATIVITY
|
| 65 |
-
βββ INSPIRATION [Constellation Stars ~60px]
|
| 66 |
-
β βββ NATURE [Organic Patterns]
|
| 67 |
-
β βββ CULTURE [Global Icons]
|
| 68 |
-
βββ IDEATION [Floating Bubbles ~50px]
|
| 69 |
-
β βββ BRAINSTORM [Thunder Cloud]
|
| 70 |
-
β βββ REFINEMENT [Diamond Polish]
|
| 71 |
-
βββ EXECUTION [Artist Tools ~45px]
|
| 72 |
-
β βββ TECHNIQUE [Skilled Hands]
|
| 73 |
-
β βββ MEDIUM [Palette Mix]
|
| 74 |
-
βββ PRESENTATION
|
| 75 |
-
βββ GALLERY [Frame Display]
|
| 76 |
-
βββ FEEDBACK [Echo Ripples]""",
|
| 77 |
-
"width": 1024,
|
| 78 |
-
"height": 1024
|
| 79 |
-
},
|
| 80 |
-
{
|
| 81 |
-
"title": "Future Cities",
|
| 82 |
-
"prompt": """A handrawn colorful mind map diagram, futuristic style, holographic elements, sustainable themes.
|
| 83 |
-
SMART CITY
|
| 84 |
-
βββ MOBILITY [Hover Transport ~60px]
|
| 85 |
-
β βββ AUTONOMOUS [Self-Driving]
|
| 86 |
-
β βββ CONNECTED [Network Grid]
|
| 87 |
-
βββ ENERGY [Solar Crystal ~55px]
|
| 88 |
-
β βββ RENEWABLE [Green Power]
|
| 89 |
-
β βββ STORAGE [Battery Hub]
|
| 90 |
-
βββ LIVING [Eco Building ~50px]
|
| 91 |
-
β βββ VERTICAL [Sky Gardens]
|
| 92 |
-
β βββ COMMUNITY [People Connect]
|
| 93 |
-
βββ INFRASTRUCTURE
|
| 94 |
-
βββ AI GRID [Neural City]
|
| 95 |
-
βββ ECO SYSTEM [Nature Tech]""",
|
| 96 |
-
"width": 1024,
|
| 97 |
-
"height": 1024
|
| 98 |
-
},
|
| 99 |
-
{
|
| 100 |
-
"title": "Health Evolution",
|
| 101 |
-
"prompt": """A handrawn colorful mind map diagram, medical style, DNA helix patterns, wellness focus.
|
| 102 |
-
HEALTH 3.0
|
| 103 |
-
βββ PREVENTION [Shield DNA ~60px]
|
| 104 |
-
β βββ LIFESTYLE [Activity Pulse]
|
| 105 |
-
β βββ MONITORING [Health Watch]
|
| 106 |
-
βββ TREATMENT [Caduceus Tech ~55px]
|
| 107 |
-
β βββ PERSONALIZED [DNA Code]
|
| 108 |
-
β βββ REGENERATIVE [Cell Renew]
|
| 109 |
-
βββ ENHANCEMENT [Upgrade Spiral ~50px]
|
| 110 |
-
β βββ COGNITIVE [Brain Boost]
|
| 111 |
-
β βββ PHYSICAL [Body Optimize]
|
| 112 |
-
βββ INTEGRATION
|
| 113 |
-
βββ AI HEALTH [Smart Doctor]
|
| 114 |
-
βββ COMMUNITY [Global Care]""",
|
| 115 |
-
"width": 1024,
|
| 116 |
-
"height": 1024
|
| 117 |
-
},
|
| 118 |
-
{
|
| 119 |
-
"title": "Space Exploration",
|
| 120 |
-
"prompt": """A handrawn colorful mind map diagram, cosmic style, star field background, planetary elements.
|
| 121 |
-
SPACE FRONTIER
|
| 122 |
-
βββ DISCOVERY [Telescope Array ~60px]
|
| 123 |
-
β βββ MAPPING [Star Charts]
|
| 124 |
-
β βββ ANALYSIS [Data Stream]
|
| 125 |
-
βββ TRAVEL [Rocket Launch ~55px]
|
| 126 |
-
β βββ PROPULSION [Energy Core]
|
| 127 |
-
β βββ NAVIGATION [Space Map]
|
| 128 |
-
βββ COLONIZATION [Dome City ~50px]
|
| 129 |
-
β βββ HABITATS [Life Sphere]
|
| 130 |
-
β βββ RESOURCES [Mine Extract]
|
| 131 |
-
βββ RESEARCH
|
| 132 |
-
βββ ASTROBIOLOGY [Life Search]
|
| 133 |
-
βββ PHYSICS [Space Time]""",
|
| 134 |
-
"width": 1024,
|
| 135 |
-
"height": 1024
|
| 136 |
-
},
|
| 137 |
-
{
|
| 138 |
-
"title": "Ocean Innovation",
|
| 139 |
-
"prompt": """A handrawn colorful mind map diagram, marine style, wave patterns, aqua themes.
|
| 140 |
-
OCEAN TECH
|
| 141 |
-
βββ EXPLORATION [Deep Submersible ~60px]
|
| 142 |
-
β βββ MAPPING [Sonar Wave]
|
| 143 |
-
β βββ RESEARCH [Lab Bubble]
|
| 144 |
-
βββ CONSERVATION [Marine Life ~55px]
|
| 145 |
-
β βββ PROTECTION [Reef Shield]
|
| 146 |
-
β βββ RESTORATION [Growth Core]
|
| 147 |
-
βββ HARVESTING [Sustainable Net ~50px]
|
| 148 |
-
β βββ ENERGY [Wave Power]
|
| 149 |
-
β βββ RESOURCES [Bio Extract]
|
| 150 |
-
βββ MONITORING
|
| 151 |
-
βββ AI SYSTEMS [Smart Sensors]
|
| 152 |
-
βββ ECOLOGY [Life Web]""",
|
| 153 |
-
"width": 1024,
|
| 154 |
-
"height": 1024
|
| 155 |
-
},
|
| 156 |
-
{
|
| 157 |
-
"title": "Quantum Computing",
|
| 158 |
-
"prompt": """A handrawn colorful mind map diagram, quantum style, wave-particle duality, matrix patterns.
|
| 159 |
-
QUANTUM TECH
|
| 160 |
-
βββ COMPUTATION [Qubit Matrix ~60px]
|
| 161 |
-
β βββ PROCESSING [Wave Function]
|
| 162 |
-
β βββ ALGORITHMS [Code Quantum]
|
| 163 |
-
βββ APPLICATIONS [Use Cases ~55px]
|
| 164 |
-
β βββ SIMULATION [Model World]
|
| 165 |
-
β βββ OPTIMIZATION [Peak Find]
|
| 166 |
-
βββ INFRASTRUCTURE [Q-Hardware ~50px]
|
| 167 |
-
β βββ CONTROL [Pulse Shape]
|
| 168 |
-
β βββ COOLING [Zero Point]
|
| 169 |
-
βββ DEVELOPMENT
|
| 170 |
-
βββ SOFTWARE [Q-Code Web]
|
| 171 |
-
βββ INTEGRATION [Classical Bridge]""",
|
| 172 |
-
"width": 1024,
|
| 173 |
-
"height": 1024
|
| 174 |
-
},
|
| 175 |
-
{
|
| 176 |
-
"title": "Bio Engineering",
|
| 177 |
-
"prompt": """A handrawn colorful mind map diagram, biological style, DNA patterns, organic flow.
|
| 178 |
-
BIOTECH
|
| 179 |
-
βββ GENETICS [DNA Helix ~60px]
|
| 180 |
-
β βββ EDITING [CRISPR Tool]
|
| 181 |
-
β βββ SYNTHESIS [Gene Build]
|
| 182 |
-
βββ APPLICATIONS [Lab Array ~55px]
|
| 183 |
-
β βββ MEDICINE [Heal Cell]
|
| 184 |
-
β βββ AGRICULTURE [Grow Plus]
|
| 185 |
-
βββ PLATFORMS [Bio Factory ~50px]
|
| 186 |
-
β βββ SENSORS [Live Detect]
|
| 187 |
-
β βββ PROCESSORS [Cell Compute]
|
| 188 |
-
βββ INTEGRATION
|
| 189 |
-
βββ AI BIOLOGY [Smart Life]
|
| 190 |
-
βββ ECOSYSTEM [Nature Net]""",
|
| 191 |
-
"width": 1024,
|
| 192 |
-
"height": 1024
|
| 193 |
-
},
|
| 194 |
-
{
|
| 195 |
-
"title": "AI Evolution",
|
| 196 |
-
"prompt": """A handrawn colorful mind map diagram, neural network style, digital patterns, intelligence flow.
|
| 197 |
-
AI FUTURE
|
| 198 |
-
βββ COGNITION [Brain Network ~60px]
|
| 199 |
-
β βββ LEARNING [Growth Path]
|
| 200 |
-
β βββ REASONING [Logic Tree]
|
| 201 |
-
βββ PERCEPTION [Sensor Array ~55px]
|
| 202 |
-
β βββ VISION [Eye Matrix]
|
| 203 |
-
β βββ LANGUAGE [Word Web]
|
| 204 |
-
βββ INTERACTION [Connect Hub ~50px]
|
| 205 |
-
β βββ HUMAN [Bridge Link]
|
| 206 |
-
β βββ MACHINE [Code Path]
|
| 207 |
-
βββ EVOLUTION
|
| 208 |
-
βββ CONSCIOUSNESS [Mind Spark]
|
| 209 |
-
βββ CREATIVITY [Art Core]""",
|
| 210 |
-
"width": 1024,
|
| 211 |
-
"height": 1024
|
| 212 |
-
}
|
| 213 |
-
]
|
| 214 |
|
| 215 |
-
#
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
for example in EXAMPLES
|
| 219 |
-
]
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
if randomize_seed:
|
| 224 |
-
seed = random.randint(0, MAX_SEED)
|
| 225 |
-
generator = torch.Generator().manual_seed(seed)
|
| 226 |
-
image = pipe(
|
| 227 |
-
prompt=prompt,
|
| 228 |
-
width=width,
|
| 229 |
-
height=height,
|
| 230 |
-
num_inference_steps=num_inference_steps,
|
| 231 |
-
generator=generator,
|
| 232 |
-
guidance_scale=0.0
|
| 233 |
-
).images[0]
|
| 234 |
-
return image, seed
|
| 235 |
-
|
| 236 |
-
# CSS μ€νμΌ μμ
|
| 237 |
-
css = """
|
| 238 |
-
.container {
|
| 239 |
-
display: flex;
|
| 240 |
-
flex-direction: row;
|
| 241 |
-
height: 100%;
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
.input-column {
|
| 245 |
-
flex: 1;
|
| 246 |
-
padding: 20px;
|
| 247 |
-
border-right: 2px solid #eee;
|
| 248 |
-
max-width: 800px; /* μ¦κ°λ μ΅λ λλΉ */
|
| 249 |
-
}
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
background: #f7f7f7;
|
| 256 |
-
}
|
| 257 |
|
| 258 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
text-align: center;
|
| 260 |
-
|
| 261 |
-
padding: 20px;
|
| 262 |
-
font-size: 2.5em;
|
| 263 |
font-weight: bold;
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
margin-bottom: 30px;
|
| 267 |
}
|
| 268 |
-
|
| 269 |
-
.subtitle {
|
| 270 |
text-align: center;
|
| 271 |
color: #666;
|
| 272 |
margin-bottom: 30px;
|
|
|
|
| 273 |
}
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
| 276 |
background: white;
|
|
|
|
| 277 |
padding: 20px;
|
| 278 |
-
border-radius: 10px;
|
| 279 |
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 280 |
-
margin-bottom: 20px;
|
| 281 |
-
width: 100%; /* μ 체 λλΉ μ¬μ© */
|
| 282 |
}
|
| 283 |
-
|
| 284 |
-
/* ν
μ€νΈ μ
λ ₯ λ°μ€ μ€νμΌ */
|
| 285 |
-
.input-box textarea {
|
| 286 |
-
width: 100% !important; /* κ°μ λλΉ 100% */
|
| 287 |
-
min-width: 600px !important; /* μ΅μ λλΉ μ€μ */
|
| 288 |
font-size: 14px !important;
|
| 289 |
-
|
| 290 |
-
padding: 12px !important;
|
| 291 |
}
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
padding: 15px;
|
| 296 |
-
margin: 10px 0;
|
| 297 |
-
border-radius: 8px;
|
| 298 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
.example-title {
|
| 302 |
-
font-weight: bold;
|
| 303 |
-
color: #2a2a2a;
|
| 304 |
-
margin-bottom: 10px;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
/* λ μ΄μμ μ‘°μ */
|
| 308 |
-
.contain {
|
| 309 |
-
max-width: 1400px !important; /* μ 체 컨ν
μ΄λ λλΉ μ¦κ° */
|
| 310 |
-
margin: 0 auto !important;
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
/* μ
λ ₯ μμ μ‘°μ */
|
| 314 |
-
.input-area {
|
| 315 |
-
flex: 2 !important; /* μ
λ ₯ μμ λΉμ¨ μ¦κ° */
|
| 316 |
}
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
| 321 |
}
|
| 322 |
"""
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
gr.Markdown(
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
)
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
label="Seed",
|
| 352 |
-
minimum=0,
|
| 353 |
-
maximum=MAX_SEED,
|
| 354 |
-
step=1,
|
| 355 |
-
value=0,
|
| 356 |
)
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
with gr.Row():
|
| 360 |
-
width = gr.Slider(
|
| 361 |
-
label="Width",
|
| 362 |
-
minimum=256,
|
| 363 |
-
maximum=MAX_IMAGE_SIZE,
|
| 364 |
-
step=32,
|
| 365 |
-
value=1024,
|
| 366 |
-
)
|
| 367 |
-
height = gr.Slider(
|
| 368 |
-
label="Height",
|
| 369 |
-
minimum=256,
|
| 370 |
-
maximum=MAX_IMAGE_SIZE,
|
| 371 |
-
step=32,
|
| 372 |
-
value=1024,
|
| 373 |
-
)
|
| 374 |
-
|
| 375 |
num_inference_steps = gr.Slider(
|
| 376 |
label="Number of inference steps",
|
|
|
|
| 377 |
minimum=1,
|
| 378 |
maximum=50,
|
| 379 |
-
step=1
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
)
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
outputs=[result, seed]
|
| 410 |
)
|
| 411 |
|
| 412 |
-
#
|
| 413 |
if __name__ == "__main__":
|
| 414 |
demo.queue()
|
| 415 |
-
demo.launch(
|
| 416 |
-
server_name="0.0.0.0",
|
| 417 |
-
server_port=7860,
|
| 418 |
-
share=False,
|
| 419 |
-
show_error=True,
|
| 420 |
-
debug=True
|
| 421 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Transformersμ νμ΄νλΌμΈμ μ΄μ©ν΄ λ²μμ© νμ΄νλΌμΈ λ‘λ
|
| 5 |
+
from transformers import pipeline as translation_pipeline
|
| 6 |
+
translator = translation_pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Diffusers λͺ¨λΈ λ‘λ
|
| 9 |
+
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# -- Stable Diffusion κ³μ΄ νμ΄νλΌμΈ μ€μ --
|
| 12 |
+
# (λͺ¨λΈ μμ: black-forest-labs/FLUX.1-schnell -> λ§μΈλλ§΅μ©μΌλ‘ 컀μ€ν
λ λͺ¨λΈμ΄μ§λ§,
|
| 13 |
+
# μ¬κΈ°μλ "μ€ν 리보λ" μ€νμΌ ν둬ννΈλ μλ κ°λ₯)
|
| 14 |
+
model_id = "black-forest-labs/FLUX.1-schnell"
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 17 |
+
model_id,
|
| 18 |
+
torch_dtype=torch.float32
|
| 19 |
+
).to("cpu") # CPU μ¬μ©
|
| 20 |
+
|
| 21 |
+
# νκΈ ν둬ννΈλ₯Ό μμ΄λ‘ λ³ννκΈ° μν ν¬νΌ ν¨μ
|
| 22 |
+
def translate_prompt_if_korean(prompt_text: str) -> str:
|
| 23 |
+
# κ°λ¨ν, λ¬Έμμ΄ λ΄μ νκΈμ΄ ν¬ν¨λμ΄ μλμ§ νμΈ ν λ²μ
|
| 24 |
+
# (μμ΄ μ
λ ₯μΌ κ²½μ° λ²μμ μ€ν΅)
|
| 25 |
+
if any("κ°" <= ch <= "ν£" for ch in prompt_text):
|
| 26 |
+
result = translator(prompt_text)
|
| 27 |
+
return result[0]['translation_text']
|
| 28 |
+
return prompt_text
|
| 29 |
+
|
| 30 |
+
def generate_storyboard(
|
| 31 |
+
prompt,
|
| 32 |
+
width=768,
|
| 33 |
+
height=512,
|
| 34 |
+
num_inference_steps=10,
|
| 35 |
+
guidance_scale=7.5,
|
| 36 |
+
seed=42
|
| 37 |
+
):
|
| 38 |
+
# λ²μ μ²λ¦¬ (νκΈ -> μμ΄)
|
| 39 |
+
prompt_en = translate_prompt_if_korean(prompt)
|
| 40 |
+
|
| 41 |
+
# μλ μμ±
|
| 42 |
+
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 43 |
+
|
| 44 |
+
# μ΄λ―Έμ§ μμ±
|
| 45 |
+
with torch.autocast("cpu"):
|
| 46 |
+
result = pipe(
|
| 47 |
+
prompt=prompt_en,
|
| 48 |
+
width=width,
|
| 49 |
+
height=height,
|
| 50 |
+
num_inference_steps=num_inference_steps,
|
| 51 |
+
guidance_scale=guidance_scale,
|
| 52 |
+
generator=generator
|
| 53 |
+
).images[0]
|
| 54 |
+
return result
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# --- λΉμ£ΌμΌ & μΈλ ¨λ UIλ₯Ό μν CSS ---
|
| 58 |
+
custom_css = """
|
| 59 |
+
#title {
|
| 60 |
text-align: center;
|
| 61 |
+
font-size: 3em;
|
|
|
|
|
|
|
| 62 |
font-weight: bold;
|
| 63 |
+
margin: 20px 0;
|
| 64 |
+
color: #333;
|
|
|
|
| 65 |
}
|
| 66 |
+
#subtitle {
|
|
|
|
| 67 |
text-align: center;
|
| 68 |
color: #666;
|
| 69 |
margin-bottom: 30px;
|
| 70 |
+
font-size: 1.2em;
|
| 71 |
}
|
| 72 |
+
.gradio-container {
|
| 73 |
+
background: linear-gradient(120deg, #f8f8f8 0%, #ffffff 100%);
|
| 74 |
+
}
|
| 75 |
+
.input-panel, .output-panel {
|
| 76 |
background: white;
|
| 77 |
+
border-radius: 12px;
|
| 78 |
padding: 20px;
|
|
|
|
| 79 |
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
+
#prompt-input {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
font-size: 14px !important;
|
| 83 |
+
min-height: 140px !important;
|
|
|
|
| 84 |
}
|
| 85 |
+
.advanced-settings {
|
| 86 |
+
font-size: 0.9em;
|
| 87 |
+
color: #444;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
+
.example-box {
|
| 90 |
+
background: #f9f9f9;
|
| 91 |
+
padding: 10px;
|
| 92 |
+
margin-top: 10px;
|
| 93 |
+
border-radius: 8px;
|
| 94 |
}
|
| 95 |
"""
|
| 96 |
|
| 97 |
+
# --- Gradio μΈν°νμ΄μ€ κ΅¬μ± ---
|
| 98 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 99 |
+
gr.Markdown("<div id='title'>Gini Storyboard</div>")
|
| 100 |
+
gr.Markdown("<div id='subtitle'>Generate a hand-drawn style storyboard in black & white film noir or any style you wish!</div>")
|
| 101 |
+
|
| 102 |
+
with gr.Row():
|
| 103 |
+
with gr.Column(elem_classes="input-panel", scale=1):
|
| 104 |
+
prompt = gr.Textbox(
|
| 105 |
+
label="Storyboard Prompt",
|
| 106 |
+
placeholder="Enter your scene descriptions here (in English or Korean)",
|
| 107 |
+
lines=8,
|
| 108 |
+
elem_id="prompt-input"
|
| 109 |
+
)
|
| 110 |
+
seed = gr.Slider(
|
| 111 |
+
label="Seed",
|
| 112 |
+
value=42,
|
| 113 |
+
minimum=0,
|
| 114 |
+
maximum=999999,
|
| 115 |
+
step=1
|
| 116 |
+
)
|
| 117 |
+
with gr.Row():
|
| 118 |
+
width = gr.Slider(
|
| 119 |
+
label="Width",
|
| 120 |
+
minimum=256,
|
| 121 |
+
maximum=1280,
|
| 122 |
+
value=768,
|
| 123 |
+
step=64
|
| 124 |
)
|
| 125 |
+
height = gr.Slider(
|
| 126 |
+
label="Height",
|
| 127 |
+
minimum=256,
|
| 128 |
+
maximum=1280,
|
| 129 |
+
value=512,
|
| 130 |
+
step=64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
)
|
| 132 |
+
with gr.Accordion("Advanced Settings", open=False, elem_classes="advanced-settings"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
num_inference_steps = gr.Slider(
|
| 134 |
label="Number of inference steps",
|
| 135 |
+
value=10,
|
| 136 |
minimum=1,
|
| 137 |
maximum=50,
|
| 138 |
+
step=1
|
| 139 |
+
)
|
| 140 |
+
guidance_scale = gr.Slider(
|
| 141 |
+
label="Guidance Scale",
|
| 142 |
+
value=7.5,
|
| 143 |
+
minimum=0.0,
|
| 144 |
+
maximum=20.0,
|
| 145 |
+
step=0.5
|
| 146 |
)
|
| 147 |
+
|
| 148 |
+
run_button = gr.Button("Generate Storyboard", variant="primary")
|
| 149 |
+
|
| 150 |
+
with gr.Column(elem_classes="output-panel", scale=1):
|
| 151 |
+
result = gr.Image(label="Storyboard Result")
|
| 152 |
+
|
| 153 |
+
# μμ ν둬ννΈ
|
| 154 |
+
gr.Markdown("### Example Prompt")
|
| 155 |
+
with gr.Box(elem_classes="example-box"):
|
| 156 |
+
example_text = (
|
| 157 |
+
"A hand-drawn storyboard style, film noir theme, black and white.\n"
|
| 158 |
+
"SCENE 1: A detective enters a dark alley [Frame 1]\n"
|
| 159 |
+
"SCENE 2: He notices a shadow [Frame 2]\n"
|
| 160 |
+
"SCENE 3: A sudden flash of light reveals a clue [Frame 3]"
|
| 161 |
+
)
|
| 162 |
+
gr.Markdown(f"```\n{example_text}\n```")
|
| 163 |
+
example_button = gr.Button("Use Example")
|
| 164 |
+
|
| 165 |
+
# μμ λ²νΌ ν΄λ¦ μ ν둬ννΈμ λ°μ
|
| 166 |
+
def load_example():
|
| 167 |
+
return example_text
|
| 168 |
+
example_button.click(fn=load_example, outputs=[prompt])
|
| 169 |
+
|
| 170 |
+
# λ²νΌ ν΄λ¦ & ν둬ννΈ Enter μ΄λ²€νΈ μ²λ¦¬
|
| 171 |
+
run_button.click(
|
| 172 |
+
fn=generate_storyboard,
|
| 173 |
+
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 174 |
+
outputs=[result]
|
| 175 |
+
)
|
| 176 |
|
| 177 |
+
prompt.submit(
|
| 178 |
+
fn=generate_storyboard,
|
| 179 |
+
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 180 |
+
outputs=[result]
|
|
|
|
| 181 |
)
|
| 182 |
|
| 183 |
+
# μ€ν
|
| 184 |
if __name__ == "__main__":
|
| 185 |
demo.queue()
|
| 186 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|