qqwjq1981 commited on
Commit
26c1b15
·
verified ·
1 Parent(s): 8d922da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -2,7 +2,7 @@
2
  import json
3
  import math
4
  import gradio as gr
5
- from PIL import Image
6
  import os
7
  from utils.keyframe_utils import generate_keyframe_prompt
8
 
@@ -23,12 +23,36 @@ def get_keyframe_images(segment_id):
23
  images.append(Image.new("RGB", (256, 144), color=(200, 200, 200)))
24
  return images
25
 
26
- # UI component for a single segment row
27
  def segment_display(segment):
28
- description = segment["description"]
29
- seg_id = segment["segment_id"]
30
- row = [f"Segment {seg_id}", description]
31
- row.extend(get_keyframe_images(seg_id))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  return row
33
 
34
  # Pagination logic
 
2
  import json
3
  import math
4
  import gradio as gr
5
+ from PIL import Image, ImageDraw
6
  import os
7
  from utils.keyframe_utils import generate_keyframe_prompt
8
 
 
23
  images.append(Image.new("RGB", (256, 144), color=(200, 200, 200)))
24
  return images
25
 
26
+
27
  def segment_display(segment):
28
+ """
29
+ Format one row for Gradio display:
30
+ - Truncate and wrap description
31
+ - Load and resize keyframe images to thumbnail size
32
+ """
33
+ seg_id = segment.get("segment_id")
34
+ description = segment.get("description", "")
35
+ short_desc = description if len(description) <= 120 else description[:117] + "..."
36
+
37
+ # Wrap long text with newlines every ~40 chars
38
+ def wrap_text(text, width=40):
39
+ return "\n".join([text[i:i+width] for i in range(0, len(text), width)])
40
+
41
+ display_desc = wrap_text(short_desc)
42
+
43
+ row = [f"Segment {seg_id}", display_desc]
44
+
45
+ for i in range(1, 4):
46
+ img_path = f"keyframes/segment_{seg_id}_v{i}.png"
47
+ if os.path.exists(img_path):
48
+ img = Image.open(img_path).resize((128, 72))
49
+ else:
50
+ # Placeholder if not found
51
+ img = Image.new("RGB", (128, 72), color=(200, 200, 200))
52
+ draw = ImageDraw.Draw(img)
53
+ draw.text((10, 30), "No Image", fill=(0, 0, 0))
54
+ row.append(img)
55
+
56
  return row
57
 
58
  # Pagination logic