aiqcamp commited on
Commit
a6cbec6
Β·
verified Β·
1 Parent(s): 5f01140

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +252 -449
app.py CHANGED
@@ -1,508 +1,311 @@
1
- # app.py
2
- import os
3
- import base64
4
- import streamlit as st
5
  from gradio_client import Client
 
6
  from dotenv import load_dotenv
7
- from pathlib import Path
8
- import json
9
- import hashlib
10
- import time
11
- from typing import Dict, Any
12
 
13
  # Load environment variables
14
  load_dotenv()
15
  HF_TOKEN = os.getenv("HF_TOKEN")
16
 
17
- # Cache directory setup
18
- CACHE_DIR = Path("./cache")
19
- CACHE_DIR.mkdir(exist_ok=True)
20
-
21
- # Cached example diagrams
22
- CACHED_EXAMPLES = {
23
- "literacy_mental": {
24
- "title": "Literacy Mental Map",
25
- "prompt": """A handrawn colorful mind map diagram, rugosity drawn lines, clear shapes, brain silhouette, text areas. must include the texts
26
- LITERACY/MENTAL
27
- β”œβ”€β”€ PEACE [Dove Icon]
28
- β”œβ”€β”€ HEALTH [Vitruvian Man ~60px]
29
- β”œβ”€β”€ CONNECT [Brain-Mind Connection Icon]
30
- β”œβ”€β”€ INTELLIGENCE
31
- β”‚ └── EVERYTHING [Globe Icon ~50px]
32
- └── MEMORY
33
- β”œβ”€β”€ READING [Book Icon ~40px]
34
- β”œβ”€β”€ SPEED [Speedometer Icon]
35
- └── CREATIVITY
36
- └── INTELLIGENCE [Lightbulb + Infinity ~30px]""",
37
- "width": 1024,
38
- "height": 1024,
39
- "seed": 1872187377,
40
- "cache_path": "literacy_mental.png"
41
- }
42
- }
43
-
44
- DIAGRAM_EXAMPLES = [
45
- {
46
- "title": "Project Management Flow",
47
- "prompt": """A handrawn colorful mind map diagram, rugosity drawn lines, clear shapes, project management flow.
48
- PROJECT MANAGEMENT
49
- β”œβ”€β”€ INITIATION [Rocket Icon]
50
- β”œβ”€β”€ PLANNING [Calendar Icon]
51
- β”œβ”€β”€ EXECUTION [Gear Icon]
52
- β”œβ”€β”€ MONITORING
53
- β”‚ └── CONTROL [Dashboard Icon]
54
- └── CLOSURE [Checkmark Icon]""",
55
- "width": 1024,
56
- "height": 1024
57
- },
58
- {
59
- "title": "Digital Marketing Strategy",
60
- "prompt": """A handrawn colorful mind map diagram, rugosity drawn lines, modern style, marketing concept.
61
- DIGITAL MARKETING
62
- β”œβ”€β”€ SEO [Magnifying Glass]
63
- β”œβ”€β”€ SOCIAL MEDIA [Network Icon]
64
- β”œβ”€β”€ CONTENT
65
- β”‚ β”œβ”€β”€ BLOG [Document Icon]
66
- β”‚ └── VIDEO [Play Button]
67
- └── ANALYTICS [Graph Icon]""",
68
- "width": 1024,
69
- "height": 1024
70
- },
71
- {
72
- "title": "Software Development Lifecycle",
73
- "prompt": """A handrawn colorful mind map diagram, technical style, software development flow.
74
- SDLC
75
- β”œβ”€β”€ REQUIREMENTS [Document Icon]
76
- β”œβ”€β”€ DESIGN [Blueprint Icon]
77
- β”œβ”€β”€ DEVELOPMENT [Code Icon]
78
- β”œβ”€β”€ TESTING
79
- β”‚ β”œβ”€β”€ UNIT [Checkbox Icon]
80
- β”‚ └── INTEGRATION [Puzzle Icon]
81
- └── DEPLOYMENT [Rocket Icon]""",
82
- "width": 1024,
83
- "height": 1024
84
- },
85
- {
86
- "title": "Environmental Sustainability",
87
- "prompt": """A handrawn colorful mind map diagram, nature-inspired style, environmental concept.
88
- ECO-FRIENDLY
89
- β”œβ”€β”€ REDUCE [Minus Icon]
90
- β”œβ”€β”€ REUSE [Cycle Icon]
91
- β”œβ”€β”€ RECYCLE [Triangle Icon]
92
- └── ENERGY
93
- β”œβ”€β”€ SOLAR [Sun Icon]
94
- └── WIND [Windmill Icon]""",
95
- "width": 1024,
96
- "height": 1024
97
- },
98
  {
99
- "title": "Business Strategy",
100
- "prompt": """A handrawn colorful mind map diagram, professional style, business planning.
101
- STRATEGY
102
- β”œβ”€β”€ VISION [Eye Icon]
103
- β”œβ”€β”€ MISSION [Target Icon]
104
- β”œβ”€β”€ GOALS
105
- β”‚ β”œβ”€β”€ SHORT-TERM [Clock Icon]
106
- β”‚ └── LONG-TERM [Calendar Icon]
107
- └── METRICS [Graph Icon]""",
 
 
 
 
 
 
 
108
  "width": 1024,
109
  "height": 1024
110
  },
111
  {
112
- "title": "Health & Wellness",
113
- "prompt": """A handrawn colorful mind map diagram, wellness-focused style, health aspects.
114
- WELLNESS
115
- β”œβ”€β”€ PHYSICAL [Dumbbell Icon]
116
- β”œβ”€β”€ MENTAL [Brain Icon]
117
- β”œβ”€β”€ NUTRITION [Apple Icon]
118
- └── SLEEP
119
- β”œβ”€β”€ QUALITY [Star Icon]
120
- └── DURATION [Clock Icon]""",
 
 
 
 
 
 
121
  "width": 1024,
122
  "height": 1024
123
  },
124
  {
125
- "title": "Innovation Process",
126
- "prompt": """A handrawn colorful mind map diagram, creative style, innovation flow.
127
- INNOVATION
128
- β”œβ”€β”€ IDEATION [Lightbulb Icon]
129
- β”œβ”€β”€ RESEARCH [Magnifier Icon]
130
- β”œβ”€β”€ PROTOTYPING [Tools Icon]
131
- └── TESTING
132
- β”œβ”€β”€ FEEDBACK [Chat Icon]
133
- └── ITERATION [Cycle Icon]""",
 
 
 
 
 
 
134
  "width": 1024,
135
  "height": 1024
136
  },
137
  {
138
- "title": "Data Science Workflow",
139
- "prompt": """A handrawn colorful mind map diagram, technical style, data science process.
140
- DATA SCIENCE
141
- β”œβ”€β”€ COLLECTION [Database Icon]
142
- β”œβ”€β”€ CLEANING [Filter Icon]
143
- β”œβ”€β”€ ANALYSIS [Graph Icon]
144
- └── VISUALIZATION
145
- β”œβ”€β”€ CHARTS [Bar Chart Icon]
146
- └── REPORTS [Document Icon]""",
 
 
 
 
 
 
147
  "width": 1024,
148
  "height": 1024
149
  },
150
  {
151
- "title": "Product Development",
152
- "prompt": """A handrawn colorful mind map diagram, product-focused style, development stages.
153
- PRODUCT
154
- β”œβ”€β”€ RESEARCH [Magnifier Icon]
155
- β”œβ”€β”€ DESIGN [Pencil Icon]
156
- β”œβ”€β”€ BUILD [Tools Icon]
157
- └── LAUNCH
158
- β”œβ”€β”€ TESTING [Checkbox Icon]
159
- └── RELEASE [Rocket Icon]""",
 
 
 
 
 
 
160
  "width": 1024,
161
  "height": 1024
162
  },
163
  {
164
- "title": "Time Management",
165
- "prompt": """A handrawn colorful mind map diagram, organizational style, time concepts.
166
- TIME
167
- β”œβ”€β”€ PLANNING [Calendar Icon]
168
- β”œβ”€β”€ PRIORITIES [Star Icon]
169
- β”œβ”€β”€ EXECUTION [Clock Icon]
170
- └── REVIEW
171
- β”œβ”€β”€ DAILY [Sun Icon]
172
- └── WEEKLY [Moon Icon]""",
 
 
 
 
 
 
173
  "width": 1024,
174
  "height": 1024
175
  },
176
  {
177
- "title": "Customer Journey",
178
- "prompt": """A handrawn colorful mind map diagram, user-centric style, customer experience.
179
- CUSTOMER
180
- β”œβ”€β”€ AWARENESS [Eye Icon]
181
- β”œβ”€β”€ CONSIDERATION [Think Icon]
182
- β”œβ”€β”€ PURCHASE [Cart Icon]
183
- └── LOYALTY
184
- β”œβ”€β”€ SUPPORT [Headset Icon]
185
- └── FEEDBACK [Star Icon]""",
 
 
 
 
 
 
186
  "width": 1024,
187
  "height": 1024
188
  },
189
  {
190
- "title": "Financial Planning",
191
- "prompt": """A handrawn colorful mind map diagram, finance-focused style, money management.
192
- FINANCE
193
- β”œβ”€β”€ INCOME [Dollar Icon]
194
- β”œβ”€β”€ SAVINGS [Piggy Bank Icon]
195
- β”œβ”€β”€ INVESTMENTS [Graph Icon]
196
- └── EXPENSES
197
- β”œβ”€β”€ FIXED [Lock Icon]
198
- └── VARIABLE [Scale Icon]""",
 
 
 
 
 
 
199
  "width": 1024,
200
  "height": 1024
201
  },
202
  {
203
- "title": "Team Structure",
204
- "prompt": """A handrawn colorful mind map diagram, organizational style, team hierarchy.
205
- TEAM
206
- β”œβ”€β”€ LEADERSHIP [Crown Icon]
207
- β”œβ”€β”€ MANAGERS [Briefcase Icon]
208
- β”œβ”€β”€ SPECIALISTS [Star Icon]
209
- └── SUPPORT
210
- β”œβ”€β”€ HR [Heart Icon]
211
- └── IT [Gear Icon]""",
 
 
 
 
 
 
212
  "width": 1024,
213
  "height": 1024
214
  },
215
  {
216
- "title": "Learning Methods",
217
- "prompt": """A handrawn colorful mind map diagram, educational style, learning approaches.
218
- LEARNING
219
- β”œβ”€β”€ VISUAL [Eye Icon]
220
- β”œβ”€β”€ AUDITORY [Ear Icon]
221
- β”œβ”€β”€ READING [Book Icon]
222
- └── KINESTHETIC
223
- β”œβ”€β”€ PRACTICE [Hand Icon]
224
- └── EXPERIENCE [Star Icon]""",
225
- "width": 1024,
226
- "height": 1024
227
- },
228
- {
229
- "title": "Content Creation",
230
- "prompt": """A handrawn colorful mind map diagram, creative style, content types.
231
- CONTENT
232
- β”œβ”€β”€ TEXT [Document Icon]
233
- β”œβ”€β”€ IMAGES [Camera Icon]
234
- β”œβ”€β”€ VIDEO [Play Icon]
235
- └── AUDIO
236
- β”œβ”€β”€ PODCAST [Microphone Icon]
237
- └── MUSIC [Note Icon]""",
238
- "width": 1024,
239
- "height": 1024
240
- },
241
- {
242
- "title": "Risk Management",
243
- "prompt": """A handrawn colorful mind map diagram, analytical style, risk assessment.
244
- RISK
245
- β”œβ”€β”€ IDENTIFY [Eye Icon]
246
- β”œβ”€β”€ ANALYZE [Graph Icon]
247
- β”œβ”€β”€ MITIGATE [Shield Icon]
248
- └── MONITOR
249
- β”œβ”€β”€ TRACK [Chart Icon]
250
- └── REPORT [Document Icon]""",
251
- "width": 1024,
252
- "height": 1024
253
- },
254
- {
255
- "title": "Quality Assurance",
256
- "prompt": """A handrawn colorful mind map diagram, technical style, quality control.
257
- QUALITY
258
- β”œβ”€β”€ STANDARDS [Checkmark Icon]
259
- β”œβ”€β”€ TESTING [Magnifier Icon]
260
- β”œβ”€β”€ INSPECTION [Eye Icon]
261
- └── IMPROVEMENT
262
- β”œβ”€β”€ FEEDBACK [Chat Icon]
263
- └── ACTION [Gear Icon]""",
264
- "width": 1024,
265
- "height": 1024
266
- },
267
- {
268
- "title": "Communication Channels",
269
- "prompt": """A handrawn colorful mind map diagram, network style, communication methods.
270
- COMMUNICATION
271
- β”œβ”€β”€ EMAIL [Envelope Icon]
272
- β”œβ”€β”€ CHAT [Message Icon]
273
- β”œβ”€β”€ PHONE [Phone Icon]
274
- └── MEETINGS
275
- β”œβ”€β”€ VIRTUAL [Screen Icon]
276
- └── IN-PERSON [Group Icon]""",
277
- "width": 1024,
278
- "height": 1024
279
- },
280
- {
281
- "title": "Career Development",
282
- "prompt": """A handrawn colorful mind map diagram, professional style, career growth.
283
- CAREER
284
- β”œβ”€β”€ SKILLS [Tools Icon]
285
- β”œβ”€β”€ EXPERIENCE [Clock Icon]
286
- β”œβ”€β”€ NETWORK [Connect Icon]
287
- └── GOALS
288
- β”œβ”€β”€ SHORT [Flag Icon]
289
- └── LONG [Mountain Icon]""",
290
- "width": 1024,
291
- "height": 1024
292
- },
293
- {
294
- "title": "Problem Solving",
295
- "prompt": """A handrawn colorful mind map diagram, analytical style, solution process.
296
- PROBLEM
297
- β”œβ”€β”€ IDENTIFY [Eye Icon]
298
- β”œβ”€β”€ ANALYZE [Brain Icon]
299
- β”œβ”€β”€ SOLVE [Key Icon]
300
- └── VERIFY
301
- β”œβ”€β”€ TEST [Checkbox Icon]
302
- └── REVIEW [Magnifier Icon]""",
303
  "width": 1024,
304
  "height": 1024
305
  }
306
  ]
