File size: 9,199 Bytes
6742856 016b059 6742856 cb7718b 016b059 2531620 016b059 2531620 016b059 cb7718b 016b059 cb7718b 016b059 cb7718b 016b059 cb7718b 016b059 cb7718b 016b059 cb7718b 016b059 2531620 016b059 2531620 016b059 2531620 016b059 2531620 cb7718b 016b059 2531620 016b059 2531620 016b059 0da9692 016b059 0da9692 016b059 2531620 016b059 cb7718b 016b059 0da9692 202b398 016b059 cb7718b 016b059 2531620 016b059 202b398 016b059 2531620 016b059 202b398 016b059 cb7718b 016b059 202b398 dd5d6cc 6742856 016b059 |
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 |
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": "Business Workflow",
"prompt": """A hand-drawn style flowchart, vibrant colors, minimalistic icons.
BUSINESS WORKFLOW
βββ START [Green Button ~40px]
β βββ COLLECT REQUIREMENTS [Folder Icon]
β βββ ANALYZE DATA [Chart Icon]
βββ IMPLEMENTATION [Coding Symbol ~50px]
β βββ FRONTEND [Browser Icon]
β βββ BACKEND [Server Icon]
βββ TEST & INTEGRATION [Gear Icon ~45px]
βββ DEPLOY
βββ END [Checkered Flag ~40px]""",
"width": 1024,
"height": 1024
},
{
"title": "Software Release Flow",
"prompt": """A hand-drawn style flowchart, pastel colors, arrows between stages.
SOFTWARE RELEASE
βββ FEATURE BRANCH [Git Branch Icon ~45px]
β βββ DEVELOPMENT [Code Editor]
β βββ UNIT TEST [Check Mark]
βββ MERGE TO MAIN [Pull Request Icon]
β βββ CI/CD [Pipeline Icon ~40px]
β βββ BUILD [Gear Icon]
βββ PRODUCTION
βββ DEPLOY [Cloud Upload Icon]""",
"width": 1024,
"height": 1024
},
{
"title": "E-Commerce Checkout",
"prompt": """A hand-drawn style flowchart, light watercolor, user journey from cart to payment.
E-COMMERCE CHECKOUT
βββ CART [Shopping Cart ~40px]
β βββ LOGIN [User Icon]
β βββ ADDRESS [Location Pin]
βββ PAYMENT [Credit Card Icon ~45px]
β βββ VALIDATION [Lock Icon]
β βββ CONFIRMATION [Receipt Icon]
βββ ORDER COMPLETE
βββ THANK YOU [Smiley Icon]""",
"width": 1024,
"height": 1024
},
{
"title": "Data Pipeline",
"prompt": """A hand-drawn style flowchart, tech-focused, neon highlights, showing data flow.
DATA PIPELINE
βββ INGESTION [Database Icon ~50px]
β βββ STREAMING [Kafka Symbol]
β βββ BATCH [CSV/JSON Files]
βββ TRANSFORMATION [Gear Icon ~45px]
β βββ CLEANING [Brush Icon]
β βββ AGGREGATION [Bar Graph]
βββ STORAGE [Cloud Icon ~50px]
βββ ANALYTICS
βββ DASHBOARDS [Monitor Icon]""",
"width": 1024,
"height": 1024
},
{
"title": "Machine Learning Lifecycle",
"prompt": """A hand-drawn style flowchart, pastel palette, ML steps from data to deployment.
ML LIFECYCLE
βββ DATA COLLECTION [Folder Icon ~45px]
β βββ DATA CLEANING [Soap Icon]
β βββ FEATURE ENGINEERING [Puzzle Icon]
βββ MODEL TRAINING [Robot Icon ~50px]
β βββ HYPERPARAM TUNING [Dial Knob]
β βββ EVALUATION [Magnifier Icon]
βββ DEPLOYMENT [Cloud Icon ~45px]
βββ MONITORING
βββ FEEDBACK LOOP [Arrow Circle Icon]""",
"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;
}
"""
# Gradio μΈν°νμ΄μ€
with gr.Blocks(css=css) as demo:
gr.Markdown(
"""
<div class="title">GINI Flowchart</div>
<div class="subtitle">Create professional process flowcharts using FLUX AI</div>
""")
with gr.Row(equal_height=True):
# μΌμͺ½ μ
λ ₯ 컬λΌ
with gr.Column(elem_id="input-column", scale=2):
with gr.Group(elem_classes="input-box"):
prompt = gr.Text(
label="Flowchart Prompt",
placeholder="Enter your process flowchart structure...",
lines=10,
elem_classes="prompt-input"
)
run_button = gr.Button("Generate Flowchart", variant="primary")
result = gr.Image(label="Generated Flowchart")
with gr.Accordion("Advanced Settings", open=False):
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=MAX_SEED,
step=1,
value=0,
)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
with gr.Row():
width = gr.Slider(
label="Width",
minimum=256,
maximum=MAX_IMAGE_SIZE,
step=32,
value=1024,
)
height = gr.Slider(
label="Height",
minimum=256,
maximum=MAX_IMAGE_SIZE,
step=32,
value=1024,
)
num_inference_steps = gr.Slider(
label="Number of inference steps",
minimum=1,
maximum=50,
step=1,
value=4,
)
# μ€λ₯Έμͺ½ μμ 컬λΌ
with gr.Column(elem_id="examples-column", scale=1):
gr.Markdown("### Example Flowcharts")
for example in EXAMPLES:
with gr.Group(elem_classes="example-card"):
gr.Markdown(f"#### {example['title']}")
gr.Markdown(f"```\n{example['prompt']}\n```")
def create_example_handler(ex):
def handler():
return {
prompt: ex["prompt"],
width: ex["width"],
height: ex["height"]
}
return handler
gr.Button("Use This Example", size="sm").click(
fn=create_example_handler(example),
outputs=[prompt, width, height]
)
# μ΄λ²€νΈ λ°μΈλ© (λ²νΌ ν΄λ¦ & ν
μ€νΈλ°μ€ μν°)
gr.on(
triggers=[run_button.click, prompt.submit],
fn=infer,
inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
outputs=[result, seed]
)
if __name__ == "__main__":
demo.queue()
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
show_error=True,
debug=True
)
|