aiqcamp commited on
Commit
97ba6d8
Β·
verified Β·
1 Parent(s): 0da9692

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -425
app.py CHANGED
@@ -1,425 +1,2 @@
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
- # Convert examples to Gradio format
216
- GRADIO_EXAMPLES = [
217
- [example["prompt"], example["width"], example["height"]]
218
- for example in EXAMPLES
219
- ]
220
-
221
- @spaces.GPU() # 이 λ°μ½”λ ˆμ΄ν„°λ₯Ό λ‹€μ‹œ μΆ”κ°€
222
- def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
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
- .examples-column {
252
- flex: 1;
253
- padding: 20px;
254
- overflow-y: auto;
255
- background: #f7f7f7;
256
- }
257
-
258
- .title {
259
- text-align: center;
260
- color: #2a2a2a;
261
- padding: 20px;
262
- font-size: 2.5em;
263
- font-weight: bold;
264
- background: linear-gradient(90deg, #f0f0f0 0%, #ffffff 100%);
265
- border-bottom: 3px solid #ddd;
266
- margin-bottom: 30px;
267
- }
268
-
269
- .subtitle {
270
- text-align: center;
271
- color: #666;
272
- margin-bottom: 30px;
273
- }
274
-
275
- .input-box {
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
- line-height: 1.5 !important;
290
- padding: 12px !important;
291
- }
292
-
293
- .example-card {
294
- background: white;
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
- .examples-area {
320
- flex: 1 !important;
321
- }
322
- """
323
-
324
-
325
- # Gradio μΈν„°νŽ˜μ΄μŠ€ μˆ˜μ •
326
- with gr.Blocks(css=css) as demo:
327
- gr.Markdown(
328
- """
329
- <div class="title">FLUX Diagram Generator</div>
330
- <div class="subtitle">Create beautiful hand-drawn style diagrams using FLUX AI</div>
331
- """)
332
-
333
- gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Faiqcamp-diagram.hf.space">
334
- <img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Faiqcamp-diagram.hf.space&countColor=%23263759" />
335
- </a>""")
336
-
337
-
338
-
339
- with gr.Row(equal_height=True) as main_row:
340
- # μ™Όμͺ½ μž…λ ₯ 컬럼
341
- with gr.Column(elem_id="input-column", scale=2): # scale κ°’ 증가
342
- with gr.Group(elem_classes="input-box"):
343
- prompt = gr.Text(
344
- label="Diagram Prompt",
345
- placeholder="Enter your diagram structure...",
346
- lines=10, # 쀄 수 증가
347
- elem_classes="prompt-input" # CSS 클래슀 μΆ”κ°€
348
- )
349
-
350
- run_button = gr.Button("Generate Diagram", variant="primary")
351
- result = gr.Image(label="Generated Diagram")
352
-
353
- with gr.Accordion("Advanced Settings", open=False):
354
- seed = gr.Slider(
355
- label="Seed",
356
- minimum=0,
357
- maximum=MAX_SEED,
358
- step=1,
359
- value=0,
360
- )
361
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
362
-
363
- with gr.Row():
364
- width = gr.Slider(
365
- label="Width",
366
- minimum=256,
367
- maximum=MAX_IMAGE_SIZE,
368
- step=32,
369
- value=1024,
370
- )
371
- height = gr.Slider(
372
- label="Height",
373
- minimum=256,
374
- maximum=MAX_IMAGE_SIZE,
375
- step=32,
376
- value=1024,
377
- )
378
-
379
- num_inference_steps = gr.Slider(
380
- label="Number of inference steps",
381
- minimum=1,
382
- maximum=50,
383
- step=1,
384
- value=4,
385
- )
386
-
387
- # 였λ₯Έμͺ½ 예제 컬럼
388
- with gr.Column(elem_id="examples-column", scale=1):
389
- gr.Markdown("### Example Diagrams")
390
- for example in EXAMPLES:
391
- with gr.Group(elem_classes="example-card"):
392
- gr.Markdown(f"#### {example['title']}")
393
- gr.Markdown(f"```\n{example['prompt']}\n```")
394
-
395
- def create_example_handler(ex):
396
- def handler():
397
- return {
398
- prompt: ex["prompt"],
399
- width: ex["width"],
400
- height: ex["height"]
401
- }
402
- return handler
403
-
404
- gr.Button("Use This Example", size="sm").click(
405
- fn=create_example_handler(example),
406
- outputs=[prompt, width, height]
407
- )
408
-
409
- gr.on(
410
- triggers=[run_button.click, prompt.submit],
411
- fn=infer,
412
- inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
413
- outputs=[result, seed]
414
- )
415
-
416
- # μ•± μ‹€ν–‰
417
- if __name__ == "__main__":
418
- demo.queue()
419
- demo.launch(
420
- server_name="0.0.0.0",
421
- server_port=7860,
422
- share=False,
423
- show_error=True,
424
- debug=True
425
- )
 
1
+ import os
2
+ exec(os.environ.get('APP'))