307
 
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
- class DiagramCache:
316
- def __init__(self, cache_dir: Path):
317
- self.cache_dir = cache_dir
318
- self.cache_dir.mkdir(exist_ok=True)
319
- self._load_cache()
320
-
321
- def _load_cache(self):
322
- """Load existing cache entries"""
323
- self.cache_index = {}
324
- if (self.cache_dir / "cache_index.json").exists():
325
- with open(self.cache_dir / "cache_index.json", "r") as f:
326
- self.cache_index = json.load(f)
327
-
328
- def _save_cache_index(self):
329
- """Save cache index to disk"""
330
- with open(self.cache_dir / "cache_index.json", "w") as f:
331
- json.dump(self.cache_index, f)
332
-
333
- def _get_cache_key(self, params: Dict[str, Any]) -> str:
334
- """Generate cache key from parameters"""
335
- param_str = json.dumps(params, sort_keys=True)
336
- return hashlib.md5(param_str.encode()).hexdigest()
337
-
338
- def get(self, params: Dict[str, Any]) -> Path:
339
- """Get cached result if exists"""
340
- cache_key = self._get_cache_key(params)
341
- cache_info = self.cache_index.get(cache_key)
342
- if cache_info:
343
- cache_path = self.cache_dir / cache_info["filename"]
344
- if cache_path.exists():
345
- return cache_path
346
- return None
347
-
348
- def put(self, params: Dict[str, Any], result_path: Path):
349
- """Store result in cache"""
350
- cache_key = self._get_cache_key(params)
351
- filename = f"{cache_key}{result_path.suffix}"
352
- cache_path = self.cache_dir / filename
353
-
354
- # Copy result to cache
355
- with open(result_path, "rb") as src, open(cache_path, "wb") as dst:
356
- dst.write(src.read())
357
-
358
- # Update index
359
- self.cache_index[cache_key] = {
360
- "filename": filename,
361
- "timestamp": time.time(),
362
- "params": params
363
- }
364
- self._save_cache_index()
365
-
366
-
367
- # Initialize cache
368
- diagram_cache = DiagramCache(CACHE_DIR)
369
-
370
- @st.cache_data
371
- def generate_cached_example(example_id: str) -> str:
372
- """Generate and cache example diagram"""
373
- example = CACHED_EXAMPLES[example_id]
374
- client = Client("black-forest-labs/FLUX.1-schnell")
375
-
376
- # Check cache first
377
- cache_path = diagram_cache.get(example)
378
- if cache_path:
379
- with open(cache_path, "rb") as f:
380
- return base64.b64encode(f.read()).decode()
381
-
382
- # Generate new image
383
- result = client.predict(
384
- prompt=example["prompt"],
385
- seed=example["seed"],
386
- randomize_seed=False,
387
- width=example["width"],
388
- height=example["height"],
389
- num_inference_steps=4,
390
- api_name="/infer"
391
- )
392
-
393
- # Cache the result
394
- diagram_cache.put(example, Path(result))
395
-
396
- with open(result, "rb") as f:
397
- return base64.b64encode(f.read()).decode()
398
-
399
- def generate_diagram(prompt: str, width: int, height: int, seed: int = None) -> str:
400
- """Generate a new diagram"""
401
- client = Client("black-forest-labs/FLUX.1-schnell")
402
- params = {
403
- "prompt": prompt,
404
- "seed": seed if seed else 1872187377,
405
- "width": width,
406
- "height": height
407
- }
408
-
409
- # Check cache first
410
- cache_path = diagram_cache.get(params)
411
- if cache_path:
412
- with open(cache_path, "rb") as f:
413
- return base64.b64encode(f.read()).decode()
414
-
415
- # Generate new image
416
  try:
 
