Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,11 @@ torch.backends.cuda.matmul.allow_tf32 = True
|
|
| 35 |
if not path.exists(gallery_path):
|
| 36 |
os.makedirs(gallery_path, exist_ok=True)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
class timer:
|
| 39 |
def __init__(self, method_name="timed process"):
|
| 40 |
self.method = method_name
|
|
@@ -102,7 +107,7 @@ def save_image(image):
|
|
| 102 |
examples = [
|
| 103 |
["A 3D Star Wars Darth Vader helmet, highly detailed metallic finish"],
|
| 104 |
["A 3D Iron Man mask with glowing eyes and metallic red-gold finish"],
|
| 105 |
-
["A
|
| 106 |
["A 3D geometric abstract cube transforming into a sphere, metallic finish"],
|
| 107 |
["A 3D steampunk mechanical heart with brass and copper details"],
|
| 108 |
["A 3D crystal dragon with transparent iridescent scales"],
|
|
@@ -154,7 +159,6 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
|
|
| 154 |
def get_random_seed():
|
| 155 |
return torch.randint(0, 1000000, (1,)).item()
|
| 156 |
|
| 157 |
-
|
| 158 |
def process_example(prompt):
|
| 159 |
return process_and_save_image(
|
| 160 |
height=1024,
|
|
@@ -165,7 +169,6 @@ def process_example(prompt):
|
|
| 165 |
seed=get_random_seed()
|
| 166 |
)
|
| 167 |
|
| 168 |
-
|
| 169 |
# Gradio ์ธํฐํ์ด์ค
|
| 170 |
with gr.Blocks(
|
| 171 |
theme=gr.themes.Soft(),
|
|
@@ -192,83 +195,117 @@ with gr.Blocks(
|
|
| 192 |
}
|
| 193 |
"""
|
| 194 |
) as demo:
|
| 195 |
-
gr.
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
with gr.Column(scale=3):
|
| 206 |
-
prompt = gr.Textbox(
|
| 207 |
-
label="Image Description",
|
| 208 |
-
placeholder="Describe the 3D image you want to create...",
|
| 209 |
-
lines=3
|
| 210 |
)
|
| 211 |
|
| 212 |
-
with gr.
|
| 213 |
-
with gr.
|
| 214 |
-
|
| 215 |
-
label="
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
step=64,
|
| 219 |
-
value=1024
|
| 220 |
-
)
|
| 221 |
-
width = gr.Slider(
|
| 222 |
-
label="Width",
|
| 223 |
-
minimum=256,
|
| 224 |
-
maximum=1152,
|
| 225 |
-
step=64,
|
| 226 |
-
value=1024
|
| 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 |
-
generate_btn = gr.Button(
|
| 254 |
-
"โจ Generate Image",
|
| 255 |
-
elem_classes=["generate-btn"]
|
| 256 |
-
)
|
| 257 |
-
|
| 258 |
-
with gr.Column(scale=4, elem_classes=["fixed-width"]):
|
| 259 |
-
output = gr.Image(
|
| 260 |
-
label="Generated Image",
|
| 261 |
-
elem_id="output-image",
|
| 262 |
-
elem_classes=["output-image", "fixed-width"],
|
| 263 |
-
value="3d.webp"
|
| 264 |
-
)
|
| 265 |
|
| 266 |
# Examples ์น์
|
| 267 |
gr.Examples(
|
| 268 |
examples=examples,
|
| 269 |
inputs=prompt,
|
| 270 |
outputs=output,
|
| 271 |
-
fn=process_example,
|
| 272 |
cache_examples=False,
|
| 273 |
examples_per_page=5
|
| 274 |
)
|
|
|
|
| 35 |
if not path.exists(gallery_path):
|
| 36 |
os.makedirs(gallery_path, exist_ok=True)
|
| 37 |
|
| 38 |
+
# ์ํ ์ด๋ฏธ์ง์ ํ๋กฌํํธ ์ ์
|
| 39 |
+
SAMPLE_IMAGES = {
|
| 40 |
+
"3d1.webp": "the most famous hero according to Zhou Qi"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
class timer:
|
| 44 |
def __init__(self, method_name="timed process"):
|
| 45 |
self.method = method_name
|
|
|
|
| 107 |
examples = [
|
| 108 |
["A 3D Star Wars Darth Vader helmet, highly detailed metallic finish"],
|
| 109 |
["A 3D Iron Man mask with glowing eyes and metallic red-gold finish"],
|
| 110 |
+
["A 3D Pokemon Pikachu figure with glossy surface"],
|
| 111 |
["A 3D geometric abstract cube transforming into a sphere, metallic finish"],
|
| 112 |
["A 3D steampunk mechanical heart with brass and copper details"],
|
| 113 |
["A 3D crystal dragon with transparent iridescent scales"],
|
|
|
|
| 159 |
def get_random_seed():
|
| 160 |
return torch.randint(0, 1000000, (1,)).item()
|
| 161 |
|
|
|
|
| 162 |
def process_example(prompt):
|
| 163 |
return process_and_save_image(
|
| 164 |
height=1024,
|
|
|
|
| 169 |
seed=get_random_seed()
|
| 170 |
)
|
| 171 |
|
|
|
|
| 172 |
# Gradio ์ธํฐํ์ด์ค
|
| 173 |
with gr.Blocks(
|
| 174 |
theme=gr.themes.Soft(),
|
|
|
|
| 195 |
}
|
| 196 |
"""
|
| 197 |
) as demo:
|
| 198 |
+
with gr.Tabs():
|
| 199 |
+
# ์ฒซ ๋ฒ์งธ ํญ - Generator
|
| 200 |
+
with gr.Tab("Generator"):
|
| 201 |
+
gr.HTML(
|
| 202 |
+
"""
|
| 203 |
+
<div style="text-align: center; max-width: 800px; margin: 0 auto; padding: 20px;">
|
| 204 |
+
<h1 style="font-size: 2.5rem; color: #2196F3;">3D Style Image Generator</h1>
|
| 205 |
+
<p style="font-size: 1.2rem; color: #666;">Create amazing 3D-style images with AI</p>
|
| 206 |
+
</div>
|
| 207 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
)
|
| 209 |
|
| 210 |
+
with gr.Row(elem_classes="container"):
|
| 211 |
+
with gr.Column(scale=3):
|
| 212 |
+
prompt = gr.Textbox(
|
| 213 |
+
label="Image Description",
|
| 214 |
+
placeholder="Describe the 3D image you want to create...",
|
| 215 |
+
lines=3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
)
|
| 217 |
+
|
| 218 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 219 |
+
with gr.Row():
|
| 220 |
+
height = gr.Slider(
|
| 221 |
+
label="Height",
|
| 222 |
+
minimum=256,
|
| 223 |
+
maximum=1152,
|
| 224 |
+
step=64,
|
| 225 |
+
value=1024
|
| 226 |
+
)
|
| 227 |
+
width = gr.Slider(
|
| 228 |
+
label="Width",
|
| 229 |
+
minimum=256,
|
| 230 |
+
maximum=1152,
|
| 231 |
+
step=64,
|
| 232 |
+
value=1024
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
with gr.Row():
|
| 236 |
+
steps = gr.Slider(
|
| 237 |
+
label="Inference Steps",
|
| 238 |
+
minimum=6,
|
| 239 |
+
maximum=25,
|
| 240 |
+
step=1,
|
| 241 |
+
value=8
|
| 242 |
+
)
|
| 243 |
+
scales = gr.Slider(
|
| 244 |
+
label="Guidance Scale",
|
| 245 |
+
minimum=0.0,
|
| 246 |
+
maximum=5.0,
|
| 247 |
+
step=0.1,
|
| 248 |
+
value=3.5
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
seed = gr.Number(
|
| 252 |
+
label="Seed (random by default, set for reproducibility)",
|
| 253 |
+
value=get_random_seed(),
|
| 254 |
+
precision=0
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
randomize_seed = gr.Button("๐ฒ Randomize Seed", elem_classes=["generate-btn"])
|
| 258 |
+
|
| 259 |
+
generate_btn = gr.Button(
|
| 260 |
+
"โจ Generate Image",
|
| 261 |
+
elem_classes=["generate-btn"]
|
| 262 |
)
|
| 263 |
+
|
| 264 |
+
with gr.Column(scale=4, elem_classes=["fixed-width"]):
|
| 265 |
+
output = gr.Image(
|
| 266 |
+
label="Generated Image",
|
| 267 |
+
elem_id="output-image",
|
| 268 |
+
elem_classes=["output-image", "fixed-width"],
|
| 269 |
+
value="3d.webp"
|
| 270 |
)
|
| 271 |
+
|
| 272 |
+
# ๋ ๋ฒ์งธ ํญ - Gallery
|
| 273 |
+
with gr.Tab("Gallery"):
|
| 274 |
+
with gr.Row():
|
| 275 |
+
gallery_html = "<div style='display: flex; flex-wrap: wrap; gap: 20px; padding: 20px;'>"
|
| 276 |
|
| 277 |
+
for img_file, prompt in SAMPLE_IMAGES.items():
|
| 278 |
+
if os.path.exists(img_file):
|
| 279 |
+
gallery_html += f"""
|
| 280 |
+
<div style='
|
| 281 |
+
border: 1px solid #ddd;
|
| 282 |
+
border-radius: 10px;
|
| 283 |
+
padding: 10px;
|
| 284 |
+
width: 300px;
|
| 285 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 286 |
+
'>
|
| 287 |
+
<img src='file/{img_file}'
|
| 288 |
+
style='width: 100%;
|
| 289 |
+
border-radius: 8px;
|
| 290 |
+
margin-bottom: 10px;'
|
| 291 |
+
>
|
| 292 |
+
<p style='
|
| 293 |
+
margin: 5px 0;
|
| 294 |
+
font-weight: bold;
|
| 295 |
+
color: #333;
|
| 296 |
+
'>Prompt: {prompt}</p>
|
| 297 |
+
</div>
|
| 298 |
+
"""
|
| 299 |
|
| 300 |
+
gallery_html += "</div>"
|
| 301 |
+
gr.HTML(gallery_html)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
# Examples ์น์
|
| 304 |
gr.Examples(
|
| 305 |
examples=examples,
|
| 306 |
inputs=prompt,
|
| 307 |
outputs=output,
|
| 308 |
+
fn=process_example,
|
| 309 |
cache_examples=False,
|
| 310 |
examples_per_page=5
|
| 311 |
)
|