Spaces:
Running
Running
feat: improve layout and organization of example selection
Browse files
app.py
CHANGED
|
@@ -304,13 +304,14 @@ example_list = {
|
|
| 304 |
"Animals": [
|
| 305 |
[os.path.join(os.path.dirname(__file__), "examples/corgi.svg"), "corgi"],
|
| 306 |
[os.path.join(os.path.dirname(__file__), "examples/duck.svg"), "duck"],
|
| 307 |
-
[os.path.join(os.path.dirname(__file__), "examples/whale.svg"), "whale"]
|
| 308 |
],
|
| 309 |
"Objects": [
|
| 310 |
[os.path.join(os.path.dirname(__file__), "examples/rocket.svg"), "rocket"]
|
| 311 |
-
]
|
| 312 |
}
|
| 313 |
|
|
|
|
| 314 |
def load_example(example_choice):
|
| 315 |
# Find the selected example in the categories
|
| 316 |
for category, examples in example_list.items():
|
|
@@ -319,8 +320,11 @@ def load_example(example_choice):
|
|
| 319 |
return example[0] # Return the file path
|
| 320 |
return None
|
| 321 |
|
|
|
|
| 322 |
# Flatten choices for dropdown
|
| 323 |
-
example_choices = [
|
|
|
|
|
|
|
| 324 |
|
| 325 |
demo = gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft())
|
| 326 |
with demo:
|
|
@@ -338,85 +342,84 @@ with demo:
|
|
| 338 |
label="Or Paste SVG Code",
|
| 339 |
lines=8.4,
|
| 340 |
)
|
| 341 |
-
|
| 342 |
# Add example dropdown
|
| 343 |
example_dropdown = gr.Dropdown(
|
| 344 |
-
choices=example_choices,
|
| 345 |
-
label="Try an Example",
|
| 346 |
-
value=None
|
| 347 |
)
|
| 348 |
|
| 349 |
# Add dropdown change event
|
| 350 |
example_dropdown.change(
|
| 351 |
-
fn=load_example,
|
| 352 |
-
inputs=[example_dropdown],
|
| 353 |
-
outputs=[svg_file]
|
| 354 |
)
|
| 355 |
|
| 356 |
-
with gr.
|
| 357 |
-
with gr.
|
| 358 |
-
gr.
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
gr.
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
)
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
-
|
| 390 |
-
gr.
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
gr.Markdown("## 🖼️ Decomposed Structure")
|
| 401 |
-
decomposed_svg_viewer = gr.HTML(
|
| 402 |
-
label="Decomposed SVG",
|
| 403 |
-
value="""
|
| 404 |
-
<div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
|
| 405 |
-
<div id='decomposed-svg-container' style='min-height: 150px; display: flex; justify-content: center; align-items: center; border-radius: 4px; padding: 10px;'>
|
| 406 |
-
<div style='color: #999; text-align: center;'>Decomposed SVG structure will appear here</div>
|
| 407 |
</div>
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
)
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
|
| 421 |
process_btn.click(
|
| 422 |
fn=predict_decompose_group,
|
|
|
|
| 304 |
"Animals": [
|
| 305 |
[os.path.join(os.path.dirname(__file__), "examples/corgi.svg"), "corgi"],
|
| 306 |
[os.path.join(os.path.dirname(__file__), "examples/duck.svg"), "duck"],
|
| 307 |
+
[os.path.join(os.path.dirname(__file__), "examples/whale.svg"), "whale"],
|
| 308 |
],
|
| 309 |
"Objects": [
|
| 310 |
[os.path.join(os.path.dirname(__file__), "examples/rocket.svg"), "rocket"]
|
| 311 |
+
],
|
| 312 |
}
|
| 313 |
|
| 314 |
+
|
| 315 |
def load_example(example_choice):
|
| 316 |
# Find the selected example in the categories
|
| 317 |
for category, examples in example_list.items():
|
|
|
|
| 320 |
return example[0] # Return the file path
|
| 321 |
return None
|
| 322 |
|
| 323 |
+
|
| 324 |
# Flatten choices for dropdown
|
| 325 |
+
example_choices = [
|
| 326 |
+
example[1] for category in example_list.values() for example in category
|
| 327 |
+
]
|
| 328 |
|
| 329 |
demo = gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft())
|
| 330 |
with demo:
|
|
|
|
| 342 |
label="Or Paste SVG Code",
|
| 343 |
lines=8.4,
|
| 344 |
)
|
| 345 |
+
|
| 346 |
# Add example dropdown
|
| 347 |
example_dropdown = gr.Dropdown(
|
| 348 |
+
choices=example_choices, label="Try an Example", value=None
|
|
|
|
|
|
|
| 349 |
)
|
| 350 |
|
| 351 |
# Add dropdown change event
|
| 352 |
example_dropdown.change(
|
| 353 |
+
fn=load_example, inputs=[example_dropdown], outputs=[svg_file]
|
|
|
|
|
|
|
| 354 |
)
|
| 355 |
|
| 356 |
+
with gr.Column(scale=1):
|
| 357 |
+
with gr.Row(scale=1):
|
| 358 |
+
with gr.Column(scale=1):
|
| 359 |
+
gr.Markdown("## 🔍 SVG Analysis")
|
| 360 |
+
object_name = gr.Textbox(
|
| 361 |
+
label="Name Your Object",
|
| 362 |
+
placeholder="Give a name to your SVG (e.g., 'dove', 'robot')",
|
| 363 |
+
value="object",
|
| 364 |
+
)
|
| 365 |
+
process_btn = gr.Button("🔄 Decompose Structure", variant="primary")
|
| 366 |
+
groups_summary = gr.Textbox(
|
| 367 |
+
label="Decomposition Results",
|
| 368 |
+
placeholder="MLLM will analyze and decompose the SVG structure...",
|
| 369 |
+
lines=6,
|
| 370 |
+
interactive=False,
|
| 371 |
+
)
|
| 372 |
+
with gr.Column(scale=1):
|
| 373 |
+
gr.Markdown("## 🎯 Animation Design")
|
| 374 |
+
animation_suggestion = gr.Textbox(
|
| 375 |
+
label="AI Suggestions",
|
| 376 |
+
placeholder="MLLM will suggest animations based on the decomposed structure...",
|
| 377 |
+
lines=14.5,
|
| 378 |
+
)
|
| 379 |
+
with gr.Row(scale=1):
|
| 380 |
+
with gr.Column(scale=1):
|
| 381 |
+
gr.Markdown("## 💡 Decomposed Elements")
|
| 382 |
+
groups_feedback = gr.Textbox(
|
| 383 |
+
label="Element Structure",
|
| 384 |
+
placeholder="If you have specific decomposition in mind, describe it here...",
|
| 385 |
+
lines=2,
|
| 386 |
+
)
|
| 387 |
+
groups_feedback_btn = gr.Button(
|
| 388 |
+
"💭 Apply Decomposition Feedback", variant="primary"
|
| 389 |
+
)
|
| 390 |
+
with gr.Column(scale=1):
|
| 391 |
+
gr.Markdown("## ✨ Create Animation")
|
| 392 |
+
describe_animation = gr.Textbox(
|
| 393 |
+
label="Animation Description",
|
| 394 |
+
placeholder="Describe your desired animation (e.g., 'gentle floating motion')",
|
| 395 |
+
lines=2,
|
| 396 |
+
)
|
| 397 |
+
animate_btn = gr.Button("🎬 Generate Animation", variant="primary")
|
| 398 |
|
| 399 |
+
with gr.Row(scale=3):
|
| 400 |
+
with gr.Column(scale=1):
|
| 401 |
+
svg_content_hidden = gr.Textbox(visible=False)
|
| 402 |
+
gr.Markdown("## 🖼️ Decomposed Structure")
|
| 403 |
+
decomposed_svg_viewer = gr.HTML(
|
| 404 |
+
label="Decomposed SVG",
|
| 405 |
+
value="""
|
| 406 |
+
<div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
|
| 407 |
+
<div id='decomposed-svg-container' style='min-height: 150px; display: flex; justify-content: center; align-items: center; border-radius: 4px; padding: 10px;'>
|
| 408 |
+
<div style='color: #999; text-align: center;'>Decomposed SVG structure will appear here</div>
|
| 409 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
</div>
|
| 411 |
+
""",
|
| 412 |
+
)
|
| 413 |
+
with gr.Column(scale=1):
|
| 414 |
+
gr.Markdown("## 🎭 Animation Preview")
|
| 415 |
+
animation_preview = gr.HTML(
|
| 416 |
+
label="Live Preview",
|
| 417 |
+
value="""
|
| 418 |
+
<div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
|
| 419 |
+
AI-powered animation generation</p>
|
| 420 |
+
</div>
|
| 421 |
+
""",
|
| 422 |
+
)
|
| 423 |
|
| 424 |
process_btn.click(
|
| 425 |
fn=predict_decompose_group,
|