Spaces:
aiqcamp
/
Running on Zero

File size: 14,397 Bytes
6742856
 
202b398
6742856
 
4fde2f5
afc3bcb
 
6742856
353b3a8
6742856
202b398
afc3bcb
 
202b398
 
6742856
 
a473659
a6cbec6
 
0118a77
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
dd5d6cc
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd5d6cc
 
0118a77
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
 
 
a6cbec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0118a77
 
dd5d6cc
 
 
a6cbec6
 
 
 
 
1a0c9b6
e86909d
afc3bcb
 
6742856
afc3bcb
 
 
 
 
 
 
 
 
 
7039a00
2531620
 
 
 
 
 
 
 
 
 
 
 
0da9692
2531620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0da9692
 
 
 
 
 
 
 
 
 
2531620
 
 
 
 
 
 
 
 
 
 
 
 
 
202b398
0da9692
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202b398
 
0da9692
2531620
202b398
2531620
 
494ca26
2531620
202b398
2531620
0da9692
2531620
 
 
0da9692
f1f3239
2531620
 
 
0da9692
 
2531620
0da9692
2531620
 
202b398
2531620
 
 
 
 
 
 
202b398
2531620
202b398
2531620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202b398
 
2531620
 
 
 
f1f3239
e6dd635
 
f1f3239
 
 
 
 
 
 
 
 
 
 
 
 
e6dd635
202b398
 
 
afc3bcb
202b398
 
 
dd5d6cc
6742856
dd5d6cc
6742856
7039a00
 
 
 
 
708b543
7039a00
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
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
410
411
412
413
414
415
416
417
418
419
420
421
import gradio as gr
import numpy as np
import random
import torch
from diffusers import DiffusionPipeline
import spaces
# κΈ°λ³Έ μ„€μ •
dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"

# λͺ¨λΈ λ‘œλ“œ
pipe = DiffusionPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-schnell", 
    torch_dtype=dtype
).to(device)

MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 2048

