PierreBrunelle commited on
Commit
cd1a88f
1 Parent(s): 7f4e676

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -34
app.py CHANGED
@@ -18,11 +18,8 @@ import PIL.Image
18
  import PIL.ImageDraw
19
 
20
  # Creating a UDF to draw bounding boxes
21
-
22
  @pxt.udf
23
- def draw_boxes(
24
- img: PIL.Image.Image, boxes: list[list[float]]
25
- ) -> PIL.Image.Image:
26
  result = img.copy() # Create a copy of `img`
27
  d = PIL.ImageDraw.Draw(result)
28
  for box in boxes:
@@ -52,11 +49,7 @@ def process_video(video_file, model_id, threshold, progress=gr.Progress()):
52
  )
53
 
54
  # Insert video into Pixeltable table
55
- videos_table.insert([
56
- {
57
- 'video': video_file.name
58
- }
59
- ])
60
 
61
  progress(0.3, desc="Running Model...")
62
 
@@ -113,39 +106,37 @@ with gr.Blocks(theme=Soft()) as demo:
113
  )
114
 
115
  with gr.Row():
116
- with gr.Column():
117
- with gr.Accordion("What This Demo Does", open=True):
118
- gr.Markdown("""
119
- 1. **Ingests Videos**: Uploads your Video.
120
- 2. **Process and Retrieve Data**: Store, version, chunk, and retrieve video and frames.
121
- 3. **Detects Objects**: Leverages Pixeltable's YOLOX integration to produce object detection results.
122
- 4. **Visualizes Output**: Displays the processed video alongside a sample of the original frames.
123
- """)
124
 
125
  # File upload components for ground truth and PDF documents
126
  with gr.Row():
127
  video_file = gr.File(label="Upload Video", file_count="single")
128
 
129
- # Add controls for chunking parameters
130
  with gr.Row():
131
- model_id = gr.Dropdown(
132
  choices=['yolox_tiny', 'yolox_m', 'yolox_x'],
133
  value='yolox_tiny',
134
  label="YOLOX Model"
135
- )
 
136
 
137
- threshold = gr.Slider(minimum=0.1, maximum=0.9, value=0.25, step=0.05, label="Threshold")
138
-
139
- with gr.Column():
140
- gr.Examples(
141
- examples=[
142
  ["bangkok.mp4", "yolox_tiny", 0.25],
143
  ["lotr.mp4", "yolox_m", 0.3],
144
  ["mi.mp4", "yolox_tiny", 0.5],
145
- ],
146
- inputs=[video_file, model_id, threshold],
147
- fn=process_video
148
- )
149
 
150
  # Button to trigger file processing
151
  process_button = gr.Button("Process Video")
@@ -156,11 +147,11 @@ with gr.Blocks(theme=Soft()) as demo:
156
  with gr.Row():
157
  frame_gallery = gr.Gallery(label="Frame Gallery", show_label=True, elem_id="gallery")
158
 
159
- process_button.click(process_video,
160
- inputs=[video_file,
161
- model_id,
162
- threshold],
163
- outputs=[output_video, frame_gallery])
164
 
165
  if __name__ == "__main__":
166
  demo.launch(debug=True)
 
18
  import PIL.ImageDraw
19
 
20
  # Creating a UDF to draw bounding boxes
 
21
  @pxt.udf
22
+ def draw_boxes(img: PIL.Image.Image, boxes: list[list[float]]) -> PIL.Image.Image:
 
 
23
  result = img.copy() # Create a copy of `img`
24
  d = PIL.ImageDraw.Draw(result)
25
  for box in boxes:
 
49
  )
50
 
51
  # Insert video into Pixeltable table
52
+ videos_table.insert([{'video': video_file.name}])
 
 
 
 
53
 
54
  progress(0.3, desc="Running Model...")
55
 
 
106
  )
107
 
108
  with gr.Row():
109
+ with gr.Column():
110
+ with gr.Accordion("What This Demo Does", open=True):
111
+ gr.Markdown("""
112
+ 1. **Ingests Videos**: Uploads your Video.
113
+ 2. **Process and Retrieve Data**: Store, version, chunk, and retrieve video and frames.
114
+ 3. **Detects Objects**: Leverages Pixeltable's YOLOX integration to produce object detection results.
115
+ 4. **Visualizes Output**: Displays the processed video alongside a sample of the original frames.
116
+ """)
117
 
118
  # File upload components for ground truth and PDF documents
119
  with gr.Row():
120
  video_file = gr.File(label="Upload Video", file_count="single")
121
 
122
+ # Add controls for chunking parameters
123
  with gr.Row():
124
+ model_id = gr.Dropdown(
125
  choices=['yolox_tiny', 'yolox_m', 'yolox_x'],
126
  value='yolox_tiny',
127
  label="YOLOX Model"
128
+ )
129
+ threshold = gr.Slider(minimum=0.1, maximum=0.9, value=0.25, step=0.05, label="Threshold")
130
 
131
+ gr.Examples(
132
+ examples=[
 
 
 
133
  ["bangkok.mp4", "yolox_tiny", 0.25],
134
  ["lotr.mp4", "yolox_m", 0.3],
135
  ["mi.mp4", "yolox_tiny", 0.5],
136
+ ],
137
+ inputs=[video_file, model_id, threshold],
138
+ fn=process_video
139
+ )
140
 
141
  # Button to trigger file processing
142
  process_button = gr.Button("Process Video")
 
147
  with gr.Row():
148
  frame_gallery = gr.Gallery(label="Frame Gallery", show_label=True, elem_id="gallery")
149
 
150
+ process_button.click(
151
+ process_video,
152
+ inputs=[video_file, model_id, threshold],
153
+ outputs=[output_video, frame_gallery]
154
+ )
155
 
156
  if __name__ == "__main__":
157
  demo.launch(debug=True)