soumyanilain commited on
Commit
4d0cf5b
·
verified ·
1 Parent(s): 4909fe4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -102
app.py CHANGED
@@ -140,18 +140,13 @@ def render_overlay(joints, text=""):
140
  ax.plot(joints[f,v,0], joints[f,v,2], joints[f,v,1],
141
  color=co, lw=lw, alpha=a, marker="o", ms=2.5*a)
142
  r = joints[:,0,:]
143
- ax.plot(r[:,0], r[:,2], r[:,1], color="white", lw=1, alpha=0.5, ls="--", label="Root")
144
  title = text[:55] if text else "Generated Motion"
145
- ax.set_title(f"{title}\n{nf} frames @ ~20fps", fontsize=11, color="white")
146
  ax.set_xlabel("X"); ax.set_ylabel("Z"); ax.set_zlabel("Y")
147
- ax.set_facecolor("#0F172A"); fig.patch.set_facecolor("#0F172A")
148
- ax.tick_params(colors="#94A3B8")
149
- ax.xaxis.label.set_color("#94A3B8")
150
- ax.yaxis.label.set_color("#94A3B8")
151
- ax.zaxis.label.set_color("#94A3B8")
152
- ax.legend(fontsize=8, facecolor="#1E293B", labelcolor="white")
153
  tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
154
- plt.savefig(tmp.name, dpi=120, bbox_inches="tight", facecolor="#0F172A")
155
  plt.close(fig)
156
  return tmp.name
157
 
@@ -245,21 +240,19 @@ CUSTOM_CSS = """
245
  /* Hide default footer */
246
  footer { display: none !important; }
247
 
248
- /* Dark theme overrides */
249
- .gradio-container {
250
- background: #0F172A !important;
251
- color: #E2E8F0 !important;
252
- }
253
-
254
- /* Header styling */
255
  .header-banner {
256
- background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
257
- border: 1px solid #1E293B;
258
  border-radius: 16px;
259
  padding: 32px 24px 24px;
260
  margin-bottom: 20px;
261
  text-align: center;
262
  }
 
 
 
 
263
  .header-banner h1 {
264
  font-size: 2.8em;
265
  font-weight: 800;
@@ -270,10 +263,12 @@ footer { display: none !important; }
270
  letter-spacing: -0.5px;
271
  }
272
  .header-banner .subtitle {
273
- color: #94A3B8;
274
  font-size: 1.05em;
275
  margin: 0 0 18px;
276
  }
 
 
277
  .badge {
278
  display: inline-block;
279
  padding: 5px 14px;
@@ -285,39 +280,41 @@ footer { display: none !important; }
285
  }
286
  .badge-cyan { background: #06B6D4; color: white; }
287
  .badge-orange { background: #F97316; color: white; }
288
- .badge-slate { background: #334155; color: #CBD5E1; }
 
289
 
290
- /* Section cards */
291
- .input-section, .output-section {
292
- background: #1E293B !important;
293
- border: 1px solid #334155 !important;
294
- border-radius: 12px !important;
295
- padding: 16px !important;
296
  }
297
-
298
- /* Generate button */
299
- .generate-btn {
300
- background: linear-gradient(135deg, #06B6D4, #3B82F6) !important;
301
- border: none !important;
302
- font-weight: 700 !important;
303
- font-size: 1.05em !important;
304
- letter-spacing: 0.5px !important;
305
- border-radius: 10px !important;
306
- transition: all 0.2s ease !important;
307
  }
308
- .generate-btn:hover {
309
- transform: translateY(-1px) !important;
310
- box-shadow: 0 4px 20px rgba(6, 182, 212, 0.35) !important;
 
 
311
  }
312
 
313
- /* Architecture section */
314
  .arch-section {
315
- background: #1E293B;
316
- border: 1px solid #334155;
317
  border-radius: 12px;
318
  padding: 20px 24px;
319
  margin: 16px 0;
320
  }
 
 
 
 
321
  .arch-section h3 {
322
  color: #06B6D4;
323
  margin: 0 0 12px;
@@ -332,32 +329,80 @@ footer { display: none !important; }
332
  margin: 10px 0;
333
  }
334
  .arch-box {
335
- background: #334155;
336
  padding: 8px 16px;
337
  border-radius: 8px;
338
  font-size: 0.85em;
339
- color: #E2E8F0;
340
  font-weight: 600;
341
  text-align: center;
342
  }
 
 
 
 
343
  .arch-arrow {
344
  color: #06B6D4;
345
  font-size: 1.3em;
346
  font-weight: bold;
347
  }
348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  /* Footer */
350
  .custom-footer {
351
- background: #0B1120;
352
- border-top: 1px solid #1E293B;
353
  border-radius: 0 0 12px 12px;
354
  padding: 24px;
355
  margin-top: 24px;
356
  text-align: center;
357
  }
358
- .footer-links {
359
- margin-bottom: 12px;
 
360
  }
 
361
  .footer-links a {
362
  color: #06B6D4;
363
  text-decoration: none;
@@ -365,22 +410,21 @@ footer { display: none !important; }
365
  font-size: 0.9em;
366
  font-weight: 500;
367
  }
368
- .footer-links a:hover {
369
- text-decoration: underline;
370
- }
371
  .footer-copyright {
372
- color: #64748B;
373
  font-size: 0.8em;
374
  margin: 0;
375
  }
376
  .footer-divider {
377
  width: 60px;
378
  border: none;
379
- border-top: 2px solid #1E293B;
380
  margin: 12px auto;
381
  }
 
382
 
383
- /* Back to top button */
384
  .back-to-top {
385
  position: fixed;
386
  bottom: 24px;
@@ -406,42 +450,19 @@ footer { display: none !important; }
406
  transform: translateY(-2px);
407
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.5);
408
  }
409
-
410
- /* Stats row */
411
- .stats-row {
412
- display: flex;
413
- justify-content: center;
414
- gap: 24px;
415
- margin: 16px 0 0;
416
- flex-wrap: wrap;
417
- }
418
- .stat-item {
419
- text-align: center;
420
- }
421
- .stat-value {
422
- font-size: 1.4em;
423
- font-weight: 800;
424
- color: #06B6D4;
425
- }
426
- .stat-label {
427
- font-size: 0.75em;
428
- color: #64748B;
429
- text-transform: uppercase;
430
- letter-spacing: 0.5px;
431
- }
432
  """