# Enhanced examples with more detailed prompts and specific styling
EXAMPLES = [
    {
        "title": "Knowledge Tree",
        "prompt": """A handrawn colorful mind map diagram, educational style, vibrant colors, clear hierarchy, golden ratio layout.
        KNOWLEDGE
        β”œβ”€β”€ ACQUISITION [Brain with Lightning ~60px]
        β”‚   β”œβ”€β”€ READING [Open Book with Glow]
        β”‚   β”œβ”€β”€ PRACTICE [Hands-on Tools]
        β”‚   └── OBSERVATION [Eye with Magnifier]
        β”œβ”€β”€ PROCESSING [Gear Network ~50px]
        β”‚   β”œβ”€β”€ ANALYSIS [Graph Trending Up]
        β”‚   └── SYNTHESIS [Puzzle Pieces]
        β”œβ”€β”€ RETENTION [Memory Chip ~45px]
        β”‚   β”œβ”€β”€ SHORT-TERM [Quick Flash]
        β”‚   └── LONG-TERM [Solid Archive]
        └── APPLICATION
            β”œβ”€β”€ CREATION [Artist Palette]
            └── INNOVATION [Lightbulb Constellation]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Digital Transformation",
        "prompt": """A handrawn colorful mind map diagram, tech-focused style, neon accents, circuit board patterns.
        DIGITAL TRANSFORM
        β”œβ”€β”€ CLOUD [Cloud with Data Rain ~55px]
        β”‚   β”œβ”€β”€ STORAGE [Database Cluster]
        β”‚   └── COMPUTING [Server Array]
        β”œβ”€β”€ AUTOMATION [Robot Arm ~50px]
        β”‚   β”œβ”€β”€ WORKFLOWS [Flowchart]
        β”‚   └── AI/ML [Neural Network]
        β”œβ”€β”€ SECURITY [Shield Matrix ~45px]
        β”‚   β”œβ”€β”€ ENCRYPTION [Lock Code]
        β”‚   └── MONITORING [Radar Screen]
        └── INTEGRATION
            β”œβ”€β”€ APIS [Puzzle Connect]
            └── MICROSERVICES [Building Blocks]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Creative Process",
        "prompt": """A handrawn colorful mind map diagram, artistic style, watercolor effects, flowing connections.
        CREATIVITY
        β”œβ”€β”€ INSPIRATION [Constellation Stars ~60px]
        β”‚   β”œβ”€β”€ NATURE [Organic Patterns]
        β”‚   └── CULTURE [Global Icons]
        β”œβ”€β”€ IDEATION [Floating Bubbles ~50px]
        β”‚   β”œβ”€β”€ BRAINSTORM [Thunder Cloud]
        β”‚   └── REFINEMENT [Diamond Polish]
        β”œβ”€β”€ EXECUTION [Artist Tools ~45px]
        β”‚   β”œβ”€β”€ TECHNIQUE [Skilled Hands]
        β”‚   └── MEDIUM [Palette Mix]
        └── PRESENTATION
            β”œβ”€β”€ GALLERY [Frame Display]
            └── FEEDBACK [Echo Ripples]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Future Cities",
        "prompt": """A handrawn colorful mind map diagram, futuristic style, holographic elements, sustainable themes.
        SMART CITY
        β”œβ”€β”€ MOBILITY [Hover Transport ~60px]
        β”‚   β”œβ”€β”€ AUTONOMOUS [Self-Driving]
        β”‚   └── CONNECTED [Network Grid]
        β”œβ”€β”€ ENERGY [Solar Crystal ~55px]
        β”‚   β”œβ”€β”€ RENEWABLE [Green Power]
        β”‚   └── STORAGE [Battery Hub]
        β”œβ”€β”€ LIVING [Eco Building ~50px]
        β”‚   β”œβ”€β”€ VERTICAL [Sky Gardens]
        β”‚   └── COMMUNITY [People Connect]
        └── INFRASTRUCTURE
            β”œβ”€β”€ AI GRID [Neural City]
            └── ECO SYSTEM [Nature Tech]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Health Evolution",
        "prompt": """A handrawn colorful mind map diagram, medical style, DNA helix patterns, wellness focus.
        HEALTH 3.0
        β”œβ”€β”€ PREVENTION [Shield DNA ~60px]
        β”‚   β”œβ”€β”€ LIFESTYLE [Activity Pulse]
        β”‚   └── MONITORING [Health Watch]
        β”œβ”€β”€ TREATMENT [Caduceus Tech ~55px]
        β”‚   β”œβ”€β”€ PERSONALIZED [DNA Code]
        β”‚   └── REGENERATIVE [Cell Renew]
        β”œβ”€β”€ ENHANCEMENT [Upgrade Spiral ~50px]
        β”‚   β”œβ”€β”€ COGNITIVE [Brain Boost]
        β”‚   └── PHYSICAL [Body Optimize]
        └── INTEGRATION
            β”œβ”€β”€ AI HEALTH [Smart Doctor]
            └── COMMUNITY [Global Care]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Space Exploration",
        "prompt": """A handrawn colorful mind map diagram, cosmic style, star field background, planetary elements.
        SPACE FRONTIER
        β”œβ”€β”€ DISCOVERY [Telescope Array ~60px]
        β”‚   β”œβ”€β”€ MAPPING [Star Charts]
        β”‚   └── ANALYSIS [Data Stream]
        β”œβ”€β”€ TRAVEL [Rocket Launch ~55px]
        β”‚   β”œβ”€β”€ PROPULSION [Energy Core]
        β”‚   └── NAVIGATION [Space Map]
        β”œβ”€β”€ COLONIZATION [Dome City ~50px]
        β”‚   β”œβ”€β”€ HABITATS [Life Sphere]
        β”‚   └── RESOURCES [Mine Extract]
        └── RESEARCH
            β”œβ”€β”€ ASTROBIOLOGY [Life Search]
            └── PHYSICS [Space Time]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Ocean Innovation",
        "prompt": """A handrawn colorful mind map diagram, marine style, wave patterns, aqua themes.
        OCEAN TECH
        β”œβ”€β”€ EXPLORATION [Deep Submersible ~60px]
        β”‚   β”œβ”€β”€ MAPPING [Sonar Wave]
        β”‚   └── RESEARCH [Lab Bubble]
        β”œβ”€β”€ CONSERVATION [Marine Life ~55px]
        β”‚   β”œβ”€β”€ PROTECTION [Reef Shield]
        β”‚   └── RESTORATION [Growth Core]
        β”œβ”€β”€ HARVESTING [Sustainable Net ~50px]
        β”‚   β”œβ”€β”€ ENERGY [Wave Power]
        β”‚   └── RESOURCES [Bio Extract]
        └── MONITORING
            β”œβ”€β”€ AI SYSTEMS [Smart Sensors]
            └── ECOLOGY [Life Web]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Quantum Computing",
        "prompt": """A handrawn colorful mind map diagram, quantum style, wave-particle duality, matrix patterns.
        QUANTUM TECH
        β”œβ”€β”€ COMPUTATION [Qubit Matrix ~60px]
        β”‚   β”œβ”€β”€ PROCESSING [Wave Function]
        β”‚   └── ALGORITHMS [Code Quantum]
        β”œβ”€β”€ APPLICATIONS [Use Cases ~55px]
        β”‚   β”œβ”€β”€ SIMULATION [Model World]
        β”‚   └── OPTIMIZATION [Peak Find]
        β”œβ”€β”€ INFRASTRUCTURE [Q-Hardware ~50px]
        β”‚   β”œβ”€β”€ CONTROL [Pulse Shape]
        β”‚   └── COOLING [Zero Point]
        └── DEVELOPMENT
            β”œβ”€β”€ SOFTWARE [Q-Code Web]
            └── INTEGRATION [Classical Bridge]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "Bio Engineering",
        "prompt": """A handrawn colorful mind map diagram, biological style, DNA patterns, organic flow.
        BIOTECH
        β”œβ”€β”€ GENETICS [DNA Helix ~60px]
        β”‚   β”œβ”€β”€ EDITING [CRISPR Tool]
        β”‚   └── SYNTHESIS [Gene Build]
        β”œβ”€β”€ APPLICATIONS [Lab Array ~55px]
        β”‚   β”œβ”€β”€ MEDICINE [Heal Cell]
        β”‚   └── AGRICULTURE [Grow Plus]
        β”œβ”€β”€ PLATFORMS [Bio Factory ~50px]
        β”‚   β”œβ”€β”€ SENSORS [Live Detect]
        β”‚   └── PROCESSORS [Cell Compute]
        └── INTEGRATION
            β”œβ”€β”€ AI BIOLOGY [Smart Life]
            └── ECOSYSTEM [Nature Net]""",
        "width": 1024,
        "height": 1024
    },
    {
        "title": "AI Evolution",
        "prompt": """A handrawn colorful mind map diagram, neural network style, digital patterns, intelligence flow.
        AI FUTURE
        β”œβ”€β”€ COGNITION [Brain Network ~60px]
        β”‚   β”œβ”€β”€ LEARNING [Growth Path]
        β”‚   └── REASONING [Logic Tree]
        β”œβ”€β”€ PERCEPTION [Sensor Array ~55px]
        β”‚   β”œβ”€β”€ VISION [Eye Matrix]
        β”‚   └── LANGUAGE [Word Web]
        β”œβ”€β”€ INTERACTION [Connect Hub ~50px]
        β”‚   β”œβ”€β”€ HUMAN [Bridge Link]
        β”‚   └── MACHINE [Code Path]
        └── EVOLUTION
            β”œβ”€β”€ CONSCIOUSNESS [Mind Spark]
            └── CREATIVITY [Art Core]""",
        "width": 1024,
        "height": 1024
    }
]