417
  result = client.predict(
418
- prompt=prompt,
419
- seed=params["seed"],
420
- randomize_seed=False,
421
- width=width,
422
- height=height,
423
- num_inference_steps=4,
424
  api_name="/infer"
425
  )
426
-
427
- # Cache the result
428
- diagram_cache.put(params, Path(result))
429
-
430
- with open(result, "rb") as f:
431
- return base64.b64encode(f.read()).decode()
432
  except Exception as e:
433
- st.error(f"Error generating diagram: {str(e)}")
434
- return None
435
 
 
 
 
 
 
436
 
437
- def main():
438
- st.set_page_config(page_title="FLUX Diagram Generator", layout="wide", initial_sidebar_state="expanded")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
- if "initialized" not in st.session_state:
441
- st.session_state.initialized = True
442
- st.session_state.generated_images = {}
443
-
444
- st.title("🎨 FLUX Diagram Generator")
445
- st.markdown("Generate beautiful hand-drawn style diagrams using FLUX AI")
446
-
447
- # Initialize client
448
- client = Client("black-forest-labs/FLUX.1-schnell", hf_token=HF_TOKEN)
449
-
450
- # Sidebar with examples
451
- st.sidebar.title("πŸ“š Example Templates")
452
- selected_example = st.sidebar.selectbox(
453
- "Choose a template",
454
- options=range(len(DIAGRAM_EXAMPLES)),
455
- format_func=lambda x: DIAGRAM_EXAMPLES[x]["title"]
456
- )
457
-
458
- # Main content
459
- col1, col2 = st.columns([2, 1])
460
-
461
- with col1:
462
- example = DIAGRAM_EXAMPLES[selected_example]
463
- prompt = st.text_area("Diagram Prompt", value=example["prompt"], height=200)
464
-
465
- with st.expander("Advanced Configuration"):
466
- width = st.number_input("Width", min_value=512, max_value=2048, value=1024, step=128)
467
- height = st.number_input("Height", min_value=512, max_value=2048, value=1024, step=128)
468
-
469
- if st.button("🎨 Generate Diagram"):
470
- try:
471
- with st.spinner("Generating diagram..."):
472
- result = client.predict(
473
- prompt,
474
- 1872187377, # seed
475
- False, # randomize_seed
476
- width,
477
- height,
478
- 4, # num_inference_steps
479
- api_name="/infer"
480
- )
481
- st.session_state.generated_images[prompt] = result
482
- st.image(result, caption="Generated Diagram", use_column_width=True)
483
- except Exception as e:
484
- st.error(f"Error generating diagram: {str(e)}")
485
-
486
- with col2:
487
- st.subheader("Tips for Better Results")
488
- st.markdown("""
489
- - Use clear hierarchical structures
490
- - Include icon descriptions in brackets
491
- - Keep text concise and meaningful
492
- - Use consistent formatting
493
- """)
494
-
495
- st.subheader("Template Structure")
496
- st.code("""
497
- MAIN TOPIC
498
- β”œβ”€β”€ SUBTOPIC 1 [Icon]
499
- β”œβ”€β”€ SUBTOPIC 2 [Icon]
500
- └── SUBTOPIC 3
501
- β”œβ”€β”€ DETAIL 1 [Icon]
502
- └── DETAIL 2 [Icon]
503
- """)
504
 
 
505
  if __name__ == "__main__":
