Milhaud commited on
Commit
329ef11
Β·
1 Parent(s): 3692442

feat: add example selection feature to SVG Animation Generator

Browse files
Files changed (1) hide show
  1. app.py +90 -52
app.py CHANGED
@@ -299,7 +299,31 @@ def create_error_html(message: str) -> str:
299
  """
300
 
301
 
302
- with gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft()) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  gr.Markdown("# 🎨 SVG Decomposition & Animation Generator")
304
  gr.Markdown(
305
  "Intelligent SVG decomposition and animation generation powered by MLLM. This tool decomposes SVG structures and generates animations based on your descriptions."
@@ -314,70 +338,85 @@ with gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft()) as demo:
314
  label="Or Paste SVG Code",
315
  lines=8.4,
316
  )
317
- with gr.Row(scale=1):
318
- with gr.Column(scale=1):
319
- gr.Markdown("## πŸ” SVG Analysis")
320
- object_name = gr.Textbox(
321
- label="Name Your Object",
322
- placeholder="Give a name to your SVG (e.g., 'dove', 'robot')",
323
- value="object",
324
- )
325
- process_btn = gr.Button("πŸ”„ Decompose Structure", variant="primary")
326
- groups_summary = gr.Textbox(
327
- label="Decomposition Results",
328
- placeholder="MLLM will analyze and decompose the SVG structure...",
329
- lines=6,
330
- interactive=False,
331
  )
332
 
333
- gr.Markdown("## πŸ’‘ Decomposed Elements")
334
- groups_feedback = gr.Textbox(
335
- label="Element Structure",
336
- placeholder="If you have specific decomposition in mind, describe it here...",
337
- lines=2,
338
- )
339
- groups_feedback_btn = gr.Button(
340
- "πŸ’­ Get Decomposition Feedback", variant="primary"
341
- )
342
 
343
- gr.Markdown("## 🎯 Animation Design")
344
- animation_suggestion = gr.Textbox(
345
- label="AI Suggestions",
346
- placeholder="MLLM will suggest animations based on the decomposed structure...",
347
- lines=4,
348
- )
 
 
 
 
 
 
 
 
 
349
 
350
- gr.Markdown("## ✨ Create Animation")
351
- gr.Markdown("πŸ’¬ **What animation would you like to create?**")
352
- describe_animation = gr.Textbox(
353
- label="Animation Description",
354
- placeholder="Describe your desired animation (e.g., 'gentle floating motion')",
355
- lines=2,
356
- )
357
- animate_btn = gr.Button("🎬 Generate Animation", variant="primary")
358
-
359
- with gr.Column(scale=2):
360
- svg_content_hidden = gr.Textbox(visible=False)
361
- gr.Markdown("## πŸ–ΌοΈ Decomposed Structure")
362
- decomposed_svg_viewer = gr.HTML(
363
- label="Decomposed SVG",
364
- value="""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  <div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
366
  <div id='decomposed-svg-container' style='min-height: 150px; display: flex; justify-content: center; align-items: center; border-radius: 4px; padding: 10px;'>
367
  <div style='color: #999; text-align: center;'>Decomposed SVG structure will appear here</div>
368
  </div>
369
  </div>
370
  """,
371
- )
372
- gr.Markdown("## 🎭 Animation Preview")
373
- animation_preview = gr.HTML(
374
- label="Live Preview",
375
- value="""
376
  <div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
377
  AI-powered animation generation</p>
378
  </div>
379
  """,
380
- )
381
 
382
  process_btn.click(
383
  fn=predict_decompose_group,
@@ -409,6 +448,5 @@ with gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft()) as demo:
409
  ],
410
  outputs=[animation_preview],
411
  )
412
-
413
  if __name__ == "__main__":
414
  demo.launch(share=True)
 
299
  """
300
 
301
 
302
+ # Define examples with proper path handling and categories
303
+ 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():
317
+ for example in examples:
318
+ if example[1] == example_choice:
319
+ return example[0] # Return the file path
320
+ return None
321
+
322
+ # Flatten choices for dropdown
323
+ example_choices = [example[1] for category in example_list.values() for example in category]
324
+
325
+ demo = gr.Blocks(title="SVG Animation Generator", theme=gr.themes.Soft())
326
+ with demo:
327
  gr.Markdown("# 🎨 SVG Decomposition & Animation Generator")
328
  gr.Markdown(
329
  "Intelligent SVG decomposition and animation generation powered by MLLM. This tool decomposes SVG structures and generates animations based on your descriptions."
 
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.Row(scale=1):
357
+ with gr.Column(scale=1):
358
+ gr.Markdown("## πŸ” SVG Analysis")
359
+ object_name = gr.Textbox(
360
+ label="Name Your Object",
361
+ placeholder="Give a name to your SVG (e.g., 'dove', 'robot')",
362
+ value="object",
363
+ )
364
+ process_btn = gr.Button("πŸ”„ Decompose Structure", variant="primary")
365
+ groups_summary = gr.Textbox(
366
+ label="Decomposition Results",
367
+ placeholder="MLLM will analyze and decompose the SVG structure...",
368
+ lines=6,
369
+ interactive=False,
370
+ )
371
 
372
+ gr.Markdown("## πŸ’‘ Decomposed Elements")
373
+ groups_feedback = gr.Textbox(
374
+ label="Element Structure",
375
+ placeholder="If you have specific decomposition in mind, describe it here...",
376
+ lines=2,
377
+ )
378
+ groups_feedback_btn = gr.Button(
379
+ "πŸ’­ Get Decomposition Feedback", variant="primary"
380
+ )
381
+
382
+ gr.Markdown("## 🎯 Animation Design")
383
+ animation_suggestion = gr.Textbox(
384
+ label="AI Suggestions",
385
+ placeholder="MLLM will suggest animations based on the decomposed structure...",
386
+ lines=4,
387
+ )
388
+
389
+ gr.Markdown("## ✨ Create Animation")
390
+ gr.Markdown("πŸ’¬ **What animation would you like to create?**")
391
+ describe_animation = gr.Textbox(
392
+ label="Animation Description",
393
+ placeholder="Describe your desired animation (e.g., 'gentle floating motion')",
394
+ lines=2,
395
+ )
396
+ animate_btn = gr.Button("🎬 Generate Animation", variant="primary")
397
+
398
+ with gr.Column(scale=2):
399
+ svg_content_hidden = gr.Textbox(visible=False)
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
  </div>
409
  """,
410
+ )
411
+ gr.Markdown("## 🎭 Animation Preview")
412
+ animation_preview = gr.HTML(
413
+ label="Live Preview",
414
+ value="""
415
  <div style='padding: 40px; text-align: center; color: #666; border: 2px dashed #ddd; border-radius: 10px;'>
416
  AI-powered animation generation</p>
417
  </div>
418
  """,
419
+ )
420
 
421
  process_btn.click(
422
  fn=predict_decompose_group,
 
448
  ],
449
  outputs=[animation_preview],
450
  )
 
451
  if __name__ == "__main__":
452
  demo.launch(share=True)