# Convert examples to Gradio format
GRADIO_EXAMPLES = [
    [example["prompt"], example["width"], example["height"]]
    for example in EXAMPLES
]

@spaces.GPU()  # 이 λ°μ½”λ ˆμ΄ν„°λ₯Ό λ‹€μ‹œ μΆ”κ°€
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
    if randomize_seed:
        seed = random.randint(0, MAX_SEED)
    generator = torch.Generator().manual_seed(seed)
    image = pipe(
        prompt=prompt,
        width=width,
        height=height,
        num_inference_steps=num_inference_steps,
        generator=generator,
        guidance_scale=0.0
    ).images[0]
    return image, seed

# CSS μŠ€νƒ€μΌ μˆ˜μ •
css = """
.container {
    display: flex;
    flex-direction: row;
    height: 100%;
}

.input-column {
    flex: 1;
    padding: 20px;
    border-right: 2px solid #eee;
    max-width: 800px;  /* μ¦κ°€λœ μ΅œλŒ€ λ„ˆλΉ„ */
}

.examples-column {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f7f7f7;
}

.title {
    text-align: center;
    color: #2a2a2a;
    padding: 20px;
    font-size: 2.5em;
    font-weight: bold;
    background: linear-gradient(90deg, #f0f0f0 0%, #ffffff 100%);
    border-bottom: 3px solid #ddd;
    margin-bottom: 30px;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
}

.input-box {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    width: 100%;  /* 전체 λ„ˆλΉ„ μ‚¬μš© */
}

/* ν…μŠ€νŠΈ μž…λ ₯ λ°•μŠ€ μŠ€νƒ€μΌ */
.input-box textarea {
    width: 100% !important;  /* κ°•μ œ λ„ˆλΉ„ 100% */
    min-width: 600px !important;  /* μ΅œμ†Œ λ„ˆλΉ„ μ„€μ • */
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding: 12px !important;
}

.example-card {
    background: white;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.example-title {
    font-weight: bold;
    color: #2a2a2a;
    margin-bottom: 10px;
}

/* λ ˆμ΄μ•„μ›ƒ μ‘°μ • */
.contain {
    max-width: 1400px !important;  /* 전체 μ»¨ν…Œμ΄λ„ˆ λ„ˆλΉ„ 증가 */
    margin: 0 auto !important;
}

/* μž…λ ₯ μ˜μ—­ μ‘°μ • */
.input-area {
    flex: 2 !important;  /* μž…λ ₯ μ˜μ—­ λΉ„μœ¨ 증가 */
}

/* 예제 μ˜μ—­ μ‘°μ • */
.examples-area {
    flex: 1 !important;
}
"""