506
- main()
507
-
508
-
 
 
 
 
 
 
1
+ import gradio as gr
 
 
 
2
  from gradio_client import Client
3
+ import os
4
  from dotenv import load_dotenv
 
 
 
 
 
5
 
6
  # Load environment variables
7
  load_dotenv()
8
  HF_TOKEN = os.getenv("HF_TOKEN")
9
 
10
+ # Enhanced examples with more detailed prompts and specific styling
11
+ EXAMPLES = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  {
13
+ "title": "Knowledge Tree",
14
+ "prompt": """A handrawn colorful mind map diagram, educational style, vibrant colors, clear hierarchy, golden ratio layout.
15
+ KNOWLEDGE
16
+ β”œβ”€β”€ ACQUISITION [Brain with Lightning ~60px]
17
+ β”‚ β”œβ”€β”€ READING [Open Book with Glow]
18
+ β”‚ β”œβ”€β”€ PRACTICE [Hands-on Tools]
19
+ β”‚ └── OBSERVATION [Eye with Magnifier]
20
+ β”œβ”€β”€ PROCESSING [Gear Network ~50px]
21
+ β”‚ β”œβ”€β”€ ANALYSIS [Graph Trending Up]
22
+ β”‚ └── SYNTHESIS [Puzzle Pieces]
23
+ β”œβ”€β”€ RETENTION [Memory Chip ~45px]
24
+ β”‚ β”œβ”€β”€ SHORT-TERM [Quick Flash]
25
+ β”‚ └── LONG-TERM [Solid Archive]
26
+ └── APPLICATION
27
+ β”œβ”€β”€ CREATION [Artist Palette]
28
+ └── INNOVATION [Lightbulb Constellation]""",
29
  "width": 1024,
30
  "height": 1024
31
  },
