Delete app-backup.py
Browse files- app-backup.py +0 -261
app-backup.py
DELETED
|
@@ -1,261 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
-
import torch
|
| 5 |
-
from diffusers import DiffusionPipeline
|
| 6 |
-
import spaces
|
| 7 |
-
|
| 8 |
-
# 기본 설정
|
| 9 |
-
dtype = torch.bfloat16
|
| 10 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
-
|
| 12 |
-
# 모델 로드
|
| 13 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 14 |
-
"black-forest-labs/FLUX.1-schnell",
|
| 15 |
-
torch_dtype=dtype
|
| 16 |
-
).to(device)
|
| 17 |
-
|
| 18 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 19 |
-
MAX_IMAGE_SIZE = 2048
|
| 20 |
-
|
| 21 |
-
# 제품 디자인 컨셉 예시
|
| 22 |
-
EXAMPLES = [
|
| 23 |
-
{
|
| 24 |
-
"title": "Smart Coffee Machine",
|
| 25 |
-
"prompt": """A sleek industrial design concept for a coffee machine:
|
| 26 |
-
- Curved metallic body with minimal bezel
|
| 27 |
-
- Touchscreen panel for settings
|
| 28 |
-
- Modern matte black finish
|
| 29 |
-
- Hand-drawn concept sketch style""",
|
| 30 |
-
"width": 1024,
|
| 31 |
-
"height": 1024
|
| 32 |
-
},
|
| 33 |
-
{
|
| 34 |
-
"title": "AI Speaker",
|
| 35 |
-
"prompt": """A futuristic AI speaker concept:
|
| 36 |
-
- Cylindrical shape with LED ring near top
|
| 37 |
-
- Voice assistant concept, floating panel controls
|
| 38 |
-
- Smooth glossy finish with minimal seams
|
| 39 |
-
- Techy, modern look in grayscale""",
|
| 40 |
-
"width": 1024,
|
| 41 |
-
"height": 1024
|
| 42 |
-
},
|
| 43 |
-
{
|
| 44 |
-
"title": "Next-Gen Smartphone",
|
| 45 |
-
"prompt": """A wireframe-style concept for a bezel-less smartphone:
|
| 46 |
-
- Edge-to-edge display
|
| 47 |
-
- Integrated camera under screen
|
| 48 |
-
- Metallic frame, minimal ports
|
| 49 |
-
- Sleek, glossy black design""",
|
| 50 |
-
"width": 1024,
|
| 51 |
-
"height": 1024
|
| 52 |
-
},
|
| 53 |
-
{
|
| 54 |
-
"title": "Futuristic Electric Bicycle",
|
| 55 |
-
"prompt": """An industrial design sketch of an electric bike:
|
| 56 |
-
- Lightweight carbon frame, aerodynamic lines
|
| 57 |
-
- Integrated battery, sleek display on handlebars
|
| 58 |
-
- Neon color highlights on wheels
|
| 59 |
-
- High-tech vibe, minimal clutter""",
|
| 60 |
-
"width": 1024,
|
| 61 |
-
"height": 1024
|
| 62 |
-
},
|
| 63 |
-
{
|
| 64 |
-
"title": "Concept Car Interior",
|
| 65 |
-
"prompt": """A luxurious and futuristic car interior concept:
|
| 66 |
-
- Wrap-around digital dashboard
|
| 67 |
-
- Minimalistic steering control, seat controls on touchscreen
|
| 68 |
-
- Ambient LED accent lights
|
| 69 |
-
- Soft leather seats, bright accent stitching""",
|
| 70 |
-
"width": 1024,
|
| 71 |
-
"height": 1024
|
| 72 |
-
}
|
| 73 |
-
]
|
| 74 |
-
|
| 75 |
-
# Convert examples to Gradio format (if needed)
|
| 76 |
-
GRADIO_EXAMPLES = [
|
| 77 |
-
[example["prompt"], example["width"], example["height"]]
|
| 78 |
-
for example in EXAMPLES
|
| 79 |
-
]
|
| 80 |
-
|
| 81 |
-
@spaces.GPU()
|
| 82 |
-
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
| 83 |
-
if randomize_seed:
|
| 84 |
-
seed = random.randint(0, MAX_SEED)
|
| 85 |
-
generator = torch.Generator().manual_seed(seed)
|
| 86 |
-
image = pipe(
|
| 87 |
-
prompt=prompt,
|
| 88 |
-
width=width,
|
| 89 |
-
height=height,
|
| 90 |
-
num_inference_steps=num_inference_steps,
|
| 91 |
-
generator=generator,
|
| 92 |
-
guidance_scale=0.0
|
| 93 |
-
).images[0]
|
| 94 |
-
return image, seed
|
| 95 |
-
|
| 96 |
-
# CSS 스타일 (기존 구조 유지)
|
| 97 |
-
css = """
|
| 98 |
-
.container {
|
| 99 |
-
display: flex;
|
| 100 |
-
flex-direction: row;
|
| 101 |
-
height: 100%;
|
| 102 |
-
}
|
| 103 |
-
.input-column {
|
| 104 |
-
flex: 1;
|
| 105 |
-
padding: 20px;
|
| 106 |
-
border-right: 2px solid #eee;
|
| 107 |
-
max-width: 800px;
|
| 108 |
-
}
|
| 109 |
-
.examples-column {
|
| 110 |
-
flex: 1;
|
| 111 |
-
padding: 20px;
|
| 112 |
-
overflow-y: auto;
|
| 113 |
-
background: #f7f7f7;
|
| 114 |
-
}
|
| 115 |
-
.title {
|
| 116 |
-
text-align: center;
|
| 117 |
-
color: #2a2a2a;
|
| 118 |
-
padding: 20px;
|
| 119 |
-
font-size: 2.5em;
|
| 120 |
-
font-weight: bold;
|
| 121 |
-
background: linear-gradient(90deg, #f0f0f0 0%, #ffffff 100%);
|
| 122 |
-
border-bottom: 3px solid #ddd;
|
| 123 |
-
margin-bottom: 30px;
|
| 124 |
-
}
|
| 125 |
-
.subtitle {
|
| 126 |
-
text-align: center;
|
| 127 |
-
color: #666;
|
| 128 |
-
margin-bottom: 30px;
|
| 129 |
-
}
|
| 130 |
-
.input-box {
|
| 131 |
-
background: white;
|
| 132 |
-
padding: 20px;
|
| 133 |
-
border-radius: 10px;
|
| 134 |
-
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 135 |
-
margin-bottom: 20px;
|
| 136 |
-
width: 100%;
|
| 137 |
-
}
|
| 138 |
-
.input-box textarea {
|
| 139 |
-
width: 100% !important;
|
| 140 |
-
min-width: 600px !important;
|
| 141 |
-
font-size: 14px !important;
|
| 142 |
-
line-height: 1.5 !important;
|
| 143 |
-
padding: 12px !important;
|
| 144 |
-
}
|
| 145 |
-
.example-card {
|
| 146 |
-
background: white;
|
| 147 |
-
padding: 15px;
|
| 148 |
-
margin: 10px 0;
|
| 149 |
-
border-radius: 8px;
|
| 150 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
|
| 151 |
-
}
|
| 152 |
-
.example-title {
|
| 153 |
-
font-weight: bold;
|
| 154 |
-
color: #2a2a2a;
|
| 155 |
-
margin-bottom: 10px;
|
| 156 |
-
}
|
| 157 |
-
.contain {
|
| 158 |
-
max-width: 1400px !important;
|
| 159 |
-
margin: 0 auto !important;
|
| 160 |
-
}
|
| 161 |
-
.input-area {
|
| 162 |
-
flex: 2 !important;
|
| 163 |
-
}
|
| 164 |
-
.examples-area {
|
| 165 |
-
flex: 1 !important;
|
| 166 |
-
}
|
| 167 |
-
"""
|
| 168 |
-
|
| 169 |
-
with gr.Blocks(css=css) as demo:
|
| 170 |
-
gr.Markdown(
|
| 171 |
-
"""
|
| 172 |
-
<div class="title">GINI Design</div>
|
| 173 |
-
<div class="subtitle">Generate sleek industrial/product design concepts with FLUX AI</div>
|
| 174 |
-
""")
|
| 175 |
-
|
| 176 |
-
with gr.Row(equal_height=True):
|
| 177 |
-
# 왼쪽 입력 컬럼
|
| 178 |
-
with gr.Column(elem_id="input-column", scale=2):
|
| 179 |
-
with gr.Group(elem_classes="input-box"):
|
| 180 |
-
prompt = gr.Text(
|
| 181 |
-
label="Design Prompt",
|
| 182 |
-
placeholder="Enter your product design concept details...",
|
| 183 |
-
lines=10,
|
| 184 |
-
elem_classes="prompt-input"
|
| 185 |
-
)
|
| 186 |
-
run_button = gr.Button("Generate Design", variant="primary")
|
| 187 |
-
result = gr.Image(label="Generated Design")
|
| 188 |
-
|
| 189 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 190 |
-
seed = gr.Slider(
|
| 191 |
-
label="Seed",
|
| 192 |
-
minimum=0,
|
| 193 |
-
maximum=MAX_SEED,
|
| 194 |
-
step=1,
|
| 195 |
-
value=0,
|
| 196 |
-
)
|
| 197 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 198 |
-
|
| 199 |
-
with gr.Row():
|
| 200 |
-
width = gr.Slider(
|
| 201 |
-
label="Width",
|
| 202 |
-
minimum=256,
|
| 203 |
-
maximum=MAX_IMAGE_SIZE,
|
| 204 |
-
step=32,
|
| 205 |
-
value=1024,
|
| 206 |
-
)
|
| 207 |
-
height = gr.Slider(
|
| 208 |
-
label="Height",
|
| 209 |
-
minimum=256,
|
| 210 |
-
maximum=MAX_IMAGE_SIZE,
|
| 211 |
-
step=32,
|
| 212 |
-
value=1024,
|
| 213 |
-
)
|
| 214 |
-
|
| 215 |
-
num_inference_steps = gr.Slider(
|
| 216 |
-
label="Number of inference steps",
|
| 217 |
-
minimum=1,
|
| 218 |
-
maximum=50,
|
| 219 |
-
step=1,
|
| 220 |
-
value=4,
|
| 221 |
-
)
|
| 222 |
-
|
| 223 |
-
# 오른쪽 예제 컬럼
|
| 224 |
-
with gr.Column(elem_id="examples-column", scale=1):
|
| 225 |
-
gr.Markdown("### Example Product Designs")
|
| 226 |
-
for example in EXAMPLES:
|
| 227 |
-
with gr.Group(elem_classes="example-card"):
|
| 228 |
-
gr.Markdown(f"#### {example['title']}")
|
| 229 |
-
gr.Markdown(f"```\n{example['prompt']}\n```")
|
| 230 |
-
|
| 231 |
-
def create_example_handler(ex):
|
| 232 |
-
def handler():
|
| 233 |
-
return {
|
| 234 |
-
prompt: ex["prompt"],
|
| 235 |
-
width: ex["width"],
|
| 236 |
-
height: ex["height"]
|
| 237 |
-
}
|
| 238 |
-
return handler
|
| 239 |
-
|
| 240 |
-
gr.Button("Use This Example", size="sm").click(
|
| 241 |
-
fn=create_example_handler(example),
|
| 242 |
-
outputs=[prompt, width, height]
|
| 243 |
-
)
|
| 244 |
-
|
| 245 |
-
# 이벤트 바인딩 (버튼 클릭 & 텍스트박스 엔터)
|
| 246 |
-
gr.on(
|
| 247 |
-
triggers=[run_button.click, prompt.submit],
|
| 248 |
-
fn=infer,
|
| 249 |
-
inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
|
| 250 |
-
outputs=[result, seed]
|
| 251 |
-
)
|
| 252 |
-
|
| 253 |
-
if __name__ == "__main__":
|
| 254 |
-
demo.queue()
|
| 255 |
-
demo.launch(
|
| 256 |
-
server_name="0.0.0.0",
|
| 257 |
-
server_port=7860,
|
| 258 |
-
share=False,
|
| 259 |
-
show_error=True,
|
| 260 |
-
debug=True
|
| 261 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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