File size: 11,363 Bytes
a6cbec6 dd5d6cc a6cbec6 dd5d6cc 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 dd5d6cc a6cbec6 dd5d6cc a6cbec6 dd5d6cc a6cbec6 dd5d6cc a6cbec6 1a0c9b6 a6cbec6 1a0c9b6 a6cbec6 dd5d6cc a6cbec6 dd5d6cc a6cbec6 dd5d6cc a6cbec6 |
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 |
import gradio as gr
from gradio_client import Client
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
HF_TOKEN = os.getenv("HF_TOKEN")
# 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
}
]
def generate_diagram(prompt, width=1024, height=1024):
"""Generate a diagram using FLUX AI"""
try:
client = Client("black-forest-labs/FLUX.1-schnell", hf_token=HF_TOKEN)
result = client.predict(
prompt,
1872187377, # seed
False, # randomize_seed
width,
height,
4, # num_inference_steps
api_name="/infer"
)
return result
except Exception as e:
raise gr.Error(f"Error generating diagram: {str(e)}")
# Convert examples to Gradio format
GRADIO_EXAMPLES = [
[example["prompt"], example["width"], example["height"]]
for example in EXAMPLES
]
# Create Gradio interface
demo = gr.Interface(
fn=generate_diagram,
inputs=[
gr.Textbox(
label="Diagram Prompt",
placeholder="Enter your diagram structure...",
lines=10
),
gr.Slider(
label="Width",
minimum=512,
maximum=2048,
step=128,
value=1024
),
gr.Slider(
label="Height",
minimum=512,
maximum=2048,
step=128,
value=1024
)
],
outputs=gr.Image(type="filepath", label="Generated Diagram"),
title="π¨ FLUX Diagram Generator",
description="""Generate beautiful hand-drawn style diagrams using FLUX AI.
Create intricate mind maps with custom themes and detailed iconography.""",
article="""
### Tips for Better Results
- Use descriptive style hints (e.g., "vibrant colors", "flowing connections")
- Include specific icon sizes (e.g., "~60px")
- Add theme-specific patterns (e.g., "circuit board patterns", "wave patterns")
- Use consistent hierarchy and formatting
- Combine both functional and decorative elements
### Template Structure
```
MAIN TOPIC
βββ PRIMARY [Icon ~60px]
β βββ SUB-A [Specific Icon]
β βββ SUB-B [Detailed Icon]
βββ SECONDARY [Icon ~55px]
β βββ SUB-C [Themed Icon]
β βββ SUB-D [Custom Icon]
βββ TERTIARY
βββ SUB-E [Dynamic Icon]
βββ SUB-F [Unique Icon]
```
""",
examples=GRADIO_EXAMPLES,
cache_examples=True,
theme=gr.themes.Soft(),
css="""
.gradio-container {
font-family: 'Inter', sans-serif;
}
.gr-prose {
max-width: 850px;
margin: auto;
}
.gr-prose code {
background-color: #f3f4f6;
padding: 0.2em 0.4em;
border-radius: 0.3em;
font-size: 0.95em;
}
.gr-prose h3 {
margin-top: 1.5em;
color: #2563eb;
}
"""
)
# Launch app
if __name__ == "__main__":
# Set HF space configs
demo.queue(max_size=15) # Increased queue size
demo.launch(
share=False,
show_error=True,
server_name="0.0.0.0",
server_port=7860,
) |