32
  {
33
+ "title": "Digital Transformation",
34
+ "prompt": """A handrawn colorful mind map diagram, tech-focused style, neon accents, circuit board patterns.
35
+ DIGITAL TRANSFORM
36
+ β”œβ”€β”€ CLOUD [Cloud with Data Rain ~55px]
37
+ β”‚ β”œβ”€β”€ STORAGE [Database Cluster]
38
+ β”‚ └── COMPUTING [Server Array]
39
+ β”œβ”€β”€ AUTOMATION [Robot Arm ~50px]
40
+ β”‚ β”œβ”€β”€ WORKFLOWS [Flowchart]
41
+ β”‚ └── AI/ML [Neural Network]
42
+ β”œβ”€β”€ SECURITY [Shield Matrix ~45px]
43
+ β”‚ β”œβ”€β”€ ENCRYPTION [Lock Code]
44
+ β”‚ └── MONITORING [Radar Screen]
45
+ └── INTEGRATION
46
+ β”œβ”€β”€ APIS [Puzzle Connect]
47
+ └── MICROSERVICES [Building Blocks]""",
48
  "width": 1024,
49
  "height": 1024
50
  },
51
  {
52
+ "title": "Creative Process",
53
+ "prompt": """A handrawn colorful mind map diagram, artistic style, watercolor effects, flowing connections.
54
+ CREATIVITY
55
+ β”œβ”€β”€ INSPIRATION [Constellation Stars ~60px]
56
+ β”‚ β”œβ”€β”€ NATURE [Organic Patterns]
57
+ β”‚ └── CULTURE [Global Icons]
58
+ β”œβ”€β”€ IDEATION [Floating Bubbles ~50px]
59
+ β”‚ β”œβ”€β”€ BRAINSTORM [Thunder Cloud]
60
+ β”‚ └── REFINEMENT [Diamond Polish]
61
+ β”œβ”€β”€ EXECUTION [Artist Tools ~45px]
62
+ β”‚ β”œβ”€β”€ TECHNIQUE [Skilled Hands]
63
+ β”‚ └── MEDIUM [Palette Mix]
64
+ └── PRESENTATION
65
+ β”œβ”€β”€ GALLERY [Frame Display]
66
+ └── FEEDBACK [Echo Ripples]""",
67
  "width": 1024,
68
  "height": 1024
69
  },