# Gradio μΈν„°νŽ˜μ΄μŠ€ μˆ˜μ •
with gr.Blocks(css=css) as demo:
    gr.Markdown(
        """
        <div class="title">FLUX Mindmap Generator</div>
        <div class="subtitle">Create beautiful hand-drawn style diagrams using FLUX AI</div>
        """)


    
    with gr.Row(equal_height=True) as main_row:
        # μ™Όμͺ½ μž…λ ₯ 컬럼
        with gr.Column(elem_id="input-column", scale=2):  # scale κ°’ 증가
            with gr.Group(elem_classes="input-box"):
                prompt = gr.Text(
                    label="Diagram Prompt",
                    placeholder="Enter your diagram structure...",
                    lines=10,  # 쀄 수 증가
                    elem_classes="prompt-input"  # CSS 클래슀 μΆ”κ°€
                )
   
                run_button = gr.Button("Generate Diagram", variant="primary")
                result = gr.Image(label="Generated Diagram")
            
            with gr.Accordion("Advanced Settings", open=False):
                seed = gr.Slider(
                    label="Seed",
                    minimum=0,
                    maximum=MAX_SEED,
                    step=1,
                    value=0,
                )
                randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
                
                with gr.Row():
                    width = gr.Slider(
                        label="Width",
                        minimum=256,
                        maximum=MAX_IMAGE_SIZE,
                        step=32,
                        value=1024,
                    )
                    height = gr.Slider(
                        label="Height",
                        minimum=256,
                        maximum=MAX_IMAGE_SIZE,
                        step=32,
                        value=1024,
                    )
                
                num_inference_steps = gr.Slider(
                    label="Number of inference steps",
                    minimum=1,
                    maximum=50,
                    step=1,
                    value=4,
                )
        
        # 였λ₯Έμͺ½ 예제 컬럼
        with gr.Column(elem_id="examples-column", scale=1):
            gr.Markdown("### Example Diagrams")
            for example in EXAMPLES:
                with gr.Group(elem_classes="example-card"):
                    gr.Markdown(f"#### {example['title']}")
                    gr.Markdown(f"```\n{example['prompt']}\n```")
                    
                    def create_example_handler(ex):
                        def handler():
                            return {
                                prompt: ex["prompt"],
                                width: ex["width"],
                                height: ex["height"]
                            }
                        return handler
                    
                    gr.Button("Use This Example", size="sm").click(
                        fn=create_example_handler(example),
                        outputs=[prompt, width, height]
                    )

    gr.on(
        triggers=[run_button.click, prompt.submit],
        fn=infer,
        inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
        outputs=[result, seed]
    )

# μ•± μ‹€ν–‰
if __name__ == "__main__":
    demo.queue()
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        show_error=True,
        debug=True
    )