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 # 인포그래픽 예시들 EXAMPLES = [ { "title": "Global Energy Mix", "prompt": """A modern flat-style infographic about global renewable energy usage: - Title: "Global Renewable Energy Share" - Bar chart showing Solar, Wind, Hydro - Pie chart: 40% Solar, 35% Wind, 25% Hydro - Minimalist icons: sun, wind turbine, water wave - Clean layout with pastel color scheme""", "width": 1024, "height": 1024 }, { "title": "Startup Growth Stats", "prompt": """A hand-drawn style infographic illustrating startup growth stages: - Title: "Startup Growth Journey" - 5 main steps: Ideation, MVP, Early Users, Funding, Scaling - Icons for each step (lightbulb, prototype gear, user group, money bag, rocket) - Vibrant color palette""", "width": 1024, "height": 1024 }, { "title": "Healthy Lifestyle", "prompt": """A watercolor style infographic showing healthy lifestyle tips: - Title: "Healthy Lifestyle" - 3 pillars: Nutrition, Exercise, Mental Health - Icons: Food plate, running shoe, yoga person - Soft pastel colors, gentle shapes""", "width": 1024, "height": 1024 }, { "title": "E-Commerce Trends", "prompt": """A hand-drawn infographic explaining e-commerce market trends: - Title: "E-Commerce Trends 2025" - Growth chart with arrow - 4 key metrics: Conversion Rate, AOV, Repeat Customers, Mobile Share - Minimal color scheme, doodle style icons""", "width": 1024, "height": 1024 }, { "title": "Planet Sustainability", "prompt": """A vivid infographic about environmental sustainability: - Title: "Planet Sustainability Goals" - Tree diagram with branches: Reduce, Reuse, Recycle - Data highlights (CO2 reduction, forest coverage, plastic usage) - Green and earthy color scheme""", "width": 1024, "height": 1024 } ] # Convert examples to Gradio format (if needed) 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; 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; } """ with gr.Blocks(css=css) as demo: gr.Markdown( """