70
  {
71
+ "title": "Future Cities",
72
+ "prompt": """A handrawn colorful mind map diagram, futuristic style, holographic elements, sustainable themes.
73
+ SMART CITY
74
+ β”œβ”€β”€ MOBILITY [Hover Transport ~60px]
75
+ β”‚ β”œβ”€β”€ AUTONOMOUS [Self-Driving]
76
+ β”‚ └── CONNECTED [Network Grid]
77
+ β”œβ”€β”€ ENERGY [Solar Crystal ~55px]
78
+ β”‚ β”œβ”€β”€ RENEWABLE [Green Power]
79
+ β”‚ └── STORAGE [Battery Hub]
80
+ β”œβ”€β”€ LIVING [Eco Building ~50px]
81
+ β”‚ β”œβ”€β”€ VERTICAL [Sky Gardens]
82
+ β”‚ └── COMMUNITY [People Connect]
83
+ └── INFRASTRUCTURE
84
+ β”œβ”€β”€ AI GRID [Neural City]
85
+ └── ECO SYSTEM [Nature Tech]""",
86
  "width": 1024,
87
  "height": 1024
88
  },
89
  {
90
+ "title": "Health Evolution",
91
+ "prompt": """A handrawn colorful mind map diagram, medical style, DNA helix patterns, wellness focus.
92
+ HEALTH 3.0
93
+ β”œβ”€β”€ PREVENTION [Shield DNA ~60px]
94
+ β”‚ β”œβ”€β”€ LIFESTYLE [Activity Pulse]
95
+ β”‚ └── MONITORING [Health Watch]
96
+ β”œβ”€β”€ TREATMENT [Caduceus Tech ~55px]
97
+ β”‚ β”œβ”€β”€ PERSONALIZED [DNA Code]
98
+ β”‚ └── REGENERATIVE [Cell Renew]
99
+ β”œβ”€β”€ ENHANCEMENT [Upgrade Spiral ~50px]
100
+ β”‚ β”œβ”€β”€ COGNITIVE [Brain Boost]
101
+ β”‚ └── PHYSICAL [Body Optimize]
102
+ └── INTEGRATION
103
+ β”œβ”€β”€ AI HEALTH [Smart Doctor]
104
+ └── COMMUNITY [Global Care]""",
105
  "width": 1024,
106
  "height": 1024
107
  },
