kerojohan commited on
Commit
0b4d993
·
1 Parent(s): 8057fce

Restore examples table behavior with thumbnail column

Browse files
Files changed (1) hide show
  1. app.py +42 -94
app.py CHANGED
@@ -45,62 +45,20 @@ def _format_duration_hms(seconds: float) -> str:
45
 
46
 
47
  # Pesos según la ficha del bucket HF; duraciones comprobadas con ffprobe sobre la URL resolve.
48
- EXAMPLE_VIDEOS = [
49
- {
50
- "name": "Rabella",
51
- "url": EXAMPLE_VIDEO_RABELLA,
52
- "size": "39,3 MB",
53
- "duration": _format_duration_hms(60.095667),
54
- },
55
- {
56
- "name": "Provagran2",
57
- "url": EXAMPLE_VIDEO_PROVAGRAN2,
58
- "size": "862 MB",
59
- "duration": _format_duration_hms(600.0),
60
- },
61
  ]
62
-
63
-
64
- def _build_examples_table_html() -> str:
65
- rows: list[str] = []
66
- for idx, example in enumerate(EXAMPLE_VIDEOS, start=1):
67
- rows.append(
68
- f"""
69
- <tr>
70
- <td>{idx}</td>
71
- <td>
72
- <div class="example-thumb-wrap">
73
- <video class="example-thumb" src="{example["url"]}" preload="metadata" muted playsinline></video>
74
- </div>
75
- </td>
76
- <td>{example["name"]}</td>
77
- <td>{example["size"]}</td>
78
- <td>{example["duration"]}</td>
79
- </tr>
80
- """
81
- )
82
- return (
83
- """
84
- <div class="examples-table-shell">
85
- <table class="examples-table">
86
- <thead>
87
- <tr>
88
- <th>#</th>
89
- <th>Miniatura</th>
90
- <th>Vídeo</th>
91
- <th>Peso</th>
92
- <th>Duración</th>
93
- </tr>
94
- </thead>
95
- <tbody>
96
- """
97
- + "".join(rows)
98
- + """
99
- </tbody>
100
- </table>
101
- </div>
102
- """
103
- )
104
  def _prepare_config(config_file: str | None, work_dir: Path) -> Path:
105
  source_path = Path(config_file) if config_file else DEFAULT_CONFIG_PATH
106
  if not source_path.exists():
