Spaces:
ginigen
/
Running on Zero

Mockup / app.py
aiqcamp's picture
Update app.py
708b543 verified
raw
history blame
12 kB
import gradio as gr
from gradio_client import Client
import os
from dotenv import load_dotenv
import warnings
# κ²½κ³  λ©”μ‹œμ§€ 숨기기
warnings.filterwarnings('ignore', category=UserWarning)
# ν™˜κ²½ λ³€μˆ˜ λ‘œλ“œ
load_dotenv()
HF_TOKEN = os.getenv("HF_TOKEN")
def generate_diagram(prompt, width=1024, height=1024):
"""FLUX AIλ₯Ό μ‚¬μš©ν•˜μ—¬ λ‹€μ΄μ–΄κ·Έλž¨ 생성"""
try:
# API ν˜ΈμΆœμ„ 톡해 이미지 생성
result = gr.Image.update(value=None) # 초기 μƒνƒœλŠ” 빈 이미지
# Hugging Face API 호좜
client = Client(
"https://black-forest-labs-flux-1-schnell.hf.space", # API μ—”λ“œν¬μΈνŠΈ 직접 지정
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"λ‹€μ΄μ–΄κ·Έλž¨ 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
# Convert example format for Gradio
GRADIO_EXAMPLES = [
[
"""A handrawn colorful mind map diagram, educational style, vibrant colors, clear hierarchy.
KNOWLEDGE
β”œβ”€β”€ ACQUISITION [Brain with Lightning ~60px]
β”‚ β”œβ”€β”€ READING [Open Book with Glow]
β”‚ └── PRACTICE [Hands-on Tools]
└── APPLICATION
β”œβ”€β”€ CREATION [Artist Palette]
└── INNOVATION [Lightbulb]""",
1024,
1024
],
[
"""A handrawn colorful mind map diagram, tech-focused style, neon accents.
DIGITAL TRANSFORM
β”œβ”€β”€ CLOUD [Cloud with Data ~55px]
β”‚ β”œβ”€β”€ STORAGE [Database]
β”‚ └── COMPUTING [Server]
└── SECURITY
β”œβ”€β”€ ENCRYPTION [Lock]
└── MONITORING [Radar]""",
1024,
1024
],
[
"""A handrawn colorful mind map diagram, creative style, flowing design.
INNOVATION
β”œβ”€β”€ IDEATION [Lightbulb ~60px]
β”‚ β”œβ”€β”€ RESEARCH [Magnifier]
β”‚ └── BRAINSTORM [Brain]
└── EXECUTION
β”œβ”€β”€ PROTOTYPE [Tools]
└── TEST [Checklist]""",
1024,
1024
]
]
# 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
]
demo = gr.Interface(
fn=generate_diagram,
inputs=[
gr.Textbox(
label="λ‹€μ΄μ–΄κ·Έλž¨ ν”„λ‘¬ν”„νŠΈ",
placeholder="λ‹€μ΄μ–΄κ·Έλž¨ ꡬ쑰λ₯Ό μž…λ ₯ν•˜μ„Έμš”...",
lines=10
),
gr.Slider(
label="λ„ˆλΉ„",
minimum=512,
maximum=2048,
step=128,
value=1024
),
gr.Slider(
label="높이",
minimum=512,
maximum=2048,
step=128,
value=1024
)
],
outputs=gr.Image(label="μƒμ„±λœ λ‹€μ΄μ–΄κ·Έλž¨"),
title="🎨 FLUX λ‹€μ΄μ–΄κ·Έλž¨ 생성기",
description="FLUX AIλ₯Ό μ‚¬μš©ν•˜μ—¬ μ•„λ¦„λ‹€μš΄ 손그림 μŠ€νƒ€μΌμ˜ λ‹€μ΄μ–΄κ·Έλž¨μ„ μƒμ„±ν•©λ‹ˆλ‹€",
article="""
### 더 λ‚˜μ€ κ²°κ³Όλ₯Ό μœ„ν•œ 팁
- λͺ…ν™•ν•œ 계측 ꡬ쑰 μ‚¬μš©
- λŒ€κ΄„ν˜Έ μ•ˆμ— μ•„μ΄μ½˜ μ„€λͺ… 포함
- κ°„κ²°ν•˜κ³  의미 μžˆλŠ” ν…μŠ€νŠΈ μ‚¬μš©
- μΌκ΄€λœ ν˜•μ‹ μœ μ§€
""",
examples=GRADIO_EXAMPLES,
cache_examples=True
)
# μ•± μ‹€ν–‰ λΆ€λΆ„λ§Œ μˆ˜μ •
if __name__ == "__main__":
demo.queue() # 큐 κΈ°λŠ₯을 λ³„λ„λ‘œ ν™œμ„±ν™”
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
show_error=True,
debug=True
)