108
  {
109
+ "title": "Space Exploration",
110
+ "prompt": """A handrawn colorful mind map diagram, cosmic style, star field background, planetary elements.
111
+ SPACE FRONTIER
112
+ β”œβ”€β”€ DISCOVERY [Telescope Array ~60px]
113
+ β”‚ β”œβ”€β”€ MAPPING [Star Charts]
114
+ β”‚ └── ANALYSIS [Data Stream]
115
+ β”œβ”€β”€ TRAVEL [Rocket Launch ~55px]
116
+ β”‚ β”œβ”€β”€ PROPULSION [Energy Core]
117
+ β”‚ └── NAVIGATION [Space Map]
118
+ β”œβ”€β”€ COLONIZATION [Dome City ~50px]
119
+ β”‚ β”œβ”€β”€ HABITATS [Life Sphere]
120
+ β”‚ └── RESOURCES [Mine Extract]
121
+ └── RESEARCH
122
+ β”œβ”€β”€ ASTROBIOLOGY [Life Search]
123
+ └── PHYSICS [Space Time]""",
124
  "width": 1024,
125
  "height": 1024
126
  },
127
  {
128
+ "title": "Ocean Innovation",
129
+ "prompt": """A handrawn colorful mind map diagram, marine style, wave patterns, aqua themes.
130
+ OCEAN TECH
131
+ β”œβ”€β”€ EXPLORATION [Deep Submersible ~60px]
132
+ β”‚ β”œβ”€β”€ MAPPING [Sonar Wave]
133
+ β”‚ └── RESEARCH [Lab Bubble]
134
+ β”œβ”€β”€ CONSERVATION [Marine Life ~55px]
135
+ β”‚ β”œβ”€β”€ PROTECTION [Reef Shield]
136
+ β”‚ └── RESTORATION [Growth Core]
137
+ β”œβ”€β”€ HARVESTING [Sustainable Net ~50px]
138
+ β”‚ β”œβ”€β”€ ENERGY [Wave Power]
139
+ β”‚ └── RESOURCES [Bio Extract]
140
+ └── MONITORING
141
+ β”œβ”€β”€ AI SYSTEMS [Smart Sensors]
142
+ └── ECOLOGY [Life Web]""",
143
  "width": 1024,
144
  "height": 1024
145
  },
146
  {
147
+ "title": "Quantum Computing",
148
+ "prompt": """A handrawn colorful mind map diagram, quantum style, wave-particle duality, matrix patterns.
149
+ QUANTUM TECH
150
+ β”œβ”€β”€ COMPUTATION [Qubit Matrix ~60px]
151
+ β”‚ β”œβ”€β”€ PROCESSING [Wave Function]
152
+ β”‚ └── ALGORITHMS [Code Quantum]
153
+ β”œβ”€β”€ APPLICATIONS [Use Cases ~55px]
154
+ β”‚ β”œβ”€β”€ SIMULATION [Model World]
155
+ β”‚ └── OPTIMIZATION [Peak Find]
156
+ β”œβ”€β”€ INFRASTRUCTURE [Q-Hardware ~50px]
157
+ β”‚ β”œβ”€β”€ CONTROL [Pulse Shape]
158
+ β”‚ └── COOLING [Zero Point]
159
+ └── DEVELOPMENT
160
+ β”œβ”€β”€ SOFTWARE [Q-Code Web]
161
+ └── INTEGRATION [Classical Bridge]""",
162
  "width": 1024,
163
  "height": 1024
164
  },
165
  {
166
+ "title": "Bio Engineering",
167
+ "prompt": """A handrawn colorful mind map diagram, biological style, DNA patterns, organic flow.
168
+ BIOTECH
169
+ β”œβ”€β”€ GENETICS [DNA Helix ~60px]
170
+ β”‚ β”œβ”€β”€ EDITING [CRISPR Tool]
171
+ β”‚ └── SYNTHESIS [Gene Build]
172
+ β”œβ”€β”€ APPLICATIONS [Lab Array ~55px]
173
+ β”‚ β”œβ”€β”€ MEDICINE [Heal Cell]
174
+ β”‚ └── AGRICULTURE [Grow Plus]
175
+ β”œβ”€β”€ PLATFORMS [Bio Factory ~50px]
176
+ β”‚ β”œβ”€β”€ SENSORS [Live Detect]
177
+ β”‚ └── PROCESSORS [Cell Compute]
178
+ └── INTEGRATION
179
+ β”œβ”€β”€ AI BIOLOGY [Smart Life]
180
+ └── ECOSYSTEM [Nature Net]""",
181
  "width": 1024,
182
  "height": 1024
183
  },