@@ -324,50 +282,19 @@ APP_CSS = """
324
  }
325
 
326
  .examples-footer .gr-examples tbody td:first-child {
327
- max-width: 220px;
328
- }
329
-
330
- .examples-table {
331
- width: 100%;
332
- border-collapse: collapse;
333
- font-size: 0.95rem;
334
- color: #2a231c;
335
- margin-top: 10px;
336
- }
337
-
338
- .examples-table th,
339
- .examples-table td {
340
- text-align: left;
341
- padding: 10px 12px;
342
- border-bottom: 1px solid #e2d8c9;
343
- vertical-align: middle;
344
- }
345
-
346
- .examples-table th {
347
- background: #ebe3d4;
348
- color: #3d352b;
349
- font-weight: 700;
350
  }
351
 
352
- .examples-table tr:last-child td {
353
- border-bottom: none;
354
- }
355
-
356
- .example-thumb-wrap {
357
  width: 112px;
358
  height: 64px;
359
- overflow: hidden;
360
- border-radius: 10px;
361
- background: #1b1510;
362
- border: 1px solid #c5bcab;
363
- }
364
-
365
- .example-thumb {
366
- width: 100%;
367
- height: 100%;
368
  object-fit: cover;
369
  display: block;
 
370
  background: #1b1510;
 
371
  }
372
 
373
  .config-note,
@@ -418,6 +345,21 @@ with gr.Blocks(title=APP_TITLE) as demo:
418
  "Si no subes configuración, se usará `config.out3_clean.yaml`.",
419
  elem_classes=["config-note"],
420
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  with gr.Column(scale=1, elem_classes=["panel"]):
422
  gr.HTML('<div class="section-kicker">Resumen</div>')
423
  summary_output = gr.Textbox(
@@ -457,11 +399,17 @@ with gr.Blocks(title=APP_TITLE) as demo:
457
  with gr.Column(elem_classes=["examples-footer"]):
458
  gr.Markdown(
459
  "### Ejemplos de vídeo\n"
460
- "La tabla muestra una miniatura de cada vídeo. "
461
  "**Peso** y **duración** corresponden al archivo original en el bucket. "
462
  "El segundo ejemplo es muy grande y puede tardar en descargarse."
463
  )
464
- gr.HTML(_build_examples_table_html())
 
 
 
 
 
 
465
 
466
  run_button.click(
467
  fn=process_video,
 
45
 
46
 
47
  # Pesos según la ficha del bucket HF; duraciones comprobadas con ffprobe sobre la URL resolve.
48
+ EXAMPLE_VIDEO_ROWS: list[tuple[str, str, str, str]] = [
49
+ (
50
+ EXAMPLE_VIDEO_RABELLA,
51
+ EXAMPLE_VIDEO_RABELLA,
52
+ "39,3 MB",
53
+ _format_duration_hms(60.095667),
54
+ ),
55
+ (
56
+ EXAMPLE_VIDEO_PROVAGRAN2,
57
+ EXAMPLE_VIDEO_PROVAGRAN2,
58
+ "862 MB",
59
+ _format_duration_hms(600.0),
60
+ ),
61
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  def _prepare_config(config_file: str | None, work_dir: Path) -> Path:
63
  source_path = Path(config_file) if config_file else DEFAULT_CONFIG_PATH
64
  if not source_path.exists():
 
282
  }
283
 
284
  .examples-footer .gr-examples tbody td:first-child {
285
+ width: 136px;
286
+ min-width: 136px;
287
+ max-width: 136px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  }
289
 
290
+ .examples-footer .gr-examples tbody td:first-child video {
 
 
 
 
291
  width: 112px;
292
  height: 64px;
 
 
 
 
 
 
 
 
 
293
  object-fit: cover;
294
  display: block;
295
+ border-radius: 10px;
296
  background: #1b1510;
297
+ border: 1px solid #c5bcab;
298
  }
299
 
300
  .config-note,
 
345
  "Si no subes configuración, se usará `config.out3_clean.yaml`.",
346
  elem_classes=["config-note"],
347
  )
348
+ example_thumbnail = gr.Video(
349
+ label="Miniatura",
350
+ interactive=False,
351
+ visible=False,
352
+ )
353
+ example_file_size = gr.Textbox(
354
+ label="Peso (original)",
355
+ interactive=False,
356
+ visible=False,
357
+ )
358
+ example_duration = gr.Textbox(
359
+ label="Duración",
360
+ interactive=False,
361
+ visible=False,
362
+ )
363
  with gr.Column(scale=1, elem_classes=["panel"]):
364
  gr.HTML('<div class="section-kicker">Resumen</div>')
365
  summary_output = gr.Textbox(
 
399
  with gr.Column(elem_classes=["examples-footer"]):
400
  gr.Markdown(
401
  "### Ejemplos de vídeo\n"
402
+ "Pulsa una fila de la tabla para cargar ese vídeo en **Video de entrada** (arriba). "
403
  "**Peso** y **duración** corresponden al archivo original en el bucket. "
404
  "El segundo ejemplo es muy grande y puede tardar en descargarse."
405
  )
406
+ gr.Examples(
407
+ examples=[list(row) for row in EXAMPLE_VIDEO_ROWS],
408
+ inputs=[example_thumbnail, video_input, example_file_size, example_duration],
409
+ label="Vídeos de ejemplo",
410
+ cache_examples=False,
411
+ examples_per_page=6,
412
+ )
413
 
414
  run_button.click(
415
  fn=process_video,