433
 
434
  with gr.Blocks(
435
  title="MotionLCM - Real-Time Text-to-Motion",
436
- theme=gr.themes.Base(
437
  primary_hue="cyan",
438
- secondary_hue="orange",
439
  neutral_hue="slate",
440
  ),
441
- css=CUSTOM_CSS
442
  ) as demo:
443
 
444
- # Back to top button
445
  gr.HTML("""<a href="#" class="back-to-top" title="Back to top">&#8679;</a>""")
446
 
447
  # Header
@@ -455,27 +476,15 @@ with gr.Blocks(
455
  <span class="badge badge-slate">ECCV 2024</span>
456
  </div>
457
  <div class="stats-row">
458
- <div class="stat-item">
459
- <div class="stat-value">22</div>
460
- <div class="stat-label">Body Joints</div>
461
- </div>
462
- <div class="stat-item">
463
- <div class="stat-value">8.4M</div>
464
- <div class="stat-label">Parameters</div>
465
- </div>
466
- <div class="stat-item">
467
- <div class="stat-value">1-4</div>
468
- <div class="stat-label">Denoising Steps</div>
469
- </div>
470
- <div class="stat-item">
471
- <div class="stat-value">20</div>
472
- <div class="stat-label">FPS Output</div>
473
- </div>
474
  </div>
475
  </div>
476
  """)
477
 
478
- # Architecture overview
479
  gr.HTML("""
480
  <div class="arch-section">
481
  <h3>How It Works</h3>
@@ -484,7 +493,7 @@ with gr.Blocks(
484
  <span class="arch-arrow">&rarr;</span>
485
  <div class="arch-box">Sentence-T5<br><small style="color:#94A3B8">Text Encoder</small></div>
486
  <span class="arch-arrow">&rarr;</span>
487
- <div class="arch-box" style="border:1px solid #06B6D4">MotionLCM<br><small style="color:#06B6D4">1-4 Steps</small></div>
488
  <span class="arch-arrow">&rarr;</span>
489
  <div class="arch-box">Motion VAE<br><small style="color:#94A3B8">Decoder</small></div>
490
  <span class="arch-arrow">&rarr;</span>
@@ -495,7 +504,7 @@ with gr.Blocks(
495
 
496
  # Main interface
497
  with gr.Row():
498
- with gr.Column(scale=1, elem_classes="input-section"):
499
  prompt = gr.Textbox(
500
  label="Text Prompt",
501
  placeholder="Describe a human motion... e.g., 'a person walks forward and waves'",
@@ -507,12 +516,12 @@ with gr.Blocks(
507
  method = gr.Radio(
508
  ["MotionLCM (Real-time, 1-4 steps)", "MLD (Baseline, ~50 steps)"],
509
  value="MotionLCM (Real-time, 1-4 steps)",
510
- label="Generation Method"
511
  )
512
  btn = gr.Button("Generate Motion", variant="primary", size="lg",
513
  elem_classes="generate-btn")
514
 
515
- with gr.Column(scale=2, elem_classes="output-section"):
516
  with gr.Tabs():
517
  with gr.Tab("Animation"):
518
  vid = gr.Video(label="3D Skeleton Animation")
 
140
  ax.plot(joints[f,v,0], joints[f,v,2], joints[f,v,1],
141
  color=co, lw=lw, alpha=a, marker="o", ms=2.5*a)
142
  r = joints[:,0,:]
143
+ ax.plot(r[:,0], r[:,2], r[:,1], color="gray", lw=1, alpha=0.5, ls="--", label="Root")
144
  title = text[:55] if text else "Generated Motion"
145
+ ax.set_title(f"{title}\n{nf} frames @ ~20fps", fontsize=11)
146
  ax.set_xlabel("X"); ax.set_ylabel("Z"); ax.set_zlabel("Y")
147
+ ax.legend(fontsize=8)
 
 
 
 
 
148
  tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
149
+ plt.savefig(tmp.name, dpi=120, bbox_inches="tight")
150
  plt.close(fig)
151
  return tmp.name
152
 
 
240
  /* Hide default footer */
241
  footer { display: none !important; }
242
 
243
+ /* Header */
 
 
 
 
 
 
244
  .header-banner {
245
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
246
+ border: 1px solid #e2e8f0;
247
  border-radius: 16px;
248
  padding: 32px 24px 24px;
249
  margin-bottom: 20px;
250
  text-align: center;
251
  }
252
+ .dark .header-banner {
253
+ background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
254
+ border-color: #334155;
255
+ }
256
  .header-banner h1 {
257
  font-size: 2.8em;
258
  font-weight: 800;
 
263
  letter-spacing: -0.5px;
264
  }
265
  .header-banner .subtitle {
266
+ color: #64748B;
267
  font-size: 1.05em;
268
  margin: 0 0 18px;
269
  }
270
+ .dark .header-banner .subtitle { color: #94A3B8; }
271
+
272
  .badge {
273
  display: inline-block;
274
  padding: 5px 14px;
 
280
  }
281
  .badge-cyan { background: #06B6D4; color: white; }
282
  .badge-orange { background: #F97316; color: white; }
283
+ .badge-slate { background: #E2E8F0; color: #334155; }
284
+ .dark .badge-slate { background: #334155; color: #CBD5E1; }
285
 
286
+ .stats-row {
287
+ display: flex;
288
+ justify-content: center;
289
+ gap: 24px;
290
+ margin: 16px 0 0;
291
+ flex-wrap: wrap;
292
  }
293
+ .stat-item { text-align: center; }
294
+ .stat-value {
295
+ font-size: 1.4em;
296
+ font-weight: 800;
297
+ color: #06B6D4;
 
 
 
 
 
298
  }
299
+ .stat-label {
300
+ font-size: 0.75em;
301
+ color: #94A3B8;
302
+ text-transform: uppercase;
303
+ letter-spacing: 0.5px;
304
  }
305
 
306
+ /* Architecture */
307
  .arch-section {
308
+ background: #f1f5f9;
309
+ border: 1px solid #e2e8f0;
310
  border-radius: 12px;
311
  padding: 20px 24px;
312
  margin: 16px 0;
313
  }
314
+ .dark .arch-section {
315
+ background: #1E293B;
316
+ border-color: #334155;
317
+ }
318
  .arch-section h3 {
319
  color: #06B6D4;
320
  margin: 0 0 12px;
 
329
  margin: 10px 0;
330
  }
331
  .arch-box {
332
+ background: #e2e8f0;
333
  padding: 8px 16px;
334
  border-radius: 8px;
335
  font-size: 0.85em;
336
+ color: #1e293b;
337
  font-weight: 600;
338
  text-align: center;
339
  }
340
+ .dark .arch-box {
341
+ background: #334155;
342
+ color: #E2E8F0;
343
+ }
344
  .arch-arrow {
345
  color: #06B6D4;
346
  font-size: 1.3em;
347
  font-weight: bold;
348
  }
349
 
350
+ /* Generate button */
351
+ .generate-btn {
352
+ background: linear-gradient(135deg, #06B6D4, #3B82F6) !important;
353
+ border: none !important;
354
+ color: white !important;
355
+ font-weight: 700 !important;
356
+ font-size: 1.05em !important;
357
+ letter-spacing: 0.5px !important;
358
+ border-radius: 10px !important;
359
+ transition: all 0.2s ease !important;
360
+ }
361
+ .generate-btn:hover {
362
+ transform: translateY(-1px) !important;
363
+ box-shadow: 0 4px 20px rgba(6, 182, 212, 0.35) !important;
364
+ }
365
+
366
+ /* Examples table */
367
+ table thead th {
368
+ background: #f1f5f9 !important;
369
+ color: #334155 !important;
370
+ font-weight: 600 !important;
371
+ }
372
+ .dark table thead th {
373
+ background: #334155 !important;
374
+ color: #E2E8F0 !important;
375
+ }
376
+ table tbody td {
377
+ color: #334155 !important;
378
+ }
379
+ .dark table tbody td {
380
+ background: #1E293B !important;
381
+ color: #CBD5E1 !important;
382
+ border-color: #334155 !important;
383
+ }
384
+ table tbody tr:hover td {
385
+ background: #e2e8f0 !important;
386
+ cursor: pointer;
387
+ }
388
+ .dark table tbody tr:hover td {
389
+ background: #334155 !important;
390
+ }
391
+
392
  /* Footer */
393
  .custom-footer {
394
+ background: #f8fafc;
395
+ border-top: 1px solid #e2e8f0;
396
  border-radius: 0 0 12px 12px;
397
  padding: 24px;
398
  margin-top: 24px;
399
  text-align: center;
400
  }
401
+ .dark .custom-footer {
402
+ background: #0B1120;
403
+ border-color: #1E293B;
404
  }
405
+ .footer-links { margin-bottom: 12px; }
406
  .footer-links a {
407
  color: #06B6D4;
408
  text-decoration: none;
 
410
  font-size: 0.9em;
411
  font-weight: 500;
412
  }
413
+ .footer-links a:hover { text-decoration: underline; }
 
 
414
  .footer-copyright {
415
+ color: #94A3B8;
416
  font-size: 0.8em;
417
  margin: 0;
418
  }
419
  .footer-divider {
420
  width: 60px;
421
  border: none;
422
+ border-top: 2px solid #e2e8f0;
423
  margin: 12px auto;
424
  }
425
+ .dark .footer-divider { border-color: #1E293B; }
426
 
427
+ /* Back to top */
428
  .back-to-top {
429
  position: fixed;
430
  bottom: 24px;
 
450
  transform: translateY(-2px);
451
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.5);
452
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  """
454
 
455
  with gr.Blocks(
456
  title="MotionLCM - Real-Time Text-to-Motion",
457
+ theme=gr.themes.Soft(
458
  primary_hue="cyan",
459
+ secondary_hue="blue",
460
  neutral_hue="slate",
461
  ),
462
+ css=CUSTOM_CSS,
463
  ) as demo:
464
 
465
+ # Back to top
466
  gr.HTML("""<a href="#" class="back-to-top" title="Back to top">&#8679;</a>""")
467
 
468
  # Header
 
476
  <span class="badge badge-slate">ECCV 2024</span>
477
  </div>
478
  <div class="stats-row">
479
+ <div class="stat-item"><div class="stat-value">22</div><div class="stat-label">Body Joints</div></div>
480
+ <div class="stat-item"><div class="stat-value">8.4M</div><div class="stat-label">Parameters</div></div>
481
+ <div class="stat-item"><div class="stat-value">1-4</div><div class="stat-label">Denoising Steps</div></div>
482
+ <div class="stat-item"><div class="stat-value">20</div><div class="stat-label">FPS Output</div></div>
 
 
 
 
 
 
 
 
 
 
 
 
483
  </div>
484
  </div>
485
  """)
486
 
487
+ # Architecture
488
  gr.HTML("""
489
  <div class="arch-section">
490
  <h3>How It Works</h3>
 
493
  <span class="arch-arrow">&rarr;</span>
494
  <div class="arch-box">Sentence-T5<br><small style="color:#94A3B8">Text Encoder</small></div>
495
  <span class="arch-arrow">&rarr;</span>
496
+ <div class="arch-box" style="border:2px solid #06B6D4">MotionLCM<br><small style="color:#06B6D4">1-4 Steps</small></div>
497
  <span class="arch-arrow">&rarr;</span>
498
  <div class="arch-box">Motion VAE<br><small style="color:#94A3B8">Decoder</small></div>
499
  <span class="arch-arrow">&rarr;</span>
 
504
 
505
  # Main interface
506
  with gr.Row():
507
+ with gr.Column(scale=1):
508
  prompt = gr.Textbox(
509
  label="Text Prompt",
510
  placeholder="Describe a human motion... e.g., 'a person walks forward and waves'",
 
516
  method = gr.Radio(
517
  ["MotionLCM (Real-time, 1-4 steps)", "MLD (Baseline, ~50 steps)"],
518
  value="MotionLCM (Real-time, 1-4 steps)",
519
+ label="Generation Method",
520
  )
521
  btn = gr.Button("Generate Motion", variant="primary", size="lg",
522
  elem_classes="generate-btn")
523
 
524
+ with gr.Column(scale=2):
525
  with gr.Tabs():
526
  with gr.Tab("Animation"):
527
  vid = gr.Video(label="3D Skeleton Animation")