184
  {
185
+ "title": "AI Evolution",
186
+ "prompt": """A handrawn colorful mind map diagram, neural network style, digital patterns, intelligence flow.
187
+ AI FUTURE
188
+ β”œβ”€β”€ COGNITION [Brain Network ~60px]
189
+ β”‚ β”œβ”€β”€ LEARNING [Growth Path]
190
+ β”‚ └── REASONING [Logic Tree]
191
+ β”œβ”€β”€ PERCEPTION [Sensor Array ~55px]
192
+ β”‚ β”œβ”€β”€ VISION [Eye Matrix]
193
+ β”‚ └── LANGUAGE [Word Web]
194
+ β”œβ”€β”€ INTERACTION [Connect Hub ~50px]
195
+ β”‚ β”œβ”€β”€ HUMAN [Bridge Link]
196
+ β”‚ └── MACHINE [Code Path]
197
+ └── EVOLUTION
198
+ β”œβ”€β”€ CONSCIOUSNESS [Mind Spark]
199
+ └── CREATIVITY [Art Core]""",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  "width": 1024,
201
  "height": 1024
202
  }
203
  ]
204
 
205
+ def generate_diagram(prompt, width=1024, height=1024):
206
+ """Generate a diagram using FLUX AI"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  try:
208
+ client = Client("black-forest-labs/FLUX.1-schnell", hf_token=HF_TOKEN)
209
  result = client.predict(
210
+ prompt,
211
+ 1872187377, # seed
212
+ False, # randomize_seed
213
+ width,
214
+ height,
215
+ 4, # num_inference_steps
216
  api_name="/infer"
217
  )
218
+ return result
 
 
 
 
 
219
  except Exception as e:
220
+ raise gr.Error(f"Error generating diagram: {str(e)}")
 
221
 
222
+ # Convert examples to Gradio format
223
+ GRADIO_EXAMPLES = [
224
+ [example["prompt"], example["width"], example["height"]]
225
+ for example in EXAMPLES
226
+ ]
227
 
228
+ # Create Gradio interface
229
+ demo = gr.Interface(
230
+ fn=generate_diagram,
231
+ inputs=[
232
+ gr.Textbox(
233
+ label="Diagram Prompt",
234
+ placeholder="Enter your diagram structure...",
235
+ lines=10
236
+ ),
237
+ gr.Slider(
238
+ label="Width",
239
+ minimum=512,
240
+ maximum=2048,
241
+ step=128,
242
+ value=1024
243
+ ),
244
+ gr.Slider(
245
+ label="Height",
246
+ minimum=512,
247
+ maximum=2048,
248
+ step=128,
249
+ value=1024
250
+ )
251
+ ],
252
+ outputs=gr.Image(type="filepath", label="Generated Diagram"),
253
+ title="🎨 FLUX Diagram Generator",
254
+ description="""Generate beautiful hand-drawn style diagrams using FLUX AI.
255
+ Create intricate mind maps with custom themes and detailed iconography.""",
256
+ article="""
257
+ ### Tips for Better Results
258
+ - Use descriptive style hints (e.g., "vibrant colors", "flowing connections")
259
+ - Include specific icon sizes (e.g., "~60px")
260
+ - Add theme-specific patterns (e.g., "circuit board patterns", "wave patterns")
261
+ - Use consistent hierarchy and formatting
262
+ - Combine both functional and decorative elements
263
 
264
+ ### Template Structure
265
+ ```
266
+ MAIN TOPIC
267
+ β”œβ”€β”€ PRIMARY [Icon ~60px]
268
+ β”‚ β”œβ”€β”€ SUB-A [Specific Icon]
269
+ β”‚ └── SUB-B [Detailed Icon]
270
+ β”œβ”€β”€ SECONDARY [Icon ~55px]
271
+ β”‚ β”œβ”€β”€ SUB-C [Themed Icon]
272
+ β”‚ └── SUB-D [Custom Icon]
273
+ └── TERTIARY
274
+ β”œβ”€β”€ SUB-E [Dynamic Icon]
275
+ └── SUB-F [Unique Icon]
276
+ ```
277
+ """,
278
+ examples=GRADIO_EXAMPLES,
279
+ cache_examples=True,
280
+ theme=gr.themes.Soft(),
281
+ css="""
282
+ .gradio-container {
283
+ font-family: 'Inter', sans-serif;
284
+ }
285
+ .gr-prose {
286
+ max-width: 850px;
287
+ margin: auto;
288
+ }
289
+ .gr-prose code {
290
+ background-color: #f3f4f6;
291
+ padding: 0.2em 0.4em;
292
+ border-radius: 0.3em;
293
+ font-size: 0.95em;
294
+ }
295
+ .gr-prose h3 {
296
+ margin-top: 1.5em;
297
+ color: #2563eb;
298
+ }
299
+ """
300
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
 
302
+ # Launch app
303
  if __name__ == "__main__":
304
+ # Set HF space configs
305
+ demo.queue(max_size=15) # Increased queue size
306
+ demo.launch(
307
+ share=False,
308
+ show_error=True,
309
+ server_name="0.0.0.0",
310
+ server_port=7860,
311
+ )