elismasilva commited on
Commit
bd5fab7
·
verified ·
1 Parent(s): 619a409

Upload folder using huggingface_hub

Browse files
Files changed (40) hide show
  1. .gitattributes +2 -0
  2. .gitignore +12 -0
  3. README.md +419 -12
  4. __init__.py +0 -0
  5. app.py +83 -0
  6. css.css +157 -0
  7. requirements.txt +1 -0
  8. space.py +222 -0
  9. src/.gitignore +12 -0
  10. src/README.md +419 -0
  11. src/backend/gradio_videoslider/__init__.py +4 -0
  12. src/backend/gradio_videoslider/templates/component/assets/worker-BAOIWoxA.js +1 -0
  13. src/backend/gradio_videoslider/templates/component/index.js +0 -0
  14. src/backend/gradio_videoslider/templates/component/style.css +1 -0
  15. src/backend/gradio_videoslider/templates/example/index.js +106 -0
  16. src/backend/gradio_videoslider/templates/example/style.css +1 -0
  17. src/backend/gradio_videoslider/videoslider.py +152 -0
  18. src/demo/__init__.py +0 -0
  19. src/demo/app.py +83 -0
  20. src/demo/css.css +157 -0
  21. src/demo/requirements.txt +1 -0
  22. src/demo/space.py +222 -0
  23. src/examples/SampleVideo 1280x720.mp4 +3 -0
  24. src/examples/Samplevideo 720x480.mp4 +3 -0
  25. src/frontend/Example.svelte +69 -0
  26. src/frontend/Index.svelte +154 -0
  27. src/frontend/gradio.config.js +9 -0
  28. src/frontend/package-lock.json +0 -0
  29. src/frontend/package.json +51 -0
  30. src/frontend/shared/InteractiveVideo.svelte +194 -0
  31. src/frontend/shared/InteractiveVideoSlider.svelte +139 -0
  32. src/frontend/shared/Player.svelte +311 -0
  33. src/frontend/shared/Slider.svelte +249 -0
  34. src/frontend/shared/Video.svelte +219 -0
  35. src/frontend/shared/VideoControls.svelte +228 -0
  36. src/frontend/shared/VideoSliderPreview.svelte +235 -0
  37. src/frontend/shared/VideoTimeline.svelte +312 -0
  38. src/frontend/shared/utils.ts +151 -0
  39. src/frontend/tsconfig.json +14 -0
  40. src/pyproject.toml +51 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ src/examples/SampleVideo[[:space:]]1280x720.mp4 filter=lfs diff=lfs merge=lfs -text
37
+ src/examples/Samplevideo[[:space:]]720x480.mp4 filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .eggs/
2
+ dist/
3
+ *.pyc
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ __tmp/*
8
+ *.pyi
9
+ .mypycache
10
+ .ruff_cache
11
+ node_modules
12
+ backend/**/templates/
README.md CHANGED
@@ -1,12 +1,419 @@
1
- ---
2
- title: Gradio Videoslider
3
- emoji: 👀
4
- colorFrom: red
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 5.38.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags: [gradio-custom-component, ImageSlider]
3
+ title: gradio_videoslider
4
+ short_description: VideoSlider Component for Gradio
5
+ colorFrom: blue
6
+ colorTo: yellow
7
+ sdk: gradio
8
+ pinned: false
9
+ app_file: space.py
10
+ ---
11
+
12
+ # `gradio_videoslider`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
14
+
15
+ VideoSlider Component for Gradio
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install gradio_videoslider
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ # In demo/app.py
27
+ import gradio as gr
28
+ from gradio_videoslider import VideoSlider
29
+ import os
30
+
31
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
32
+ #
33
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
34
+ #
35
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
36
+ # video_path_1 = "video_antes.mp4"
37
+ # video_path_2 = "video_depois.mp4"
38
+ #
39
+ # Option B: Absolute Path (the full path to the file on your computer)
40
+ # Example for Windows:
41
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
42
+ #
43
+ # Example for Linux/macOS:
44
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
45
+
46
+ # Set your file paths here:
47
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
48
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
49
+
50
+
51
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
52
+ def process_uploaded_videos(video_inputs):
53
+ """This function handles the uploaded videos."""
54
+ print("Received videos from upload:", video_inputs)
55
+ return video_inputs
56
+
57
+
58
+ # --- 3. GRADIO INTERFACE ---
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("# Video Slider Component Usage Examples")
61
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
62
+
63
+ with gr.Tabs():
64
+ # --- TAB 1: UPLOAD EXAMPLE ---
65
+ with gr.TabItem("1. Compare via Upload"):
66
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
67
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
68
+ video_slider_output = VideoSlider(
69
+ label="Video comparision",
70
+ interactive=False,
71
+ autoplay=True,
72
+ loop=True,
73
+ height=400,
74
+ width=700
75
+ )
76
+ submit_btn = gr.Button("Submit")
77
+ submit_btn.click(
78
+ fn=process_uploaded_videos,
79
+ inputs=[video_slider_input],
80
+ outputs=[video_slider_output]
81
+ )
82
+
83
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
84
+ with gr.TabItem("2. Compare Local Files"):
85
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
86
+
87
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
88
+ VideoSlider(
89
+ label="Video comparision",
90
+ value=(video_path_1, video_path_2),
91
+ interactive=False,
92
+ autoplay=True,
93
+ loop=True,
94
+ height=400,
95
+ width=700
96
+ )
97
+
98
+ # Optional: A check to give a helpful error message if files are not found.
99
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
100
+ print("---")
101
+ print(f"WARNING: Could not find one or both video files.")
102
+ print(f"Please make sure these paths are correct in your app.py file:")
103
+ print(f" - '{os.path.abspath(video_path_1)}'")
104
+ print(f" - '{os.path.abspath(video_path_2)}'")
105
+ print("---")
106
+
107
+ if __name__ == '__main__':
108
+ demo.launch()
109
+
110
+ ```
111
+
112
+ ## `VideoSlider`
113
+
114
+ ### Initialization
115
+
116
+ <table>
117
+ <thead>
118
+ <tr>
119
+ <th align="left">name</th>
120
+ <th align="left" style="width: 25%;">type</th>
121
+ <th align="left">default</th>
122
+ <th align="left">description</th>
123
+ </tr>
124
+ </thead>
125
+ <tbody>
126
+ <tr>
127
+ <td align="left"><code>value</code></td>
128
+ <td align="left" style="width: 25%;">
129
+
130
+ ```python
131
+ typing.Union[
132
+ typing.Tuple[str | pathlib.Path, str | pathlib.Path],
133
+ typing.Callable,
134
+ NoneType,
135
+ ][
136
+ typing.Tuple[str | pathlib.Path, str | pathlib.Path][
137
+ str | pathlib.Path, str | pathlib.Path
138
+ ],
139
+ Callable,
140
+ None,
141
+ ]
142
+ ```
143
+
144
+ </td>
145
+ <td align="left"><code>None</code></td>
146
+ <td align="left">A tuple of two video file paths or URLs to display initially.</td>
147
+ </tr>
148
+
149
+ <tr>
150
+ <td align="left"><code>height</code></td>
151
+ <td align="left" style="width: 25%;">
152
+
153
+ ```python
154
+ int | None
155
+ ```
156
+
157
+ </td>
158
+ <td align="left"><code>None</code></td>
159
+ <td align="left">The height of the component in pixels.</td>
160
+ </tr>
161
+
162
+ <tr>
163
+ <td align="left"><code>width</code></td>
164
+ <td align="left" style="width: 25%;">
165
+
166
+ ```python
167
+ int | None
168
+ ```
169
+
170
+ </td>
171
+ <td align="left"><code>None</code></td>
172
+ <td align="left">The width of the component in pixels.</td>
173
+ </tr>
174
+
175
+ <tr>
176
+ <td align="left"><code>label</code></td>
177
+ <td align="left" style="width: 25%;">
178
+
179
+ ```python
180
+ str | None
181
+ ```
182
+
183
+ </td>
184
+ <td align="left"><code>None</code></td>
185
+ <td align="left">The label for this component.</td>
186
+ </tr>
187
+
188
+ <tr>
189
+ <td align="left"><code>every</code></td>
190
+ <td align="left" style="width: 25%;">
191
+
192
+ ```python
193
+ float | None
194
+ ```
195
+
196
+ </td>
197
+ <td align="left"><code>None</code></td>
198
+ <td align="left">None</td>
199
+ </tr>
200
+
201
+ <tr>
202
+ <td align="left"><code>show_label</code></td>
203
+ <td align="left" style="width: 25%;">
204
+
205
+ ```python
206
+ bool | None
207
+ ```
208
+
209
+ </td>
210
+ <td align="left"><code>None</code></td>
211
+ <td align="left">None</td>
212
+ </tr>
213
+
214
+ <tr>
215
+ <td align="left"><code>container</code></td>
216
+ <td align="left" style="width: 25%;">
217
+
218
+ ```python
219
+ bool
220
+ ```
221
+
222
+ </td>
223
+ <td align="left"><code>True</code></td>
224
+ <td align="left">None</td>
225
+ </tr>
226
+
227
+ <tr>
228
+ <td align="left"><code>scale</code></td>
229
+ <td align="left" style="width: 25%;">
230
+
231
+ ```python
232
+ int | None
233
+ ```
234
+
235
+ </td>
236
+ <td align="left"><code>None</code></td>
237
+ <td align="left">None</td>
238
+ </tr>
239
+
240
+ <tr>
241
+ <td align="left"><code>min_width</code></td>
242
+ <td align="left" style="width: 25%;">
243
+
244
+ ```python
245
+ int
246
+ ```
247
+
248
+ </td>
249
+ <td align="left"><code>160</code></td>
250
+ <td align="left">None</td>
251
+ </tr>
252
+
253
+ <tr>
254
+ <td align="left"><code>interactive</code></td>
255
+ <td align="left" style="width: 25%;">
256
+
257
+ ```python
258
+ bool | None
259
+ ```
260
+
261
+ </td>
262
+ <td align="left"><code>None</code></td>
263
+ <td align="left">If False, the component will be in display-only mode.</td>
264
+ </tr>
265
+
266
+ <tr>
267
+ <td align="left"><code>visible</code></td>
268
+ <td align="left" style="width: 25%;">
269
+
270
+ ```python
271
+ bool
272
+ ```
273
+
274
+ </td>
275
+ <td align="left"><code>True</code></td>
276
+ <td align="left">None</td>
277
+ </tr>
278
+
279
+ <tr>
280
+ <td align="left"><code>elem_id</code></td>
281
+ <td align="left" style="width: 25%;">
282
+
283
+ ```python
284
+ str | None
285
+ ```
286
+
287
+ </td>
288
+ <td align="left"><code>None</code></td>
289
+ <td align="left">None</td>
290
+ </tr>
291
+
292
+ <tr>
293
+ <td align="left"><code>elem_classes</code></td>
294
+ <td align="left" style="width: 25%;">
295
+
296
+ ```python
297
+ typing.Union[typing.List[str], str, NoneType][
298
+ typing.List[str][str], str, None
299
+ ]
300
+ ```
301
+
302
+ </td>
303
+ <td align="left"><code>None</code></td>
304
+ <td align="left">None</td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td align="left"><code>position</code></td>
309
+ <td align="left" style="width: 25%;">
310
+
311
+ ```python
312
+ int
313
+ ```
314
+
315
+ </td>
316
+ <td align="left"><code>50</code></td>
317
+ <td align="left">The initial position of the slider, from 0 to 100.</td>
318
+ </tr>
319
+
320
+ <tr>
321
+ <td align="left"><code>show_download_button</code></td>
322
+ <td align="left" style="width: 25%;">
323
+
324
+ ```python
325
+ bool
326
+ ```
327
+
328
+ </td>
329
+ <td align="left"><code>True</code></td>
330
+ <td align="left">None</td>
331
+ </tr>
332
+
333
+ <tr>
334
+ <td align="left"><code>show_fullscreen_button</code></td>
335
+ <td align="left" style="width: 25%;">
336
+
337
+ ```python
338
+ bool
339
+ ```
340
+
341
+ </td>
342
+ <td align="left"><code>True</code></td>
343
+ <td align="left">None</td>
344
+ </tr>
345
+
346
+ <tr>
347
+ <td align="left"><code>autoplay</code></td>
348
+ <td align="left" style="width: 25%;">
349
+
350
+ ```python
351
+ bool
352
+ ```
353
+
354
+ </td>
355
+ <td align="left"><code>False</code></td>
356
+ <td align="left">If True, the videos will start playing automatically.</td>
357
+ </tr>
358
+
359
+ <tr>
360
+ <td align="left"><code>loop</code></td>
361
+ <td align="left" style="width: 25%;">
362
+
363
+ ```python
364
+ bool
365
+ ```
366
+
367
+ </td>
368
+ <td align="left"><code>False</code></td>
369
+ <td align="left">If True, the videos will loop when they finish.</td>
370
+ </tr>
371
+ </tbody></table>
372
+
373
+
374
+ ### Events
375
+
376
+ | name | description |
377
+ |:-----|:------------|
378
+ | `change` | Triggered when the value of the VideoSlider changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
379
+ | `upload` | This listener is triggered when the user uploads a file into the VideoSlider. |
380
+ | `clear` | This listener is triggered when the user clears the VideoSlider using the clear button for the component. |
381
+
382
+
383
+
384
+ ### User function
385
+
386
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
387
+
388
+ - When used as an Input, the component only impacts the input signature of the user function.
389
+ - When used as an output, the component only impacts the return signature of the user function.
390
+
391
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
392
+
393
+
394
+
395
+ ```python
396
+ def predict(
397
+ value: typing.Optional[
398
+ typing.Tuple[
399
+ str | pathlib.Path | None, str | pathlib.Path | None
400
+ ]
401
+ ][
402
+ typing.Tuple[
403
+ str | pathlib.Path | None, str | pathlib.Path | None
404
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
405
+ None,
406
+ ]
407
+ ) -> typing.Optional[
408
+ typing.Tuple[
409
+ str | pathlib.Path | None, str | pathlib.Path | None
410
+ ]
411
+ ][
412
+ typing.Tuple[
413
+ str | pathlib.Path | None, str | pathlib.Path | None
414
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
415
+ None,
416
+ ]:
417
+ return value
418
+ ```
419
+
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # In demo/app.py
2
+ import gradio as gr
3
+ from gradio_videoslider import VideoSlider
4
+ import os
5
+
6
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
7
+ #
8
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
9
+ #
10
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
11
+ # video_path_1 = "video_antes.mp4"
12
+ # video_path_2 = "video_depois.mp4"
13
+ #
14
+ # Option B: Absolute Path (the full path to the file on your computer)
15
+ # Example for Windows:
16
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
17
+ #
18
+ # Example for Linux/macOS:
19
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
20
+
21
+ # Set your file paths here:
22
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
23
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
24
+
25
+
26
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
27
+ def process_uploaded_videos(video_inputs):
28
+ """This function handles the uploaded videos."""
29
+ print("Received videos from upload:", video_inputs)
30
+ return video_inputs
31
+
32
+
33
+ # --- 3. GRADIO INTERFACE ---
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("# Video Slider Component Usage Examples")
36
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
37
+
38
+ with gr.Tabs():
39
+ # --- TAB 1: UPLOAD EXAMPLE ---
40
+ with gr.TabItem("1. Compare via Upload"):
41
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
42
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
43
+ video_slider_output = VideoSlider(
44
+ label="Video comparision",
45
+ interactive=False,
46
+ autoplay=True,
47
+ loop=True,
48
+ height=400,
49
+ width=700
50
+ )
51
+ submit_btn = gr.Button("Submit")
52
+ submit_btn.click(
53
+ fn=process_uploaded_videos,
54
+ inputs=[video_slider_input],
55
+ outputs=[video_slider_output]
56
+ )
57
+
58
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
59
+ with gr.TabItem("2. Compare Local Files"):
60
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
61
+
62
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
63
+ VideoSlider(
64
+ label="Video comparision",
65
+ value=(video_path_1, video_path_2),
66
+ interactive=False,
67
+ autoplay=True,
68
+ loop=True,
69
+ height=400,
70
+ width=700
71
+ )
72
+
73
+ # Optional: A check to give a helpful error message if files are not found.
74
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
75
+ print("---")
76
+ print(f"WARNING: Could not find one or both video files.")
77
+ print(f"Please make sure these paths are correct in your app.py file:")
78
+ print(f" - '{os.path.abspath(video_path_1)}'")
79
+ print(f" - '{os.path.abspath(video_path_2)}'")
80
+ print("---")
81
+
82
+ if __name__ == '__main__':
83
+ demo.launch()
css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_videoslider
space.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'VideoSlider': {'description': 'A custom Gradio component to display a side-by-side video comparison with a slider.\nIt can be used as both an input (uploading two videos) and an output (displaying two videos).', 'members': {'__init__': {'value': {'type': 'typing.Union[\n typing.Tuple[str | pathlib.Path, str | pathlib.Path],\n typing.Callable,\n NoneType,\n][\n typing.Tuple[str | pathlib.Path, str | pathlib.Path][\n str | pathlib.Path, str | pathlib.Path\n ],\n Callable,\n None,\n]', 'default': 'None', 'description': 'A tuple of two video file paths or URLs to display initially.'}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'The height of the component in pixels.'}, 'width': {'type': 'int | None', 'default': 'None', 'description': 'The width of the component in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': 'If False, the component will be in display-only mode.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'typing.Union[typing.List[str], str, NoneType][\n typing.List[str][str], str, None\n]', 'default': 'None', 'description': None}, 'position': {'type': 'int', 'default': '50', 'description': 'The initial position of the slider, from 0 to 100.'}, 'show_download_button': {'type': 'bool', 'default': 'True', 'description': None}, 'show_fullscreen_button': {'type': 'bool', 'default': 'True', 'description': None}, 'autoplay': {'type': 'bool', 'default': 'False', 'description': 'If True, the videos will start playing automatically.'}, 'loop': {'type': 'bool', 'default': 'False', 'description': 'If True, the videos will loop when they finish.'}}, 'postprocess': {'value': {'type': 'typing.Optional[\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ]\n][\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ][str | pathlib.Path | None, str | pathlib.Path | None],\n None,\n]', 'description': None}}, 'preprocess': {'return': {'type': 'typing.Optional[\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ]\n][\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ][str | pathlib.Path | None, str | pathlib.Path | None],\n None,\n]', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the VideoSlider changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the VideoSlider.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the VideoSlider using the clear button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'VideoSlider': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_videoslider`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ VideoSlider Component for Gradio
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_videoslider
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ # In demo/app.py
42
+ import gradio as gr
43
+ from gradio_videoslider import VideoSlider
44
+ import os
45
+
46
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
47
+ #
48
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
49
+ #
50
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
51
+ # video_path_1 = "video_antes.mp4"
52
+ # video_path_2 = "video_depois.mp4"
53
+ #
54
+ # Option B: Absolute Path (the full path to the file on your computer)
55
+ # Example for Windows:
56
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
57
+ #
58
+ # Example for Linux/macOS:
59
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
60
+
61
+ # Set your file paths here:
62
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
63
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
64
+
65
+
66
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
67
+ def process_uploaded_videos(video_inputs):
68
+ \"\"\"This function handles the uploaded videos.\"\"\"
69
+ print("Received videos from upload:", video_inputs)
70
+ return video_inputs
71
+
72
+
73
+ # --- 3. GRADIO INTERFACE ---
74
+ with gr.Blocks() as demo:
75
+ gr.Markdown("# Video Slider Component Usage Examples")
76
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
77
+
78
+ with gr.Tabs():
79
+ # --- TAB 1: UPLOAD EXAMPLE ---
80
+ with gr.TabItem("1. Compare via Upload"):
81
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
82
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
83
+ video_slider_output = VideoSlider(
84
+ label="Video comparision",
85
+ interactive=False,
86
+ autoplay=True,
87
+ loop=True,
88
+ height=400,
89
+ width=700
90
+ )
91
+ submit_btn = gr.Button("Submit")
92
+ submit_btn.click(
93
+ fn=process_uploaded_videos,
94
+ inputs=[video_slider_input],
95
+ outputs=[video_slider_output]
96
+ )
97
+
98
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
99
+ with gr.TabItem("2. Compare Local Files"):
100
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
101
+
102
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
103
+ VideoSlider(
104
+ label="Video comparision",
105
+ value=(video_path_1, video_path_2),
106
+ interactive=False,
107
+ autoplay=True,
108
+ loop=True,
109
+ height=400,
110
+ width=700
111
+ )
112
+
113
+ # Optional: A check to give a helpful error message if files are not found.
114
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
115
+ print("---")
116
+ print(f"WARNING: Could not find one or both video files.")
117
+ print(f"Please make sure these paths are correct in your app.py file:")
118
+ print(f" - '{os.path.abspath(video_path_1)}'")
119
+ print(f" - '{os.path.abspath(video_path_2)}'")
120
+ print("---")
121
+
122
+ if __name__ == '__main__':
123
+ demo.launch()
124
+
125
+ ```
126
+ """, elem_classes=["md-custom"], header_links=True)
127
+
128
+
129
+ gr.Markdown("""
130
+ ## `VideoSlider`
131
+
132
+ ### Initialization
133
+ """, elem_classes=["md-custom"], header_links=True)
134
+
135
+ gr.ParamViewer(value=_docs["VideoSlider"]["members"]["__init__"], linkify=[])
136
+
137
+
138
+ gr.Markdown("### Events")
139
+ gr.ParamViewer(value=_docs["VideoSlider"]["events"], linkify=['Event'])
140
+
141
+
142
+
143
+
144
+ gr.Markdown("""
145
+
146
+ ### User function
147
+
148
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
149
+
150
+ - When used as an Input, the component only impacts the input signature of the user function.
151
+ - When used as an output, the component only impacts the return signature of the user function.
152
+
153
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
154
+
155
+
156
+
157
+ ```python
158
+ def predict(
159
+ value: typing.Optional[
160
+ typing.Tuple[
161
+ str | pathlib.Path | None, str | pathlib.Path | None
162
+ ]
163
+ ][
164
+ typing.Tuple[
165
+ str | pathlib.Path | None, str | pathlib.Path | None
166
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
167
+ None,
168
+ ]
169
+ ) -> typing.Optional[
170
+ typing.Tuple[
171
+ str | pathlib.Path | None, str | pathlib.Path | None
172
+ ]
173
+ ][
174
+ typing.Tuple[
175
+ str | pathlib.Path | None, str | pathlib.Path | None
176
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
177
+ None,
178
+ ]:
179
+ return value
180
+ ```
181
+ """, elem_classes=["md-custom", "VideoSlider-user-fn"], header_links=True)
182
+
183
+
184
+
185
+
186
+ demo.load(None, js=r"""function() {
187
+ const refs = {};
188
+ const user_fn_refs = {
189
+ VideoSlider: [], };
190
+ requestAnimationFrame(() => {
191
+
192
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
193
+ if (refs.length > 0) {
194
+ const el = document.querySelector(`.${key}-user-fn`);
195
+ if (!el) return;
196
+ refs.forEach(ref => {
197
+ el.innerHTML = el.innerHTML.replace(
198
+ new RegExp("\\b"+ref+"\\b", "g"),
199
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
200
+ );
201
+ })
202
+ }
203
+ })
204
+
205
+ Object.entries(refs).forEach(([key, refs]) => {
206
+ if (refs.length > 0) {
207
+ const el = document.querySelector(`.${key}`);
208
+ if (!el) return;
209
+ refs.forEach(ref => {
210
+ el.innerHTML = el.innerHTML.replace(
211
+ new RegExp("\\b"+ref+"\\b", "g"),
212
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
213
+ );
214
+ })
215
+ }
216
+ })
217
+ })
218
+ }
219
+
220
+ """)
221
+
222
+ demo.launch()
src/.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .eggs/
2
+ dist/
3
+ *.pyc
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ __tmp/*
8
+ *.pyi
9
+ .mypycache
10
+ .ruff_cache
11
+ node_modules
12
+ backend/**/templates/
src/README.md ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags: [gradio-custom-component, ImageSlider]
3
+ title: gradio_videoslider
4
+ short_description: VideoSlider Component for Gradio
5
+ colorFrom: blue
6
+ colorTo: yellow
7
+ sdk: gradio
8
+ pinned: false
9
+ app_file: space.py
10
+ ---
11
+
12
+ # `gradio_videoslider`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
14
+
15
+ VideoSlider Component for Gradio
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install gradio_videoslider
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ # In demo/app.py
27
+ import gradio as gr
28
+ from gradio_videoslider import VideoSlider
29
+ import os
30
+
31
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
32
+ #
33
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
34
+ #
35
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
36
+ # video_path_1 = "video_antes.mp4"
37
+ # video_path_2 = "video_depois.mp4"
38
+ #
39
+ # Option B: Absolute Path (the full path to the file on your computer)
40
+ # Example for Windows:
41
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
42
+ #
43
+ # Example for Linux/macOS:
44
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
45
+
46
+ # Set your file paths here:
47
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
48
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
49
+
50
+
51
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
52
+ def process_uploaded_videos(video_inputs):
53
+ """This function handles the uploaded videos."""
54
+ print("Received videos from upload:", video_inputs)
55
+ return video_inputs
56
+
57
+
58
+ # --- 3. GRADIO INTERFACE ---
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("# Video Slider Component Usage Examples")
61
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
62
+
63
+ with gr.Tabs():
64
+ # --- TAB 1: UPLOAD EXAMPLE ---
65
+ with gr.TabItem("1. Compare via Upload"):
66
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
67
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
68
+ video_slider_output = VideoSlider(
69
+ label="Video comparision",
70
+ interactive=False,
71
+ autoplay=True,
72
+ loop=True,
73
+ height=400,
74
+ width=700
75
+ )
76
+ submit_btn = gr.Button("Submit")
77
+ submit_btn.click(
78
+ fn=process_uploaded_videos,
79
+ inputs=[video_slider_input],
80
+ outputs=[video_slider_output]
81
+ )
82
+
83
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
84
+ with gr.TabItem("2. Compare Local Files"):
85
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
86
+
87
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
88
+ VideoSlider(
89
+ label="Video comparision",
90
+ value=(video_path_1, video_path_2),
91
+ interactive=False,
92
+ autoplay=True,
93
+ loop=True,
94
+ height=400,
95
+ width=700
96
+ )
97
+
98
+ # Optional: A check to give a helpful error message if files are not found.
99
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
100
+ print("---")
101
+ print(f"WARNING: Could not find one or both video files.")
102
+ print(f"Please make sure these paths are correct in your app.py file:")
103
+ print(f" - '{os.path.abspath(video_path_1)}'")
104
+ print(f" - '{os.path.abspath(video_path_2)}'")
105
+ print("---")
106
+
107
+ if __name__ == '__main__':
108
+ demo.launch()
109
+
110
+ ```
111
+
112
+ ## `VideoSlider`
113
+
114
+ ### Initialization
115
+
116
+ <table>
117
+ <thead>
118
+ <tr>
119
+ <th align="left">name</th>
120
+ <th align="left" style="width: 25%;">type</th>
121
+ <th align="left">default</th>
122
+ <th align="left">description</th>
123
+ </tr>
124
+ </thead>
125
+ <tbody>
126
+ <tr>
127
+ <td align="left"><code>value</code></td>
128
+ <td align="left" style="width: 25%;">
129
+
130
+ ```python
131
+ typing.Union[
132
+ typing.Tuple[str | pathlib.Path, str | pathlib.Path],
133
+ typing.Callable,
134
+ NoneType,
135
+ ][
136
+ typing.Tuple[str | pathlib.Path, str | pathlib.Path][
137
+ str | pathlib.Path, str | pathlib.Path
138
+ ],
139
+ Callable,
140
+ None,
141
+ ]
142
+ ```
143
+
144
+ </td>
145
+ <td align="left"><code>None</code></td>
146
+ <td align="left">A tuple of two video file paths or URLs to display initially.</td>
147
+ </tr>
148
+
149
+ <tr>
150
+ <td align="left"><code>height</code></td>
151
+ <td align="left" style="width: 25%;">
152
+
153
+ ```python
154
+ int | None
155
+ ```
156
+
157
+ </td>
158
+ <td align="left"><code>None</code></td>
159
+ <td align="left">The height of the component in pixels.</td>
160
+ </tr>
161
+
162
+ <tr>
163
+ <td align="left"><code>width</code></td>
164
+ <td align="left" style="width: 25%;">
165
+
166
+ ```python
167
+ int | None
168
+ ```
169
+
170
+ </td>
171
+ <td align="left"><code>None</code></td>
172
+ <td align="left">The width of the component in pixels.</td>
173
+ </tr>
174
+
175
+ <tr>
176
+ <td align="left"><code>label</code></td>
177
+ <td align="left" style="width: 25%;">
178
+
179
+ ```python
180
+ str | None
181
+ ```
182
+
183
+ </td>
184
+ <td align="left"><code>None</code></td>
185
+ <td align="left">The label for this component.</td>
186
+ </tr>
187
+
188
+ <tr>
189
+ <td align="left"><code>every</code></td>
190
+ <td align="left" style="width: 25%;">
191
+
192
+ ```python
193
+ float | None
194
+ ```
195
+
196
+ </td>
197
+ <td align="left"><code>None</code></td>
198
+ <td align="left">None</td>
199
+ </tr>
200
+
201
+ <tr>
202
+ <td align="left"><code>show_label</code></td>
203
+ <td align="left" style="width: 25%;">
204
+
205
+ ```python
206
+ bool | None
207
+ ```
208
+
209
+ </td>
210
+ <td align="left"><code>None</code></td>
211
+ <td align="left">None</td>
212
+ </tr>
213
+
214
+ <tr>
215
+ <td align="left"><code>container</code></td>
216
+ <td align="left" style="width: 25%;">
217
+
218
+ ```python
219
+ bool
220
+ ```
221
+
222
+ </td>
223
+ <td align="left"><code>True</code></td>
224
+ <td align="left">None</td>
225
+ </tr>
226
+
227
+ <tr>
228
+ <td align="left"><code>scale</code></td>
229
+ <td align="left" style="width: 25%;">
230
+
231
+ ```python
232
+ int | None
233
+ ```
234
+
235
+ </td>
236
+ <td align="left"><code>None</code></td>
237
+ <td align="left">None</td>
238
+ </tr>
239
+
240
+ <tr>
241
+ <td align="left"><code>min_width</code></td>
242
+ <td align="left" style="width: 25%;">
243
+
244
+ ```python
245
+ int
246
+ ```
247
+
248
+ </td>
249
+ <td align="left"><code>160</code></td>
250
+ <td align="left">None</td>
251
+ </tr>
252
+
253
+ <tr>
254
+ <td align="left"><code>interactive</code></td>
255
+ <td align="left" style="width: 25%;">
256
+
257
+ ```python
258
+ bool | None
259
+ ```
260
+
261
+ </td>
262
+ <td align="left"><code>None</code></td>
263
+ <td align="left">If False, the component will be in display-only mode.</td>
264
+ </tr>
265
+
266
+ <tr>
267
+ <td align="left"><code>visible</code></td>
268
+ <td align="left" style="width: 25%;">
269
+
270
+ ```python
271
+ bool
272
+ ```
273
+
274
+ </td>
275
+ <td align="left"><code>True</code></td>
276
+ <td align="left">None</td>
277
+ </tr>
278
+
279
+ <tr>
280
+ <td align="left"><code>elem_id</code></td>
281
+ <td align="left" style="width: 25%;">
282
+
283
+ ```python
284
+ str | None
285
+ ```
286
+
287
+ </td>
288
+ <td align="left"><code>None</code></td>
289
+ <td align="left">None</td>
290
+ </tr>
291
+
292
+ <tr>
293
+ <td align="left"><code>elem_classes</code></td>
294
+ <td align="left" style="width: 25%;">
295
+
296
+ ```python
297
+ typing.Union[typing.List[str], str, NoneType][
298
+ typing.List[str][str], str, None
299
+ ]
300
+ ```
301
+
302
+ </td>
303
+ <td align="left"><code>None</code></td>
304
+ <td align="left">None</td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td align="left"><code>position</code></td>
309
+ <td align="left" style="width: 25%;">
310
+
311
+ ```python
312
+ int
313
+ ```
314
+
315
+ </td>
316
+ <td align="left"><code>50</code></td>
317
+ <td align="left">The initial position of the slider, from 0 to 100.</td>
318
+ </tr>
319
+
320
+ <tr>
321
+ <td align="left"><code>show_download_button</code></td>
322
+ <td align="left" style="width: 25%;">
323
+
324
+ ```python
325
+ bool
326
+ ```
327
+
328
+ </td>
329
+ <td align="left"><code>True</code></td>
330
+ <td align="left">None</td>
331
+ </tr>
332
+
333
+ <tr>
334
+ <td align="left"><code>show_fullscreen_button</code></td>
335
+ <td align="left" style="width: 25%;">
336
+
337
+ ```python
338
+ bool
339
+ ```
340
+
341
+ </td>
342
+ <td align="left"><code>True</code></td>
343
+ <td align="left">None</td>
344
+ </tr>
345
+
346
+ <tr>
347
+ <td align="left"><code>autoplay</code></td>
348
+ <td align="left" style="width: 25%;">
349
+
350
+ ```python
351
+ bool
352
+ ```
353
+
354
+ </td>
355
+ <td align="left"><code>False</code></td>
356
+ <td align="left">If True, the videos will start playing automatically.</td>
357
+ </tr>
358
+
359
+ <tr>
360
+ <td align="left"><code>loop</code></td>
361
+ <td align="left" style="width: 25%;">
362
+
363
+ ```python
364
+ bool
365
+ ```
366
+
367
+ </td>
368
+ <td align="left"><code>False</code></td>
369
+ <td align="left">If True, the videos will loop when they finish.</td>
370
+ </tr>
371
+ </tbody></table>
372
+
373
+
374
+ ### Events
375
+
376
+ | name | description |
377
+ |:-----|:------------|
378
+ | `change` | Triggered when the value of the VideoSlider changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
379
+ | `upload` | This listener is triggered when the user uploads a file into the VideoSlider. |
380
+ | `clear` | This listener is triggered when the user clears the VideoSlider using the clear button for the component. |
381
+
382
+
383
+
384
+ ### User function
385
+
386
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
387
+
388
+ - When used as an Input, the component only impacts the input signature of the user function.
389
+ - When used as an output, the component only impacts the return signature of the user function.
390
+
391
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
392
+
393
+
394
+
395
+ ```python
396
+ def predict(
397
+ value: typing.Optional[
398
+ typing.Tuple[
399
+ str | pathlib.Path | None, str | pathlib.Path | None
400
+ ]
401
+ ][
402
+ typing.Tuple[
403
+ str | pathlib.Path | None, str | pathlib.Path | None
404
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
405
+ None,
406
+ ]
407
+ ) -> typing.Optional[
408
+ typing.Tuple[
409
+ str | pathlib.Path | None, str | pathlib.Path | None
410
+ ]
411
+ ][
412
+ typing.Tuple[
413
+ str | pathlib.Path | None, str | pathlib.Path | None
414
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
415
+ None,
416
+ ]:
417
+ return value
418
+ ```
419
+
src/backend/gradio_videoslider/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ from .videoslider import VideoSlider
3
+
4
+ __all__ = ['VideoSlider']
src/backend/gradio_videoslider/templates/component/assets/worker-BAOIWoxA.js ADDED
@@ -0,0 +1 @@
 
 
1
+ (function(){"use strict";const i="https://unpkg.com/@ffmpeg/[email protected]/dist/umd/ffmpeg-core.js";var E;(function(t){t.LOAD="LOAD",t.EXEC="EXEC",t.FFPROBE="FFPROBE",t.WRITE_FILE="WRITE_FILE",t.READ_FILE="READ_FILE",t.DELETE_FILE="DELETE_FILE",t.RENAME="RENAME",t.CREATE_DIR="CREATE_DIR",t.LIST_DIR="LIST_DIR",t.DELETE_DIR="DELETE_DIR",t.ERROR="ERROR",t.DOWNLOAD="DOWNLOAD",t.PROGRESS="PROGRESS",t.LOG="LOG",t.MOUNT="MOUNT",t.UNMOUNT="UNMOUNT"})(E||(E={}));const f=new Error("unknown message type"),a=new Error("ffmpeg is not loaded, call `await ffmpeg.load()` first"),u=new Error("failed to import ffmpeg-core.js");let r;const O=async({coreURL:t,wasmURL:n,workerURL:e})=>{const o=!r;try{t||(t=i),importScripts(t)}catch{if((!t||t===i)&&(t=i.replace("/umd/","/esm/")),self.createFFmpegCore=(await import(t)).default,!self.createFFmpegCore)throw u}const s=t,c=n||t.replace(/.js$/g,".wasm"),p=e||t.replace(/.js$/g,".worker.js");return r=await self.createFFmpegCore({mainScriptUrlOrBlob:`${s}#${btoa(JSON.stringify({wasmURL:c,workerURL:p}))}`}),r.setLogger(R=>self.postMessage({type:E.LOG,data:R})),r.setProgress(R=>self.postMessage({type:E.PROGRESS,data:R})),o},m=({args:t,timeout:n=-1})=>{r.setTimeout(n),r.exec(...t);const e=r.ret;return r.reset(),e},l=({args:t,timeout:n=-1})=>{r.setTimeout(n),r.ffprobe(...t);const e=r.ret;return r.reset(),e},D=({path:t,data:n})=>(r.FS.writeFile(t,n),!0),S=({path:t,encoding:n})=>r.FS.readFile(t,{encoding:n}),I=({path:t})=>(r.FS.unlink(t),!0),L=({oldPath:t,newPath:n})=>(r.FS.rename(t,n),!0),N=({path:t})=>(r.FS.mkdir(t),!0),A=({path:t})=>{const n=r.FS.readdir(t),e=[];for(const o of n){const s=r.FS.stat(`${t}/${o}`),c=r.FS.isDir(s.mode);e.push({name:o,isDir:c})}return e},k=({path:t})=>(r.FS.rmdir(t),!0),w=({fsType:t,options:n,mountPoint:e})=>{const o=t,s=r.FS.filesystems[o];return s?(r.FS.mount(s,n,e),!0):!1},b=({mountPoint:t})=>(r.FS.unmount(t),!0);self.onmessage=async({data:{id:t,type:n,data:e}})=>{const o=[];let s;try{if(n!==E.LOAD&&!r)throw a;switch(n){case E.LOAD:s=await O(e);break;case E.EXEC:s=m(e);break;case E.FFPROBE:s=l(e);break;case E.WRITE_FILE:s=D(e);break;case E.READ_FILE:s=S(e);break;case E.DELETE_FILE:s=I(e);break;case E.RENAME:s=L(e);break;case E.CREATE_DIR:s=N(e);break;case E.LIST_DIR:s=A(e);break;case E.DELETE_DIR:s=k(e);break;case E.MOUNT:s=w(e);break;case E.UNMOUNT:s=b(e);break;default:throw f}}catch(c){self.postMessage({id:t,type:E.ERROR,data:c.toString()});return}s instanceof Uint8Array&&o.push(s.buffer),self.postMessage({id:t,type:n,data:s},o)}})();
src/backend/gradio_videoslider/templates/component/index.js ADDED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_videoslider/templates/component/style.css ADDED
@@ -0,0 +1 @@
 
 
1
+ .block.svelte-239wnu{position:relative;margin:0;box-shadow:var(--block-shadow);border-width:var(--block-border-width);border-color:var(--block-border-color);border-radius:var(--block-radius);background:var(--block-background-fill);width:100%;line-height:var(--line-sm)}.block.fullscreen.svelte-239wnu{border-radius:0}.auto-margin.svelte-239wnu{margin-left:auto;margin-right:auto}.block.border_focus.svelte-239wnu{border-color:var(--color-accent)}.block.border_contrast.svelte-239wnu{border-color:var(--body-text-color)}.padded.svelte-239wnu{padding:var(--block-padding)}.hidden.svelte-239wnu{display:none}.flex.svelte-239wnu{display:flex;flex-direction:column}.hide-container.svelte-239wnu:not(.fullscreen){margin:0;box-shadow:none;--block-border-width:0;background:transparent;padding:0;overflow:visible}.resize-handle.svelte-239wnu{position:absolute;bottom:0;right:0;width:10px;height:10px;fill:var(--block-border-color);cursor:nwse-resize}.fullscreen.svelte-239wnu{position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:1000;overflow:auto}.animating.svelte-239wnu{animation:svelte-239wnu-pop-out .1s ease-out forwards}@keyframes svelte-239wnu-pop-out{0%{position:fixed;top:var(--start-top);left:var(--start-left);width:var(--start-width);height:var(--start-height);z-index:100}to{position:fixed;top:0vh;left:0vw;width:100vw;height:100vh;z-index:1000}}.placeholder.svelte-239wnu{border-radius:var(--block-radius);border-width:var(--block-border-width);border-color:var(--block-border-color);border-style:dashed}Tables */ table,tr,td,th{margin-top:var(--spacing-sm);margin-bottom:var(--spacing-sm);padding:var(--spacing-xl)}.md code,.md pre{background:none;font-family:var(--font-mono);font-size:var(--text-sm);text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:2;tab-size:2;-webkit-hyphens:none;hyphens:none}.md pre[class*=language-]::selection,.md pre[class*=language-] ::selection,.md code[class*=language-]::selection,.md code[class*=language-] ::selection{text-shadow:none;background:#b3d4fc}.md pre{padding:1em;margin:.5em 0;overflow:auto;position:relative;margin-top:var(--spacing-sm);margin-bottom:var(--spacing-sm);box-shadow:none;border:none;border-radius:var(--radius-md);background:var(--code-background-fill);padding:var(--spacing-xxl);font-family:var(--font-mono);text-shadow:none;border-radius:var(--radius-sm);white-space:nowrap;display:block;white-space:pre}.md :not(pre)>code{padding:.1em;border-radius:var(--radius-xs);white-space:normal;background:var(--code-background-fill);border:1px solid var(--panel-border-color);padding:var(--spacing-xxs) var(--spacing-xs)}.md .token.comment,.md .token.prolog,.md .token.doctype,.md .token.cdata{color:#708090}.md .token.punctuation{color:#999}.md .token.namespace{opacity:.7}.md .token.property,.md .token.tag,.md .token.boolean,.md .token.number,.md .token.constant,.md .token.symbol,.md .token.deleted{color:#905}.md .token.selector,.md .token.attr-name,.md .token.string,.md .token.char,.md .token.builtin,.md .token.inserted{color:#690}.md .token.atrule,.md .token.attr-value,.md .token.keyword{color:#07a}.md .token.function,.md .token.class-name{color:#dd4a68}.md .token.regex,.md .token.important,.md .token.variable{color:#e90}.md .token.important,.md .token.bold{font-weight:700}.md .token.italic{font-style:italic}.md .token.entity{cursor:help}.dark .md .token.comment,.dark .md .token.prolog,.dark .md .token.cdata{color:#5c6370}.dark .md .token.doctype,.dark .md .token.punctuation,.dark .md .token.entity{color:#abb2bf}.dark .md .token.attr-name,.dark .md .token.class-name,.dark .md .token.boolean,.dark .md .token.constant,.dark .md .token.number,.dark .md .token.atrule{color:#d19a66}.dark .md .token.keyword{color:#c678dd}.dark .md .token.property,.dark .md .token.tag,.dark .md .token.symbol,.dark .md .token.deleted,.dark .md .token.important{color:#e06c75}.dark .md .token.selector,.dark .md .token.string,.dark .md .token.char,.dark .md .token.builtin,.dark .md .token.inserted,.dark .md .token.regex,.dark .md .token.attr-value,.dark .md .token.attr-value>.token.punctuation{color:#98c379}.dark .md .token.variable,.dark .md .token.operator,.dark .md .token.function{color:#61afef}.dark .md .token.url{color:#56b6c2}span.svelte-1m32c2s div[class*=code_wrap]{position:relative}span.svelte-1m32c2s span.katex{font-size:var(--text-lg);direction:ltr}span.svelte-1m32c2s div[class*=code_wrap]>button{z-index:1;cursor:pointer;border-bottom-left-radius:var(--radius-sm);padding:var(--spacing-md);width:25px;height:25px;position:absolute;right:0}span.svelte-1m32c2s .check{opacity:0;z-index:var(--layer-top);transition:opacity .2s;background:var(--code-background-fill);color:var(--body-text-color);position:absolute;top:var(--size-1-5);left:var(--size-1-5)}span.svelte-1m32c2s p:not(:first-child){margin-top:var(--spacing-xxl)}span.svelte-1m32c2s .md-header-anchor{margin-left:-25px;padding-right:8px;line-height:1;color:var(--body-text-color-subdued);opacity:0}span.svelte-1m32c2s h1:hover .md-header-anchor,span.svelte-1m32c2s h2:hover .md-header-anchor,span.svelte-1m32c2s h3:hover .md-header-anchor,span.svelte-1m32c2s h4:hover .md-header-anchor,span.svelte-1m32c2s h5:hover .md-header-anchor,span.svelte-1m32c2s h6:hover .md-header-anchor{opacity:1}span.md.svelte-1m32c2s .md-header-anchor>svg{color:var(--body-text-color-subdued)}span.svelte-1m32c2s table{word-break:break-word}div.svelte-17qq50w>.md.prose{font-weight:var(--block-info-text-weight);font-size:var(--block-info-text-size);line-height:var(--line-sm)}div.svelte-17qq50w>.md.prose *{color:var(--block-info-text-color)}div.svelte-17qq50w{margin-bottom:var(--spacing-md)}span.has-info.svelte-zgrq3{margin-bottom:var(--spacing-xs)}span.svelte-zgrq3:not(.has-info){margin-bottom:var(--spacing-lg)}span.svelte-zgrq3{display:inline-block;position:relative;z-index:var(--layer-4);border:solid var(--block-title-border-width) var(--block-title-border-color);border-radius:var(--block-title-radius);background:var(--block-title-background-fill);padding:var(--block-title-padding);color:var(--block-title-text-color);font-weight:var(--block-title-text-weight);font-size:var(--block-title-text-size);line-height:var(--line-sm)}span[dir=rtl].svelte-zgrq3{display:block}.hide.svelte-zgrq3{margin:0;height:0}label.svelte-13ao5pu.svelte-13ao5pu{display:inline-flex;align-items:center;z-index:var(--layer-2);box-shadow:var(--block-label-shadow);border:var(--block-label-border-width) solid var(--block-label-border-color);border-top:none;border-left:none;border-radius:var(--block-label-radius);background:var(--block-label-background-fill);padding:var(--block-label-padding);pointer-events:none;color:var(--block-label-text-color);font-weight:var(--block-label-text-weight);font-size:var(--block-label-text-size);line-height:var(--line-sm)}.gr-group label.svelte-13ao5pu.svelte-13ao5pu{border-top-left-radius:0}label.float.svelte-13ao5pu.svelte-13ao5pu{position:absolute;top:var(--block-label-margin);left:var(--block-label-margin)}label.svelte-13ao5pu.svelte-13ao5pu:not(.float){position:static;margin-top:var(--block-label-margin);margin-left:var(--block-label-margin)}.hide.svelte-13ao5pu.svelte-13ao5pu{height:0}span.svelte-13ao5pu.svelte-13ao5pu{opacity:.8;margin-right:var(--size-2);width:calc(var(--block-label-text-size) - 1px);height:calc(var(--block-label-text-size) - 1px)}.hide-label.svelte-13ao5pu.svelte-13ao5pu{box-shadow:none;border-width:0;background:transparent;overflow:visible}label[dir=rtl].svelte-13ao5pu.svelte-13ao5pu{border:var(--block-label-border-width) solid var(--block-label-border-color);border-top:none;border-right:none;border-bottom-left-radius:var(--block-radius);border-bottom-right-radius:var(--block-label-radius);border-top-left-radius:var(--block-label-radius)}label[dir=rtl].svelte-13ao5pu span.svelte-13ao5pu{margin-left:var(--size-2);margin-right:0}button.svelte-qgco6m{display:flex;justify-content:center;align-items:center;gap:1px;z-index:var(--layer-2);border-radius:var(--radius-xs);color:var(--block-label-text-color);border:1px solid transparent;padding:var(--spacing-xxs)}button.svelte-qgco6m:hover{background-color:var(--background-fill-secondary)}button[disabled].svelte-qgco6m{opacity:.5;box-shadow:none}button[disabled].svelte-qgco6m:hover{cursor:not-allowed}.padded.svelte-qgco6m{background:var(--bg-color)}button.svelte-qgco6m:hover,button.highlight.svelte-qgco6m{cursor:pointer;color:var(--color-accent)}.padded.svelte-qgco6m:hover{color:var(--block-label-text-color)}span.svelte-qgco6m{padding:0 1px;font-size:10px}div.svelte-qgco6m{display:flex;align-items:center;justify-content:center;transition:filter .2s ease-in-out}.x-small.svelte-qgco6m{width:10px;height:10px}.small.svelte-qgco6m{width:14px;height:14px}.medium.svelte-qgco6m{width:20px;height:20px}.large.svelte-qgco6m{width:22px;height:22px}.pending.svelte-qgco6m{animation:svelte-qgco6m-flash .5s infinite}@keyframes svelte-qgco6m-flash{0%{opacity:.5}50%{opacity:1}to{opacity:.5}}.transparent.svelte-qgco6m{background:transparent;border:none;box-shadow:none}.empty.svelte-3w3rth{display:flex;justify-content:center;align-items:center;margin-top:calc(0px - var(--size-6));height:var(--size-full)}.icon.svelte-3w3rth{opacity:.5;height:var(--size-5);color:var(--body-text-color)}.small.svelte-3w3rth{min-height:calc(var(--size-32) - 20px)}.large.svelte-3w3rth{min-height:calc(var(--size-64) - 20px)}.unpadded_box.svelte-3w3rth{margin-top:0}.small_parent.svelte-3w3rth{min-height:100%!important}.dropdown-arrow.svelte-145leq6,.dropdown-arrow.svelte-ihhdbf{fill:currentColor}.circle.svelte-ihhdbf{fill:currentColor;opacity:.1}svg.svelte-pb9pol{animation:svelte-pb9pol-spin 1.5s linear infinite}@keyframes svelte-pb9pol-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}h2.svelte-1xg7h5n{font-size:var(--text-xl)!important}p.svelte-1xg7h5n,h2.svelte-1xg7h5n{white-space:pre-line}.wrap.svelte-1xg7h5n{display:flex;flex-direction:column;justify-content:center;align-items:center;min-height:var(--size-60);color:var(--block-label-text-color);line-height:var(--line-md);height:100%;padding-top:var(--size-3);text-align:center;margin:auto var(--spacing-lg)}.or.svelte-1xg7h5n{color:var(--body-text-color-subdued);display:flex}.icon-wrap.svelte-1xg7h5n{width:30px;margin-bottom:var(--spacing-lg)}@media (--screen-md){.wrap.svelte-1xg7h5n{font-size:var(--text-lg)}}.hovered.svelte-1xg7h5n{color:var(--color-accent)}div.svelte-q32hvf{border-top:1px solid transparent;display:flex;max-height:100%;justify-content:center;align-items:center;gap:var(--spacing-sm);height:auto;align-items:flex-end;color:var(--block-label-text-color);flex-shrink:0}.show_border.svelte-q32hvf{border-top:1px solid var(--block-border-color);margin-top:var(--spacing-xxl);box-shadow:var(--shadow-drop)}.source-selection.svelte-15ls1gu{display:flex;align-items:center;justify-content:center;border-top:1px solid var(--border-color-primary);width:100%;margin-left:auto;margin-right:auto;height:var(--size-10)}.icon.svelte-15ls1gu{width:22px;height:22px;margin:var(--spacing-lg) var(--spacing-xs);padding:var(--spacing-xs);color:var(--neutral-400);border-radius:var(--radius-md)}.selected.svelte-15ls1gu{color:var(--color-accent)}.icon.svelte-15ls1gu:hover,.icon.svelte-15ls1gu:focus{color:var(--color-accent)}.icon-button-wrapper.svelte-109se4{display:flex;flex-direction:row;align-items:center;justify-content:center;z-index:var(--layer-3);gap:var(--spacing-sm);box-shadow:var(--shadow-drop);border:1px solid var(--border-color-primary);background:var(--block-background-fill);padding:var(--spacing-xxs)}.icon-button-wrapper.hide-top-corner.svelte-109se4{border-top:none;border-right:none;border-radius:var(--block-label-right-radius)}.icon-button-wrapper.display-top-corner.svelte-109se4{border-radius:var(--radius-sm) 0 0 var(--radius-sm);top:var(--spacing-sm);right:-1px}.icon-button-wrapper.svelte-109se4:not(.top-panel){border:1px solid var(--border-color-primary);border-radius:var(--radius-sm)}.top-panel.svelte-109se4{position:absolute;top:var(--block-label-margin);right:var(--block-label-margin);margin:0}.icon-button-wrapper.svelte-109se4 button{margin:var(--spacing-xxs);border-radius:var(--radius-xs);position:relative}.icon-button-wrapper.svelte-109se4 a.download-link:not(:last-child),.icon-button-wrapper.svelte-109se4 button:not(:last-child){margin-right:var(--spacing-xxs)}.icon-button-wrapper.svelte-109se4 a.download-link:not(:last-child):not(.no-border *):after,.icon-button-wrapper.svelte-109se4 button:not(:last-child):not(.no-border *):after{content:"";position:absolute;right:-4.5px;top:15%;height:70%;width:1px;background-color:var(--border-color-primary)}.icon-button-wrapper.svelte-109se4>*{height:100%}svg.svelte-43sxxs.svelte-43sxxs{width:var(--size-20);height:var(--size-20)}svg.svelte-43sxxs path.svelte-43sxxs{fill:var(--loader-color)}div.svelte-43sxxs.svelte-43sxxs{z-index:var(--layer-2)}.margin.svelte-43sxxs.svelte-43sxxs{margin:var(--size-4)}.wrap.svelte-17v219f.svelte-17v219f{display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:var(--layer-2);transition:opacity .1s ease-in-out;border-radius:var(--block-radius);background:var(--block-background-fill);padding:0 var(--size-6);max-height:var(--size-screen-h);overflow:hidden}.wrap.center.svelte-17v219f.svelte-17v219f{top:0;right:0;left:0}.wrap.default.svelte-17v219f.svelte-17v219f{top:0;right:0;bottom:0;left:0}.hide.svelte-17v219f.svelte-17v219f{opacity:0;pointer-events:none}.generating.svelte-17v219f.svelte-17v219f{animation:svelte-17v219f-pulseStart 1s cubic-bezier(.4,0,.6,1),svelte-17v219f-pulse 2s cubic-bezier(.4,0,.6,1) 1s infinite;border:2px solid var(--color-accent);background:transparent;z-index:var(--layer-1);pointer-events:none}.translucent.svelte-17v219f.svelte-17v219f{background:none}@keyframes svelte-17v219f-pulseStart{0%{opacity:0}to{opacity:1}}@keyframes svelte-17v219f-pulse{0%,to{opacity:1}50%{opacity:.5}}.loading.svelte-17v219f.svelte-17v219f{z-index:var(--layer-2);color:var(--body-text-color)}.eta-bar.svelte-17v219f.svelte-17v219f{position:absolute;top:0;right:0;bottom:0;left:0;transform-origin:left;opacity:.8;z-index:var(--layer-1);transition:10ms;background:var(--background-fill-secondary)}.progress-bar-wrap.svelte-17v219f.svelte-17v219f{border:1px solid var(--border-color-primary);background:var(--background-fill-primary);width:55.5%;height:var(--size-4)}.progress-bar.svelte-17v219f.svelte-17v219f{transform-origin:left;background-color:var(--loader-color);width:var(--size-full);height:var(--size-full)}.progress-level.svelte-17v219f.svelte-17v219f{display:flex;flex-direction:column;align-items:center;gap:1;z-index:var(--layer-2);width:var(--size-full)}.progress-level-inner.svelte-17v219f.svelte-17v219f{margin:var(--size-2) auto;color:var(--body-text-color);font-size:var(--text-sm);font-family:var(--font-mono)}.meta-text.svelte-17v219f.svelte-17v219f{position:absolute;bottom:0;right:0;z-index:var(--layer-2);padding:var(--size-1) var(--size-2);font-size:var(--text-sm);font-family:var(--font-mono)}.meta-text-center.svelte-17v219f.svelte-17v219f{display:flex;position:absolute;top:0;right:0;justify-content:center;align-items:center;transform:translateY(var(--size-6));z-index:var(--layer-2);padding:var(--size-1) var(--size-2);font-size:var(--text-sm);font-family:var(--font-mono);text-align:center}.error.svelte-17v219f.svelte-17v219f{box-shadow:var(--shadow-drop);border:solid 1px var(--error-border-color);border-radius:var(--radius-full);background:var(--error-background-fill);padding-right:var(--size-4);padding-left:var(--size-4);color:var(--error-text-color);font-weight:var(--weight-semibold);font-size:var(--text-lg);line-height:var(--line-lg);font-family:var(--font)}.minimal.svelte-17v219f.svelte-17v219f{pointer-events:none}.minimal.svelte-17v219f .progress-text.svelte-17v219f{background:var(--block-background-fill)}.border.svelte-17v219f.svelte-17v219f{border:1px solid var(--border-color-primary)}.clear-status.svelte-17v219f.svelte-17v219f{position:absolute;display:flex;top:var(--size-2);right:var(--size-2);justify-content:flex-end;gap:var(--spacing-sm);z-index:var(--layer-1)}.toast-body.svelte-1pgj5gs{display:flex;position:relative;right:0;left:0;align-items:center;margin:var(--size-6) var(--size-4);margin:auto;border-radius:var(--container-radius);overflow:hidden;pointer-events:auto}.toast-body.error.svelte-1pgj5gs{border:1px solid var(--color-red-700);background:var(--color-red-50)}.dark .toast-body.error.svelte-1pgj5gs{border:1px solid var(--color-red-500);background-color:var(--color-grey-950)}.toast-body.warning.svelte-1pgj5gs{border:1px solid var(--color-yellow-700);background:var(--color-yellow-50)}.dark .toast-body.warning.svelte-1pgj5gs{border:1px solid var(--color-yellow-500);background-color:var(--color-grey-950)}.toast-body.info.svelte-1pgj5gs{border:1px solid var(--color-grey-700);background:var (--color-grey-50)}.dark .toast-body.info.svelte-1pgj5gs{border:1px solid var(--color-grey-500);background-color:var(--color-grey-950)}.toast-body.success.svelte-1pgj5gs{border:1px solid var(--color-green-700);background:var(--color-green-50)}.dark .toast-body.success.svelte-1pgj5gs{border:1px solid var(--color-green-500);background-color:var(--color-grey-950)}.toast-title.svelte-1pgj5gs{display:flex;align-items:center;font-weight:var(--weight-bold);font-size:var(--text-lg);line-height:var(--line-sm)}.toast-title.error.svelte-1pgj5gs{color:var(--color-red-700)}.dark .toast-title.error.svelte-1pgj5gs{color:var(--color-red-50)}.toast-title.warning.svelte-1pgj5gs{color:var(--color-yellow-700)}.dark .toast-title.warning.svelte-1pgj5gs{color:var(--color-yellow-50)}.toast-title.info.svelte-1pgj5gs{color:var(--color-grey-700)}.dark .toast-title.info.svelte-1pgj5gs{color:var(--color-grey-50)}.toast-title.success.svelte-1pgj5gs{color:var(--color-green-700)}.dark .toast-title.success.svelte-1pgj5gs{color:var(--color-green-50)}.toast-close.svelte-1pgj5gs{margin:0 var(--size-3);border-radius:var(--size-3);padding:0px var(--size-1-5);font-size:var(--size-5);line-height:var(--size-5)}.toast-close.error.svelte-1pgj5gs{color:var(--color-red-700)}.dark .toast-close.error.svelte-1pgj5gs{color:var(--color-red-500)}.toast-close.warning.svelte-1pgj5gs{color:var(--color-yellow-700)}.dark .toast-close.warning.svelte-1pgj5gs{color:var(--color-yellow-500)}.toast-close.info.svelte-1pgj5gs{color:var(--color-grey-700)}.dark .toast-close.info.svelte-1pgj5gs{color:var(--color-grey-500)}.toast-close.success.svelte-1pgj5gs{color:var(--color-green-700)}.dark .toast-close.success.svelte-1pgj5gs{color:var(--color-green-500)}.toast-text.svelte-1pgj5gs{font-size:var(--text-lg);word-wrap:break-word;overflow-wrap:break-word;word-break:break-word}.toast-text.error.svelte-1pgj5gs{color:var(--color-red-700)}.dark .toast-text.error.svelte-1pgj5gs{color:var(--color-red-50)}.toast-text.warning.svelte-1pgj5gs{color:var(--color-yellow-700)}.dark .toast-text.warning.svelte-1pgj5gs{color:var(--color-yellow-50)}.toast-text.info.svelte-1pgj5gs{color:var(--color-grey-700)}.dark .toast-text.info.svelte-1pgj5gs{color:var(--color-grey-50)}.toast-text.success.svelte-1pgj5gs{color:var(--color-green-700)}.dark .toast-text.success.svelte-1pgj5gs{color:var(--color-green-50)}.toast-details.svelte-1pgj5gs{margin:var(--size-3) var(--size-3) var(--size-3) 0;width:100%}.toast-icon.svelte-1pgj5gs{display:flex;position:absolute;position:relative;flex-shrink:0;justify-content:center;align-items:center;margin:var(--size-2);border-radius:var(--radius-full);padding:var(--size-1);padding-left:calc(var(--size-1) - 1px);width:35px;height:35px}.toast-icon.error.svelte-1pgj5gs{color:var(--color-red-700)}.dark .toast-icon.error.svelte-1pgj5gs{color:var(--color-red-500)}.toast-icon.warning.svelte-1pgj5gs{color:var(--color-yellow-700)}.dark .toast-icon.warning.svelte-1pgj5gs{color:var(--color-yellow-500)}.toast-icon.info.svelte-1pgj5gs{color:var(--color-grey-700)}.dark .toast-icon.info.svelte-1pgj5gs{color:var(--color-grey-500)}.toast-icon.success.svelte-1pgj5gs{color:var(--color-green-700)}.dark .toast-icon.success.svelte-1pgj5gs{color:var(--color-green-500)}@keyframes svelte-1pgj5gs-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}.timer.svelte-1pgj5gs{position:absolute;bottom:0;left:0;transform-origin:0 0;animation:svelte-1pgj5gs-countdown 10s linear forwards;width:100%;height:var(--size-1)}.timer.error.svelte-1pgj5gs{background:var(--color-red-700)}.dark .timer.error.svelte-1pgj5gs{background:var(--color-red-500)}.timer.warning.svelte-1pgj5gs{background:var(--color-yellow-700)}.dark .timer.warning.svelte-1pgj5gs{background:var(--color-yellow-500)}.timer.info.svelte-1pgj5gs{background:var(--color-grey-700)}.dark .timer.info.svelte-1pgj5gs{background:var(--color-grey-500)}.timer.success.svelte-1pgj5gs{background:var(--color-green-700)}.dark .timer.success.svelte-1pgj5gs{background:var(--color-green-500)}.hidden.svelte-1pgj5gs{display:none}.toast-text.svelte-1pgj5gs a{text-decoration:underline}.toast-wrap.svelte-gatr8h{display:flex;position:fixed;top:var(--size-4);right:var(--size-4);flex-direction:column;align-items:end;gap:var(--size-2);z-index:var(--layer-top);width:calc(100% - var(--size-8))}@media (--screen-sm){.toast-wrap.svelte-gatr8h{width:calc(var(--size-96) + var(--size-10))}}.streaming-bar.svelte-ga0jj6{position:absolute;bottom:0;left:0;right:0;height:4px;background-color:var(--primary-600);animation:svelte-ga0jj6-countdown linear forwards;z-index:1}@keyframes svelte-ga0jj6-countdown{0%{transform:translate(0)}to{transform:translate(-100%)}}.wrap.svelte-12ucyq4.svelte-12ucyq4{position:relative;width:100%;height:100%;z-index:var(--layer-1);overflow:hidden}.icon-wrap.svelte-12ucyq4.svelte-12ucyq4{display:block;position:absolute;top:50%;transform:translate(-20.5px,-50%);left:10px;width:40px;transition:.2s;color:var(--body-text-color);height:30px;border-radius:5px;background-color:var(--color-accent);display:flex;align-items:center;justify-content:center;z-index:var(--layer-3);box-shadow:0 0 5px 2px #0000004d;font-size:12px}.icon.left.svelte-12ucyq4.svelte-12ucyq4{transform:rotate(135deg);text-shadow:-1px -1px 1px rgba(0,0,0,.1)}.icon.right.svelte-12ucyq4.svelte-12ucyq4{transform:rotate(-45deg);text-shadow:-1px -1px 1px rgba(0,0,0,.1)}.icon.center.svelte-12ucyq4.svelte-12ucyq4{display:block;width:1px;height:100%;background-color:var(--color);opacity:.1}.icon-wrap.active.svelte-12ucyq4.svelte-12ucyq4,.icon-wrap.disabled.svelte-12ucyq4.svelte-12ucyq4{opacity:0}.outer.svelte-12ucyq4.svelte-12ucyq4{width:20px;height:100%;position:absolute;cursor:grab;top:0;left:-10px;pointer-events:auto;z-index:var(--layer-2)}.grab.svelte-12ucyq4.svelte-12ucyq4{cursor:grabbing}.inner.svelte-12ucyq4.svelte-12ucyq4{width:1px;height:100%;background:var(--color);position:absolute;left:calc((100% - 2px)/2)}.disabled.svelte-12ucyq4.svelte-12ucyq4{cursor:auto}.disabled.svelte-12ucyq4 .inner.svelte-12ucyq4{box-shadow:none}.content.svelte-12ucyq4.svelte-12ucyq4{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.unstyled-link.svelte-151nsdd{all:unset;cursor:pointer}.overlay.svelte-1pwzuub{position:absolute;background-color:#0006;width:100%;height:100%}.hidden.svelte-1pwzuub{display:none}.load-wrap.svelte-1pwzuub{display:flex;justify-content:center;align-items:center;height:100%}.loader.svelte-1pwzuub{display:flex;position:relative;background-color:var(--border-color-accent-subdued);animation:svelte-1pwzuub-shadowPulse 2s linear infinite;box-shadow:-24px 0 var(--border-color-accent-subdued),24px 0 var(--border-color-accent-subdued);margin:var(--spacing-md);border-radius:50%;width:10px;height:10px;scale:.5}@keyframes svelte-1pwzuub-shadowPulse{33%{box-shadow:-24px 0 var(--border-color-accent-subdued),24px 0 #fff;background:#fff}66%{box-shadow:-24px 0 #fff,24px 0 #fff;background:var(--border-color-accent-subdued)}to{box-shadow:-24px 0 #fff,24px 0 var(--border-color-accent-subdued);background:#fff}}.load-wrap.svelte-kn3uji{display:flex;justify-content:center;align-items:center;height:100%}.loader.svelte-kn3uji{display:flex;position:relative;background-color:var(--border-color-accent-subdued);animation:svelte-kn3uji-shadowPulse 2s linear infinite;box-shadow:-24px 0 var(--border-color-accent-subdued),24px 0 var(--border-color-accent-subdued);margin:var(--spacing-md);border-radius:50%;width:10px;height:10px;scale:.5}@keyframes svelte-kn3uji-shadowPulse{33%{box-shadow:-24px 0 var(--border-color-accent-subdued),24px 0 #fff;background:#fff}66%{box-shadow:-24px 0 #fff,24px 0 #fff;background:var(--border-color-accent-subdued)}to{box-shadow:-24px 0 #fff,24px 0 var(--border-color-accent-subdued);background:#fff}}.container.svelte-kn3uji{display:flex;flex-direction:column;align-items:center;justify-content:center;margin:var(--spacing-lg) var(--spacing-lg) 0 var(--spacing-lg)}#timeline.svelte-kn3uji{display:flex;height:var(--size-10);flex:1;position:relative}img.svelte-kn3uji{flex:1 1 auto;min-width:0;object-fit:cover;height:var(--size-12);border:1px solid var(--block-border-color);-webkit-user-select:none;user-select:none;z-index:1}.handle.svelte-kn3uji{width:3px;background-color:var(--color-accent);cursor:ew-resize;height:var(--size-12);z-index:3;position:absolute}.opaque-layer.svelte-kn3uji{background-color:#e6672840;border:1px solid var(--color-accent);height:var(--size-12);position:absolute;z-index:2}.wrap.svelte-cr2edf.svelte-cr2edf{overflow-y:auto;transition:opacity .5s ease-in-out;background:var(--block-background-fill);position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:var(--size-40);width:var(--size-full)}.wrap.svelte-cr2edf.svelte-cr2edf:after{content:"";position:absolute;top:0;left:0;width:var(--upload-progress-width);height:100%;transition:all .5s ease-in-out;z-index:1}.uploading.svelte-cr2edf.svelte-cr2edf{font-size:var(--text-lg);font-family:var(--font);z-index:2}.file-name.svelte-cr2edf.svelte-cr2edf{margin:var(--spacing-md);font-size:var(--text-lg);color:var(--body-text-color-subdued)}.file.svelte-cr2edf.svelte-cr2edf{font-size:var(--text-md);z-index:2;display:flex;align-items:center}.file.svelte-cr2edf progress.svelte-cr2edf{display:inline;height:var(--size-1);width:100%;transition:all .5s ease-in-out;color:var(--color-accent);border:none}.file.svelte-cr2edf progress[value].svelte-cr2edf::-webkit-progress-value{background-color:var(--color-accent);border-radius:20px}.file.svelte-cr2edf progress[value].svelte-cr2edf::-webkit-progress-bar{background-color:var(--border-color-accent);border-radius:20px}.progress-bar.svelte-cr2edf.svelte-cr2edf{width:14px;height:14px;border-radius:50%;background:radial-gradient(closest-side,var(--block-background-fill) 64%,transparent 53% 100%),conic-gradient(var(--color-accent) var(--upload-progress-width),var(--border-color-accent) 0);transition:all .5s ease-in-out}button.svelte-1o7nwih{cursor:pointer;width:var(--size-full)}.center.svelte-1o7nwih{display:flex;justify-content:center}.flex.svelte-1o7nwih{display:flex;flex-direction:column;justify-content:center;align-items:center}.hidden.svelte-1o7nwih{display:none;position:absolute;flex-grow:0}.hidden.svelte-1o7nwih svg{display:none}.disable_click.svelte-1o7nwih{cursor:default}.icon-mode.svelte-1o7nwih{position:absolute!important;width:var(--size-4);height:var(--size-4);padding:0;min-height:0;border-radius:var(--radius-circle)}.icon-mode.svelte-1o7nwih svg{width:var(--size-4);height:var(--size-4)}.container.svelte-uu53fr.svelte-uu53fr{width:100%}time.svelte-uu53fr.svelte-uu53fr{color:var(--color-accent);font-weight:700;padding-left:var(--spacing-xs)}.timeline-wrapper.svelte-uu53fr.svelte-uu53fr{display:flex;align-items:center;justify-content:center;width:100%}.text-button.svelte-uu53fr.svelte-uu53fr{border:1px solid var(--neutral-400);border-radius:var(--radius-sm);font-weight:300;font-size:var(--size-3);text-align:center;color:var(--neutral-400);height:var(--size-5);font-weight:700;padding:0 5px;margin-left:5px}.text-button.svelte-uu53fr.svelte-uu53fr:hover,.text-button.svelte-uu53fr.svelte-uu53fr:focus{color:var(--color-accent);border-color:var(--color-accent)}.controls.svelte-uu53fr.svelte-uu53fr{display:flex;justify-content:space-between;align-items:center;margin:var(--spacing-lg);overflow:hidden}.edit-buttons.svelte-uu53fr.svelte-uu53fr{display:flex;gap:var(--spacing-sm)}@media (max-width: 320px){.controls.svelte-uu53fr.svelte-uu53fr{flex-direction:column;align-items:flex-start}.edit-buttons.svelte-uu53fr.svelte-uu53fr{margin-top:var(--spacing-sm)}.controls.svelte-uu53fr .svelte-uu53fr{margin:var(--spacing-sm)}.controls.svelte-uu53fr .text-button.svelte-uu53fr{margin-left:0}}.container.svelte-uu53fr.svelte-uu53fr{display:flex;flex-direction:column}.hidden.svelte-uu53fr.svelte-uu53fr{display:none}span.svelte-yzke89.svelte-yzke89{text-shadow:0 0 8px rgba(0,0,0,.5)}progress.svelte-yzke89.svelte-yzke89{margin-right:var(--size-3);border-radius:var(--radius-sm);width:var(--size-full);height:var(--size-2)}progress.svelte-yzke89.svelte-yzke89::-webkit-progress-bar{border-radius:2px;background-color:#fff3;overflow:hidden}progress.svelte-yzke89.svelte-yzke89::-webkit-progress-value{background-color:#ffffffe6}.mirror.svelte-yzke89.svelte-yzke89{transform:scaleX(-1)}.mirror-wrap.svelte-yzke89.svelte-yzke89{position:relative;height:100%;width:100%}.controls.svelte-yzke89.svelte-yzke89{position:absolute;bottom:0;opacity:0;transition:.5s;margin:var(--size-2);border-radius:var(--radius-md);background:var(--color-grey-800);padding:var(--size-2) var(--size-1);width:calc(100% - var(--size-2) * 2)}.wrap.svelte-yzke89:hover .controls.svelte-yzke89{opacity:1}.inner.svelte-yzke89.svelte-yzke89{display:flex;justify-content:space-between;align-items:center;padding-right:var(--size-2);padding-left:var(--size-2);width:var(--size-full);height:var(--size-full)}.icon.svelte-yzke89.svelte-yzke89{display:flex;justify-content:center;cursor:pointer;width:var(--size-6);color:#fff}.time.svelte-yzke89.svelte-yzke89{flex-shrink:0;margin-right:var(--size-3);margin-left:var(--size-3);color:#fff;font-size:var(--text-sm);font-family:var(--font-mono)}.wrap.svelte-yzke89.svelte-yzke89{position:relative;background-color:var(--background-fill-secondary);height:var(--size-full);width:var(--size-full);border-radius:var(--radius-xl)}.wrap.svelte-yzke89 video{height:var(--size-full);width:var(--size-full)}.video-container.svelte-4wejaf{height:100%;width:100%;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden}.main-wrapper.svelte-4wejaf{position:relative;width:100%;height:100%;cursor:pointer}.player-wrapper.svelte-4wejaf{position:absolute;top:0;left:0;width:100%;height:100%}.player-wrapper.fixed.svelte-4wejaf{background:var(--block-background-fill)}.main-wrapper>.wrap{position:absolute;top:0;left:0;z-index:10;cursor:default}img.svelte-kxeri3{object-fit:cover}.image-container.svelte-x2tujq.svelte-x2tujq{height:100%;position:relative;min-width:var(--size-20)}.image-container.svelte-x2tujq button.svelte-x2tujq{width:var(--size-full);height:var(--size-full);border-radius:var(--radius-lg);display:flex;align-items:center;justify-content:center}.image-frame.svelte-x2tujq img{width:var(--size-full);height:var(--size-full);object-fit:scale-down}.selectable.svelte-x2tujq.svelte-x2tujq{cursor:crosshair}.fullscreen-controls svg{position:relative;top:0}.image-container:fullscreen{background-color:#000;display:flex;justify-content:center;align-items:center}.image-container:fullscreen img{max-width:90vw;max-height:90vh;object-fit:scale-down}.image-frame.svelte-x2tujq.svelte-x2tujq{width:auto;height:100%;display:flex;align-items:center;justify-content:center}button.svelte-fjcd9c{cursor:pointer;width:var(--size-full)}.wrap.svelte-fjcd9c{display:flex;flex-direction:column;justify-content:center;align-items:center;min-height:var(--size-60);color:var(--block-label-text-color);height:100%;padding-top:var(--size-3)}.icon-wrap.svelte-fjcd9c{width:30px;margin-bottom:var(--spacing-lg)}@media (--screen-md){.wrap.svelte-fjcd9c{font-size:var(--text-lg)}}.wrap.svelte-1tdan5a.svelte-1tdan5a{position:relative;width:var(--size-full);height:var(--size-full)}.hide.svelte-1tdan5a.svelte-1tdan5a{display:none}video.svelte-1tdan5a.svelte-1tdan5a{width:var(--size-full);height:var(--size-full);object-fit:contain}.button-wrap.svelte-1tdan5a.svelte-1tdan5a{position:absolute;background-color:var(--block-background-fill);border:1px solid var(--border-color-primary);padding:var(--size-1-5);display:flex;bottom:var(--size-2);left:50%;transform:translate(-50%);box-shadow:var(--shadow-drop-lg);border-radius:var(--radius-xl);line-height:var(--size-3);color:var(--button-secondary-text-color)}.icon-with-text.svelte-1tdan5a.svelte-1tdan5a{width:var(--size-20);align-items:center;margin:0 var(--spacing-xl);display:flex;justify-content:space-evenly}@media (--screen-md){button.svelte-1tdan5a.svelte-1tdan5a{bottom:var(--size-4)}}@media (--screen-xl){button.svelte-1tdan5a.svelte-1tdan5a{bottom:var(--size-8)}}.icon.svelte-1tdan5a.svelte-1tdan5a{width:18px;height:18px;display:flex;justify-content:space-between;align-items:center}.color-primary.svelte-1tdan5a.svelte-1tdan5a{fill:var(--primary-600);stroke:var(--primary-600);color:var(--primary-600)}.flip.svelte-1tdan5a.svelte-1tdan5a{transform:scaleX(-1)}.select-wrap.svelte-1tdan5a.svelte-1tdan5a{-webkit-appearance:none;-moz-appearance:none;appearance:none;color:var(--button-secondary-text-color);background-color:transparent;width:95%;font-size:var(--text-md);position:absolute;bottom:var(--size-2);background-color:var(--block-background-fill);box-shadow:var(--shadow-drop-lg);border-radius:var(--radius-xl);z-index:var(--layer-top);border:1px solid var(--border-color-primary);text-align:left;line-height:var(--size-4);white-space:nowrap;text-overflow:ellipsis;left:50%;transform:translate(-50%);max-width:var(--size-52)}.select-wrap.svelte-1tdan5a>option.svelte-1tdan5a{padding:.25rem .5rem;border-bottom:1px solid var(--border-color-accent);padding-right:var(--size-8);text-overflow:ellipsis;overflow:hidden}.select-wrap.svelte-1tdan5a>option.svelte-1tdan5a:hover{background-color:var(--color-accent)}.select-wrap.svelte-1tdan5a>option.svelte-1tdan5a:last-child{border:none}.inset-icon.svelte-1tdan5a.svelte-1tdan5a{position:absolute;top:5px;right:-6.5px;width:var(--size-10);height:var(--size-5);opacity:.8}@media (--screen-md){.wrap.svelte-1tdan5a.svelte-1tdan5a{font-size:var(--text-lg)}}.image-frame.svelte-1562gr6 img{width:var(--size-full);height:var(--size-full);object-fit:scale-down}.upload-container.svelte-1562gr6{display:flex;align-items:center;justify-content:center;height:100%;flex-shrink:1;max-height:100%}.reduced-height.svelte-1562gr6{height:calc(100% - var(--size-10))}.image-container.svelte-1562gr6{display:flex;height:100%;flex-direction:column;justify-content:center;align-items:center;max-height:100%}.selectable.svelte-1562gr6{cursor:crosshair}.image-frame.svelte-1562gr6{object-fit:cover;width:100%;height:100%}.container.svelte-1sgcyba img{width:100%;height:100%}.container.selected.svelte-1sgcyba{border-color:var(--border-color-accent)}.border.table.svelte-1sgcyba{border:2px solid var(--border-color-primary)}.container.table.svelte-1sgcyba{margin:0 auto;border-radius:var(--radius-lg);overflow:hidden;width:var(--size-20);height:var(--size-20);object-fit:cover}.container.gallery.svelte-1sgcyba{width:var(--size-20);max-width:var(--size-20);object-fit:cover}.file-name.svelte-1kyjvp4{padding:var(--size-6);font-size:var(--text-xxl);word-break:break-all}.file-size.svelte-1kyjvp4{padding:var(--size-2);font-size:var(--text-xl)}.upload-container.svelte-1kyjvp4{height:100%;width:100%}.video-container.svelte-1kyjvp4{display:flex;height:100%;flex-direction:column;justify-content:center;align-items:center}.container.svelte-9k2sta{display:flex;flex-direction:row;gap:var(--spacing-lg);width:100%;height:100%}.video-slot.svelte-9k2sta{flex:1;display:flex;justify-content:center;align-items:center;min-height:var(--size-60);border:1px solid var(--border-color-primary);border-radius:var(--radius-lg);overflow:hidden;position:relative}.video-slot .upload-text{color:var(--body-text-color-subdued);text-align:center}
src/backend/gradio_videoslider/templates/example/index.js ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const {
2
+ SvelteComponent: k,
3
+ append_hydration: d,
4
+ attr: c,
5
+ children: w,
6
+ claim_element: g,
7
+ claim_space: y,
8
+ detach: o,
9
+ element: v,
10
+ init: E,
11
+ insert_hydration: I,
12
+ noop: p,
13
+ safe_not_equal: q,
14
+ space: b,
15
+ src_url_equal: h,
16
+ toggle_class: f
17
+ } = window.__gradio__svelte__internal;
18
+ function G(r) {
19
+ let e, s, n, u, i, _, a, m;
20
+ return {
21
+ c() {
22
+ e = v("div"), s = v("img"), u = b(), i = v("img"), a = b(), m = v("span"), this.h();
23
+ },
24
+ l(t) {
25
+ e = g(t, "DIV", { class: !0 });
26
+ var l = w(e);
27
+ s = g(l, "IMG", { src: !0, class: !0 }), u = y(l), i = g(l, "IMG", { src: !0, class: !0 }), a = y(l), m = g(l, "SPAN", { class: !0 }), w(m).forEach(o), l.forEach(o), this.h();
28
+ },
29
+ h() {
30
+ h(s.src, n = /*samples_dir*/
31
+ r[1] + /*value*/
32
+ r[0][0]) || c(s, "src", n), c(s, "class", "svelte-l4wpk0"), h(i.src, _ = /*samples_dir*/
33
+ r[1] + /*value*/
34
+ r[0][1]) || c(i, "src", _), c(i, "class", "svelte-l4wpk0"), c(m, "class", "svelte-l4wpk0"), c(e, "class", "wrap svelte-l4wpk0"), f(
35
+ e,
36
+ "table",
37
+ /*type*/
38
+ r[2] === "table"
39
+ ), f(
40
+ e,
41
+ "gallery",
42
+ /*type*/
43
+ r[2] === "gallery"
44
+ ), f(
45
+ e,
46
+ "selected",
47
+ /*selected*/
48
+ r[3]
49
+ );
50
+ },
51
+ m(t, l) {
52
+ I(t, e, l), d(e, s), d(e, u), d(e, i), d(e, a), d(e, m);
53
+ },
54
+ p(t, [l]) {
55
+ l & /*samples_dir, value*/
56
+ 3 && !h(s.src, n = /*samples_dir*/
57
+ t[1] + /*value*/
58
+ t[0][0]) && c(s, "src", n), l & /*samples_dir, value*/
59
+ 3 && !h(i.src, _ = /*samples_dir*/
60
+ t[1] + /*value*/
61
+ t[0][1]) && c(i, "src", _), l & /*type*/
62
+ 4 && f(
63
+ e,
64
+ "table",
65
+ /*type*/
66
+ t[2] === "table"
67
+ ), l & /*type*/
68
+ 4 && f(
69
+ e,
70
+ "gallery",
71
+ /*type*/
72
+ t[2] === "gallery"
73
+ ), l & /*selected*/
74
+ 8 && f(
75
+ e,
76
+ "selected",
77
+ /*selected*/
78
+ t[3]
79
+ );
80
+ },
81
+ i: p,
82
+ o: p,
83
+ d(t) {
84
+ t && o(e);
85
+ }
86
+ };
87
+ }
88
+ function M(r, e, s) {
89
+ let { value: n } = e, { samples_dir: u } = e, { type: i } = e, { selected: _ = !1 } = e;
90
+ return r.$$set = (a) => {
91
+ "value" in a && s(0, n = a.value), "samples_dir" in a && s(1, u = a.samples_dir), "type" in a && s(2, i = a.type), "selected" in a && s(3, _ = a.selected);
92
+ }, [n, u, i, _];
93
+ }
94
+ class S extends k {
95
+ constructor(e) {
96
+ super(), E(this, e, M, G, q, {
97
+ value: 0,
98
+ samples_dir: 1,
99
+ type: 2,
100
+ selected: 3
101
+ });
102
+ }
103
+ }
104
+ export {
105
+ S as default
106
+ };
src/backend/gradio_videoslider/templates/example/style.css ADDED
@@ -0,0 +1 @@
 
 
1
+ .wrap.svelte-l4wpk0.svelte-l4wpk0{position:relative;height:var(--size-64);width:var(--size-40);overflow:hidden;border-radius:var(--radius-lg)}img.svelte-l4wpk0.svelte-l4wpk0{height:var(--size-64);width:var(--size-40);position:absolute;object-fit:cover}.wrap.selected.svelte-l4wpk0.svelte-l4wpk0{border-color:var(--color-accent)}.wrap.svelte-l4wpk0 img.svelte-l4wpk0:first-child{clip-path:inset(0 50% 0 0%)}.wrap.svelte-l4wpk0 img.svelte-l4wpk0:nth-of-type(2){clip-path:inset(0 0 0 50%)}span.svelte-l4wpk0.svelte-l4wpk0{position:absolute;top:0;left:calc(50% - .75px);height:var(--size-64);width:1.5px;background:var(--border-color-primary)}.table.svelte-l4wpk0.svelte-l4wpk0{margin:0 auto;border:2px solid var(--border-color-primary);border-radius:var(--radius-lg)}.gallery.svelte-l4wpk0.svelte-l4wpk0{border:2px solid var(--border-color-primary);object-fit:cover}
src/backend/gradio_videoslider/videoslider.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # In backend/videoslider.py
2
+ from __future__ import annotations
3
+
4
+ from pathlib import Path
5
+ from typing import Any, Callable, List, Tuple
6
+
7
+ from gradio_client import handle_file
8
+ from gradio_client.documentation import document
9
+
10
+ from gradio import processing_utils
11
+ from gradio.components.base import Component
12
+ from gradio.data_classes import FileData, GradioRootModel
13
+ from gradio.events import Events
14
+
15
+ class VideoSliderData(GradioRootModel):
16
+ """
17
+ Data model for the VideoSlider component. Represents the data structure
18
+ sent between the frontend and backend, which is a tuple of two FileData objects.
19
+ """
20
+ root: Tuple[FileData | None, FileData | None]
21
+
22
+ # Type alias for the value passed to or returned from a user's function.
23
+ # It's a tuple of two file paths (string or Path object).
24
+ VideoSliderValue = Tuple[str | Path | None, str | Path | None]
25
+
26
+ @document()
27
+ class VideoSlider(Component):
28
+ """
29
+ A custom Gradio component to display a side-by-side video comparison with a slider.
30
+ It can be used as both an input (uploading two videos) and an output (displaying two videos).
31
+ """
32
+ # The data model used for communication with the frontend.
33
+ data_model = VideoSliderData
34
+ # The events that this component can trigger.
35
+ EVENTS = [Events.change, Events.upload, Events.clear]
36
+
37
+ def __init__(
38
+ self,
39
+ value: Tuple[str | Path, str | Path] | Callable | None = None,
40
+ *,
41
+ height: int | None = None,
42
+ width: int | None = None,
43
+ label: str | None = None,
44
+ every: float | None = None,
45
+ show_label: bool | None = None,
46
+ container: bool = True,
47
+ scale: int | None = None,
48
+ min_width: int = 160,
49
+ interactive: bool | None = None,
50
+ visible: bool = True,
51
+ elem_id: str | None = None,
52
+ elem_classes: List[str] | str | None = None,
53
+ position: int = 50,
54
+ show_download_button: bool = True,
55
+ show_fullscreen_button: bool = True,
56
+ autoplay: bool = False,
57
+ loop: bool = False,
58
+ ):
59
+ """
60
+ Initializes the VideoSlider component.
61
+
62
+ Parameters:
63
+ value: A tuple of two video file paths or URLs to display initially.
64
+ height: The height of the component in pixels.
65
+ width: The width of the component in pixels.
66
+ label: The label for this component.
67
+ position: The initial position of the slider, from 0 to 100.
68
+ autoplay: If True, the videos will start playing automatically.
69
+ loop: If True, the videos will loop when they finish.
70
+ interactive: If False, the component will be in display-only mode.
71
+ """
72
+ self.height = height
73
+ self.width = width
74
+ self.position = position
75
+ self.show_download_button = show_download_button
76
+ self.show_fullscreen_button = show_fullscreen_button
77
+ self.autoplay = autoplay
78
+ self.loop = loop
79
+ self.type = "filepath" # The component handles file paths.
80
+
81
+ super().__init__(
82
+ label=label,
83
+ every=every,
84
+ show_label=show_label,
85
+ container=container,
86
+ scale=scale,
87
+ min_width=min_width,
88
+ interactive=interactive,
89
+ visible=visible,
90
+ elem_id=elem_id,
91
+ elem_classes=elem_classes,
92
+ value=value,
93
+ )
94
+
95
+ def preprocess(self, payload: VideoSliderData | None) -> VideoSliderValue | None:
96
+ """
97
+ Processes data from the frontend into a format usable by a Python function.
98
+ It converts the FileData objects into a tuple of simple string file paths.
99
+ """
100
+ if payload is None or payload.root is None:
101
+ return None
102
+
103
+ video1, video2 = payload.root
104
+
105
+ p1 = Path(video1.path) if video1 and video1.path else None
106
+ p2 = Path(video2.path) if video2 and video2.path else None
107
+
108
+ return (str(p1) if p1 else None, str(p2) if p2 else None)
109
+
110
+ def postprocess(self, value: VideoSliderValue | None) -> VideoSliderData | None:
111
+ """
112
+ Processes data returned from a Python function into a format for the frontend.
113
+ It takes a tuple of file paths, makes them servable by Gradio, and returns
114
+ a VideoSliderData object.
115
+ """
116
+ if value is None or (value[0] is None and value[1] is None):
117
+ return None
118
+
119
+ video1_path, video2_path = value
120
+
121
+ fd1 = None
122
+ if video1_path:
123
+ # Copies the file to a temp cache and returns a FileData object.
124
+ new_path = processing_utils.move_resource_to_block_cache(video1_path, self)
125
+ fd1 = FileData(path=str(new_path))
126
+
127
+ fd2 = None
128
+ if video2_path:
129
+ new_path = processing_utils.move_resource_to_block_cache(video2_path, self)
130
+ fd2 = FileData(path=str(new_path))
131
+
132
+ return VideoSliderData(root=(fd1, fd2))
133
+
134
+ def api_info(self) -> dict[str, Any]:
135
+ """
136
+ Provides API information for the component.
137
+ """
138
+ return {"type": "array", "items": {"type": "string", "description": "path to video file"}, "length": 2}
139
+
140
+ def example_payload(self) -> Any:
141
+ """
142
+ Returns an example payload for the component's API documentation.
143
+ """
144
+ video_url = "https://gradio-builds.s3.amazonaws.com/demo-files/world.mp4"
145
+ return VideoSliderData(root=(handle_file(video_url), handle_file(video_url)))
146
+
147
+ def example_value(self) -> Any:
148
+ """
149
+ Returns an example value for the component's API documentation.
150
+ """
151
+ video_url = "https://gradio-builds.s3.amazonaws.com/demo-files/world.mp4"
152
+ return (video_url, video_url)
src/demo/__init__.py ADDED
File without changes
src/demo/app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # In demo/app.py
2
+ import gradio as gr
3
+ from gradio_videoslider import VideoSlider
4
+ import os
5
+
6
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
7
+ #
8
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
9
+ #
10
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
11
+ # video_path_1 = "video_antes.mp4"
12
+ # video_path_2 = "video_depois.mp4"
13
+ #
14
+ # Option B: Absolute Path (the full path to the file on your computer)
15
+ # Example for Windows:
16
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
17
+ #
18
+ # Example for Linux/macOS:
19
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
20
+
21
+ # Set your file paths here:
22
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
23
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
24
+
25
+
26
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
27
+ def process_uploaded_videos(video_inputs):
28
+ """This function handles the uploaded videos."""
29
+ print("Received videos from upload:", video_inputs)
30
+ return video_inputs
31
+
32
+
33
+ # --- 3. GRADIO INTERFACE ---
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("# Video Slider Component Usage Examples")
36
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
37
+
38
+ with gr.Tabs():
39
+ # --- TAB 1: UPLOAD EXAMPLE ---
40
+ with gr.TabItem("1. Compare via Upload"):
41
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
42
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
43
+ video_slider_output = VideoSlider(
44
+ label="Video comparision",
45
+ interactive=False,
46
+ autoplay=True,
47
+ loop=True,
48
+ height=400,
49
+ width=700
50
+ )
51
+ submit_btn = gr.Button("Submit")
52
+ submit_btn.click(
53
+ fn=process_uploaded_videos,
54
+ inputs=[video_slider_input],
55
+ outputs=[video_slider_output]
56
+ )
57
+
58
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
59
+ with gr.TabItem("2. Compare Local Files"):
60
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
61
+
62
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
63
+ VideoSlider(
64
+ label="Video comparision",
65
+ value=(video_path_1, video_path_2),
66
+ interactive=False,
67
+ autoplay=True,
68
+ loop=True,
69
+ height=400,
70
+ width=700
71
+ )
72
+
73
+ # Optional: A check to give a helpful error message if files are not found.
74
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
75
+ print("---")
76
+ print(f"WARNING: Could not find one or both video files.")
77
+ print(f"Please make sure these paths are correct in your app.py file:")
78
+ print(f" - '{os.path.abspath(video_path_1)}'")
79
+ print(f" - '{os.path.abspath(video_path_2)}'")
80
+ print("---")
81
+
82
+ if __name__ == '__main__':
83
+ demo.launch()
src/demo/css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
src/demo/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_videoslider
src/demo/space.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'VideoSlider': {'description': 'A custom Gradio component to display a side-by-side video comparison with a slider.\nIt can be used as both an input (uploading two videos) and an output (displaying two videos).', 'members': {'__init__': {'value': {'type': 'typing.Union[\n typing.Tuple[str | pathlib.Path, str | pathlib.Path],\n typing.Callable,\n NoneType,\n][\n typing.Tuple[str | pathlib.Path, str | pathlib.Path][\n str | pathlib.Path, str | pathlib.Path\n ],\n Callable,\n None,\n]', 'default': 'None', 'description': 'A tuple of two video file paths or URLs to display initially.'}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'The height of the component in pixels.'}, 'width': {'type': 'int | None', 'default': 'None', 'description': 'The width of the component in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': 'If False, the component will be in display-only mode.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'typing.Union[typing.List[str], str, NoneType][\n typing.List[str][str], str, None\n]', 'default': 'None', 'description': None}, 'position': {'type': 'int', 'default': '50', 'description': 'The initial position of the slider, from 0 to 100.'}, 'show_download_button': {'type': 'bool', 'default': 'True', 'description': None}, 'show_fullscreen_button': {'type': 'bool', 'default': 'True', 'description': None}, 'autoplay': {'type': 'bool', 'default': 'False', 'description': 'If True, the videos will start playing automatically.'}, 'loop': {'type': 'bool', 'default': 'False', 'description': 'If True, the videos will loop when they finish.'}}, 'postprocess': {'value': {'type': 'typing.Optional[\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ]\n][\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ][str | pathlib.Path | None, str | pathlib.Path | None],\n None,\n]', 'description': None}}, 'preprocess': {'return': {'type': 'typing.Optional[\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ]\n][\n typing.Tuple[\n str | pathlib.Path | None, str | pathlib.Path | None\n ][str | pathlib.Path | None, str | pathlib.Path | None],\n None,\n]', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the VideoSlider changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the VideoSlider.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the VideoSlider using the clear button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'VideoSlider': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_videoslider`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ VideoSlider Component for Gradio
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_videoslider
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ # In demo/app.py
42
+ import gradio as gr
43
+ from gradio_videoslider import VideoSlider
44
+ import os
45
+
46
+ # --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
47
+ #
48
+ # IMPORTANT: Replace the values below with the paths to YOUR video files.
49
+ #
50
+ # Option A: Relative Path (if the video is in the same folder as this app.py)
51
+ # video_path_1 = "video_antes.mp4"
52
+ # video_path_2 = "video_depois.mp4"
53
+ #
54
+ # Option B: Absolute Path (the full path to the file on your computer)
55
+ # Example for Windows:
56
+ # video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
57
+ #
58
+ # Example for Linux/macOS:
59
+ # video_path_1 = "/home/yourname/videos/my_video_1.mp4"
60
+
61
+ # Set your file paths here:
62
+ video_path_1 = "examples/SampleVideo 720x480.mp4"
63
+ video_path_2 = "examples/SampleVideo 1280x720.mp4"
64
+
65
+
66
+ # --- 2. FUNCTION FOR THE UPLOAD EXAMPLE (remains the same) ---
67
+ def process_uploaded_videos(video_inputs):
68
+ \"\"\"This function handles the uploaded videos.\"\"\"
69
+ print("Received videos from upload:", video_inputs)
70
+ return video_inputs
71
+
72
+
73
+ # --- 3. GRADIO INTERFACE ---
74
+ with gr.Blocks() as demo:
75
+ gr.Markdown("# Video Slider Component Usage Examples")
76
+ gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
77
+
78
+ with gr.Tabs():
79
+ # --- TAB 1: UPLOAD EXAMPLE ---
80
+ with gr.TabItem("1. Compare via Upload"):
81
+ gr.Markdown("## Upload two videos to compare them side-by-side.")
82
+ video_slider_input = VideoSlider(label="Your Videos", height=400, width=700)
83
+ video_slider_output = VideoSlider(
84
+ label="Video comparision",
85
+ interactive=False,
86
+ autoplay=True,
87
+ loop=True,
88
+ height=400,
89
+ width=700
90
+ )
91
+ submit_btn = gr.Button("Submit")
92
+ submit_btn.click(
93
+ fn=process_uploaded_videos,
94
+ inputs=[video_slider_input],
95
+ outputs=[video_slider_output]
96
+ )
97
+
98
+ # --- TAB 2: LOCAL FILE EXAMPLE ---
99
+ with gr.TabItem("2. Compare Local Files"):
100
+ gr.Markdown("## Example with videos pre-loaded from your local disk.")
101
+
102
+ # This is the key part: we pass a tuple of your local file paths to the `value` parameter.
103
+ VideoSlider(
104
+ label="Video comparision",
105
+ value=(video_path_1, video_path_2),
106
+ interactive=False,
107
+ autoplay=True,
108
+ loop=True,
109
+ height=400,
110
+ width=700
111
+ )
112
+
113
+ # Optional: A check to give a helpful error message if files are not found.
114
+ if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
115
+ print("---")
116
+ print(f"WARNING: Could not find one or both video files.")
117
+ print(f"Please make sure these paths are correct in your app.py file:")
118
+ print(f" - '{os.path.abspath(video_path_1)}'")
119
+ print(f" - '{os.path.abspath(video_path_2)}'")
120
+ print("---")
121
+
122
+ if __name__ == '__main__':
123
+ demo.launch()
124
+
125
+ ```
126
+ """, elem_classes=["md-custom"], header_links=True)
127
+
128
+
129
+ gr.Markdown("""
130
+ ## `VideoSlider`
131
+
132
+ ### Initialization
133
+ """, elem_classes=["md-custom"], header_links=True)
134
+
135
+ gr.ParamViewer(value=_docs["VideoSlider"]["members"]["__init__"], linkify=[])
136
+
137
+
138
+ gr.Markdown("### Events")
139
+ gr.ParamViewer(value=_docs["VideoSlider"]["events"], linkify=['Event'])
140
+
141
+
142
+
143
+
144
+ gr.Markdown("""
145
+
146
+ ### User function
147
+
148
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
149
+
150
+ - When used as an Input, the component only impacts the input signature of the user function.
151
+ - When used as an output, the component only impacts the return signature of the user function.
152
+
153
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
154
+
155
+
156
+
157
+ ```python
158
+ def predict(
159
+ value: typing.Optional[
160
+ typing.Tuple[
161
+ str | pathlib.Path | None, str | pathlib.Path | None
162
+ ]
163
+ ][
164
+ typing.Tuple[
165
+ str | pathlib.Path | None, str | pathlib.Path | None
166
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
167
+ None,
168
+ ]
169
+ ) -> typing.Optional[
170
+ typing.Tuple[
171
+ str | pathlib.Path | None, str | pathlib.Path | None
172
+ ]
173
+ ][
174
+ typing.Tuple[
175
+ str | pathlib.Path | None, str | pathlib.Path | None
176
+ ][str | pathlib.Path | None, str | pathlib.Path | None],
177
+ None,
178
+ ]:
179
+ return value
180
+ ```
181
+ """, elem_classes=["md-custom", "VideoSlider-user-fn"], header_links=True)
182
+
183
+
184
+
185
+
186
+ demo.load(None, js=r"""function() {
187
+ const refs = {};
188
+ const user_fn_refs = {
189
+ VideoSlider: [], };
190
+ requestAnimationFrame(() => {
191
+
192
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
193
+ if (refs.length > 0) {
194
+ const el = document.querySelector(`.${key}-user-fn`);
195
+ if (!el) return;
196
+ refs.forEach(ref => {
197
+ el.innerHTML = el.innerHTML.replace(
198
+ new RegExp("\\b"+ref+"\\b", "g"),
199
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
200
+ );
201
+ })
202
+ }
203
+ })
204
+
205
+ Object.entries(refs).forEach(([key, refs]) => {
206
+ if (refs.length > 0) {
207
+ const el = document.querySelector(`.${key}`);
208
+ if (!el) return;
209
+ refs.forEach(ref => {
210
+ el.innerHTML = el.innerHTML.replace(
211
+ new RegExp("\\b"+ref+"\\b", "g"),
212
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
213
+ );
214
+ })
215
+ }
216
+ })
217
+ })
218
+ }
219
+
220
+ """)
221
+
222
+ demo.launch()
src/examples/SampleVideo 1280x720.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f25b31f155970c46300934bda4a76cd2f581acab45c49762832ffdfddbcf9fdd
3
+ size 1055736
src/examples/Samplevideo 720x480.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99d1ffc857ae1c12f0c378e7503a0057232e920ab6666a35f55caab37d43322a
3
+ size 564010
src/frontend/Example.svelte ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: [string, string];
3
+ export let samples_dir: string;
4
+ export let type: "gallery" | "table";
5
+ export let selected = false;
6
+ </script>
7
+
8
+ <!-- TODO: fix -->
9
+ <!-- svelte-ignore a11y-missing-attribute -->
10
+ <div
11
+ class="wrap"
12
+ class:table={type === "table"}
13
+ class:gallery={type === "gallery"}
14
+ class:selected
15
+ >
16
+ <img src={samples_dir + value[0]} />
17
+
18
+ <img src={samples_dir + value[1]} />
19
+ <span></span>
20
+ </div>
21
+
22
+ <style>
23
+ .wrap {
24
+ position: relative;
25
+ height: var(--size-64);
26
+ width: var(--size-40);
27
+ overflow: hidden;
28
+ border-radius: var(--radius-lg);
29
+ }
30
+ img {
31
+ height: var(--size-64);
32
+ width: var(--size-40);
33
+ position: absolute;
34
+ /* border-radius: var(--radius-lg); */
35
+ /* max-width: none; */
36
+ object-fit: cover;
37
+ }
38
+
39
+ .wrap.selected {
40
+ border-color: var(--color-accent);
41
+ }
42
+ .wrap img:first-child {
43
+ clip-path: inset(0 50% 0 0%);
44
+ }
45
+
46
+ .wrap img:nth-of-type(2) {
47
+ clip-path: inset(0 0 0 50%);
48
+ }
49
+ span {
50
+ position: absolute;
51
+ top: 0;
52
+ left: calc(50% - 0.75px);
53
+ height: var(--size-64);
54
+ width: 1.5px;
55
+ background: var(--border-color-primary);
56
+ }
57
+
58
+ .table {
59
+ margin: 0 auto;
60
+ border: 2px solid var(--border-color-primary);
61
+ border-radius: var(--radius-lg);
62
+ }
63
+
64
+ .gallery {
65
+ border: 2px solid var(--border-color-primary);
66
+ /* max-height: var(--size-20); */
67
+ object-fit: cover;
68
+ }
69
+ </style>
src/frontend/Index.svelte ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- videoslider/frontend/Index.svelte -->
2
+ <!-- Enable programmatic access to the component's props from outside. -->
3
+ <svelte:options accessors={true} />
4
+
5
+ <script lang="ts">
6
+ // Import Gradio types and common components.
7
+ import type { Gradio } from "@gradio/utils";
8
+ import { Block } from "@gradio/atoms";
9
+ import { StatusTracker } from "@gradio/statustracker";
10
+ import type { FileData } from "@gradio/client";
11
+ import type { LoadingStatus } from "@gradio/statustracker";
12
+
13
+ // Import the two main views for this component.
14
+ import VideoSliderPreview from "./shared/VideoSliderPreview.svelte";
15
+ import InteractiveVideoSlider from "./shared/InteractiveVideoSlider.svelte";
16
+
17
+ // ------------------
18
+ // Props from Backend
19
+ // ------------------
20
+ export let elem_id = "";
21
+ export let elem_classes: string[] = [];
22
+ export let visible = true;
23
+ /** The core value of the component: a tuple of two video files. */
24
+ export let value: [FileData | null, FileData | null] = [null, null];
25
+ export let label: string;
26
+ export let show_label: boolean;
27
+ export let root: string;
28
+ export let height: number | undefined;
29
+ export let width: number | undefined;
30
+ export let container = true;
31
+ export let scale: number | null = null;
32
+ export let min_width: number | undefined = undefined;
33
+ export let loading_status: LoadingStatus;
34
+ /** If false, the component is in display-only mode. */
35
+ export let interactive: boolean;
36
+ export let show_download_button: boolean;
37
+ export let show_fullscreen_button: boolean;
38
+ /** The initial position of the slider, from 0 to 100. */
39
+ export let position: number;
40
+ export let autoplay: boolean;
41
+ export let loop: boolean;
42
+ /** The Gradio event dispatcher. */
43
+ export let gradio: Gradio<{
44
+ change: never;
45
+ clear: never;
46
+ upload: never;
47
+ error: string;
48
+ }>;
49
+
50
+ // -----------------
51
+ // Internal State
52
+ // -----------------
53
+ /** Holds the fullscreen state for the component. */
54
+ let fullscreen = false;
55
+ /** Stores the previous value to detect changes. */
56
+ let old_value: [FileData | null, FileData | null] = [null, null];
57
+ /** Tracks if the user is dragging over the upload area. */
58
+ let dragging = false;
59
+
60
+ // -----------------
61
+ // Reactive Logic
62
+ // -----------------
63
+ /** Converts the 0-100 position from Python to a 0-1 scale for CSS. */
64
+ $: normalised_slider_position = Math.max(0, Math.min(100, position)) / 100;
65
+
66
+ /** Dispatches a 'change' event whenever the `value` prop is updated from within the component. */
67
+ $: {
68
+ if (JSON.stringify(value) !== JSON.stringify(old_value)) {
69
+ old_value = value;
70
+ gradio.dispatch("change");
71
+ }
72
+ }
73
+ </script>
74
+
75
+ <!--
76
+ This block acts as a router.
77
+ It displays one of two sub-components based on the `interactive` prop from the backend.
78
+ -->
79
+ {#if !interactive}
80
+ <!-- Static/Output Mode: Shows the side-by-side video player with a slider. -->
81
+ <Block
82
+ {visible}
83
+ variant={"solid"}
84
+ padding={false}
85
+ {elem_id}
86
+ {elem_classes}
87
+ {height}
88
+ {width}
89
+ {container}
90
+ {scale}
91
+ {min_width}
92
+ allow_overflow={false}
93
+ bind:fullscreen
94
+ >
95
+ <StatusTracker
96
+ autoscroll={gradio.autoscroll}
97
+ i18n={gradio.i18n}
98
+ {...loading_status}
99
+ />
100
+ <VideoSliderPreview
101
+ bind:value
102
+ {interactive}
103
+ {label}
104
+ {show_label}
105
+ {show_download_button}
106
+ {show_fullscreen_button}
107
+ i18n={gradio.i18n}
108
+ position={normalised_slider_position}
109
+ slider_color="var(--border-color-primary)"
110
+ on:clear={() => gradio.dispatch("clear")}
111
+ on:fullscreen={({ detail }) => { fullscreen = detail; }}
112
+ {autoplay}
113
+ {loop}
114
+ upload={(...args) => gradio.client.upload(...args)}
115
+ />
116
+ </Block>
117
+ {:else}
118
+ <!-- Interactive/Input Mode: Shows two upload boxes for the user to add videos. -->
119
+ <Block
120
+ {visible}
121
+ variant={"solid"}
122
+ border_mode={dragging ? "focus" : "base"}
123
+ padding={true}
124
+ {elem_id}
125
+ {elem_classes}
126
+ {height}
127
+ {width}
128
+ {container}
129
+ {scale}
130
+ {min_width}
131
+ allow_overflow={false}
132
+ >
133
+ <StatusTracker
134
+ autoscroll={gradio.autoscroll}
135
+ i18n={gradio.i18n}
136
+ {...loading_status}
137
+ />
138
+ <InteractiveVideoSlider
139
+ bind:value
140
+ {root}
141
+ on:upload={() => gradio.dispatch("upload")}
142
+ on:clear={() => gradio.dispatch("clear")}
143
+ on:error={({ detail }) => gradio.dispatch("error", detail)}
144
+ {label}
145
+ {show_label}
146
+ max_file_size={gradio.max_file_size}
147
+ i18n={gradio.i18n}
148
+ upload={(...args) => gradio.client.upload(...args)}
149
+ stream_handler={gradio.client?.stream}
150
+ {autoplay}
151
+ {loop}
152
+ />
153
+ </Block>
154
+ {/if}
src/frontend/gradio.config.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export default {
2
+ plugins: [],
3
+ svelte: {
4
+ preprocess: [],
5
+ },
6
+ build: {
7
+ target: "modules",
8
+ },
9
+ };
src/frontend/package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
src/frontend/package.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "gradio_videoslider",
3
+ "version": "0.1.0",
4
+ "description": "A video slider component for Gradio to compare two videos.",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "Apache-2.0",
8
+ "private": false,
9
+ "dependencies": {
10
+ "d3-drag": "^3.0.0",
11
+ "d3-selection": "^3.0.0",
12
+ "@types/d3-drag": "^3.0.7",
13
+ "@types/d3-selection": "^3.0.11",
14
+ "@ffmpeg/ffmpeg": "^0.12.7",
15
+ "@ffmpeg/util": "^0.12.1",
16
+ "hls.js": "^1.5.13",
17
+ "mrmime": "^2.0.0",
18
+ "@gradio/atoms": "0.16.3",
19
+ "@gradio/client": "1.15.5",
20
+ "@gradio/icons": "0.12.0",
21
+ "@gradio/image": "0.22.12",
22
+ "@gradio/statustracker": "0.10.14",
23
+ "@gradio/upload": "0.16.10",
24
+ "@gradio/utils": "0.10.2",
25
+ "@gradio/wasm": "0.18.1"
26
+ },
27
+ "devDependencies": {
28
+ "@gradio/preview": "0.14.0"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "gradio": "./Index.svelte",
33
+ "svelte": "./dist/Index.svelte",
34
+ "types": "./dist/Index.svelte.d.ts"
35
+ },
36
+ "./example": {
37
+ "gradio": "./Example.svelte",
38
+ "svelte": "./dist/Example.svelte",
39
+ "types": "./dist/Example.svelte.d.ts"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "peerDependencies": {
44
+ "svelte": "^4.0.0"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/gradio-app/gradio.git",
49
+ "directory": "js/videoslider"
50
+ }
51
+ }
src/frontend/shared/InteractiveVideo.svelte ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component provides an interactive area for a single video. It can handle
4
+ uploading a video file, recording from a webcam, or displaying an existing video.
5
+ It's a building block for more complex components like the InteractiveVideoSlider.
6
+ -->
7
+ <script lang="ts">
8
+ import { createEventDispatcher } from "svelte";
9
+ import { Upload } from "@gradio/upload";
10
+ import type { FileData, Client } from "@gradio/client";
11
+ import { BlockLabel, SelectSource } from "@gradio/atoms";
12
+ import { Webcam } from "@gradio/image";
13
+ import { Video } from "@gradio/icons";
14
+ import type { WebcamOptions } from "./utils";
15
+ import { prettyBytes } from "./utils";
16
+ import Player from "./Player.svelte";
17
+ import type { I18nFormatter } from "@gradio/utils";
18
+
19
+ // ------------------
20
+ // Props
21
+ // ------------------
22
+ /** The FileData object representing the current video. */
23
+ export let value: FileData | null = null;
24
+ export let subtitle: FileData | null = null;
25
+ /** The available input sources, e.g., 'upload', 'webcam'. */
26
+ export let sources:
27
+ | ["webcam"]
28
+ | ["upload"]
29
+ | ["webcam", "upload"]
30
+ | ["upload", "webcam"] = ["webcam", "upload"];
31
+ export let label: string | undefined = undefined;
32
+ export let show_download_button = false;
33
+ export let show_label = true;
34
+ export let webcam_options: WebcamOptions;
35
+ export let include_audio: boolean;
36
+ export let autoplay: boolean;
37
+ export let root: string;
38
+ export let i18n: I18nFormatter;
39
+ /** The currently selected input source. */
40
+ export let active_source: "webcam" | "upload" = "webcam";
41
+ export let handle_reset_value: () => void = () => {};
42
+ export let max_file_size: number | null = null;
43
+ export let upload: Client["upload"];
44
+ export let stream_handler: Client["stream"];
45
+ export let loop: boolean;
46
+ export let uploading = false;
47
+
48
+ // -----------------
49
+ // Internal State
50
+ // -----------------
51
+ /** Tracks if the video has been edited (e.g., trimmed). */
52
+ let has_change_history = false;
53
+ /** Tracks if the user is dragging a file over the component. */
54
+ let dragging = false;
55
+
56
+ const dispatch = createEventDispatcher<{
57
+ change: FileData | null;
58
+ drag: boolean;
59
+ error: string;
60
+ upload: FileData;
61
+ }>();
62
+
63
+ // -----------------
64
+ // Event Handlers
65
+ // -----------------
66
+
67
+ /** Handles the 'load' event from the Upload component. */
68
+ function handle_load({ detail }: CustomEvent<FileData | null>): void {
69
+ value = detail;
70
+ dispatch("change", detail);
71
+ dispatch("upload", detail!);
72
+ }
73
+
74
+ /** Handles the 'clear' event. */
75
+ function handle_clear(): void {
76
+ value = null;
77
+ dispatch("change", null);
78
+ }
79
+
80
+ /** Handles changes from the Player (e.g., after trimming). */
81
+ function handle_change(video: FileData): void {
82
+ has_change_history = true;
83
+ dispatch("change", video);
84
+ }
85
+
86
+ /** Handles a new video captured from the webcam. */
87
+ function handle_capture({
88
+ detail
89
+ }: CustomEvent<FileData | any | null>): void {
90
+ dispatch("change", detail);
91
+ }
92
+
93
+ /** Dispatches the 'drag' event when the dragging state changes. */
94
+ $: dispatch("drag", dragging);
95
+ </script>
96
+
97
+ <BlockLabel {show_label} Icon={Video} label={label || "Video"} />
98
+
99
+ <div data-testid="video" class="video-container">
100
+ <!-- If no video is loaded, show the upload or webcam interface. -->
101
+ {#if value === null || value.url === undefined}
102
+ <div class="upload-container">
103
+ {#if active_source === "upload"}
104
+ <Upload
105
+ bind:dragging
106
+ bind:uploading
107
+ filetype="video/x-m4v,video/*"
108
+ on:load={handle_load}
109
+ {max_file_size}
110
+ on:error={({ detail }) => dispatch("error", detail)}
111
+ {root}
112
+ {upload}
113
+ {stream_handler}
114
+ aria_label={i18n("video.drop_to_upload")}
115
+ >
116
+ <slot />
117
+ </Upload>
118
+ {:else if active_source === "webcam"}
119
+ <Webcam
120
+ {root}
121
+ mirror_webcam={webcam_options.mirror}
122
+ webcam_constraints={webcam_options.constraints}
123
+ {include_audio}
124
+ mode="video"
125
+ on:error
126
+ on:capture={handle_capture}
127
+ on:start_recording
128
+ on:stop_recording
129
+ {i18n}
130
+ {upload}
131
+ stream_every={1}
132
+ />
133
+ {/if}
134
+ </div>
135
+ <!-- If a video is loaded, display the player. -->
136
+ {:else if value?.url}
137
+ <!-- Use a key to force re-rendering of the Player when the video URL changes. -->
138
+ {#key value?.url}
139
+ <Player
140
+ {upload}
141
+ {root}
142
+ interactive
143
+ src={value.url}
144
+ subtitle={subtitle?.url}
145
+ is_stream={false}
146
+ mirror={webcam_options.mirror && active_source === "webcam"}
147
+ {label}
148
+ {handle_change}
149
+ {handle_reset_value}
150
+ {loop}
151
+ {value}
152
+ {i18n}
153
+ {show_download_button}
154
+ {handle_clear}
155
+ {has_change_history}
156
+ />
157
+ {/key}
158
+ <!-- Fallback for file data without a URL (e.g., before upload completes). -->
159
+ {:else if value.size}
160
+ <div class="file-name">{value.orig_name || value.url}</div>
161
+ <div class="file-size">
162
+ {prettyBytes(value.size)}
163
+ </div>
164
+ {/if}
165
+
166
+ <!-- Show the source selection buttons (upload/webcam). -->
167
+ <SelectSource {sources} bind:active_source {handle_clear} />
168
+ </div>
169
+
170
+ <style>
171
+ .file-name {
172
+ padding: var(--size-6);
173
+ font-size: var(--text-xxl);
174
+ word-break: break-all;
175
+ }
176
+
177
+ .file-size {
178
+ padding: var(--size-2);
179
+ font-size: var(--text-xl);
180
+ }
181
+
182
+ .upload-container {
183
+ height: 100%;
184
+ width: 100%;
185
+ }
186
+
187
+ .video-container {
188
+ display: flex;
189
+ height: 100%;
190
+ flex-direction: column;
191
+ justify-content: center;
192
+ align-items: center;
193
+ }
194
+ </style>
src/frontend/shared/InteractiveVideoSlider.svelte ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component provides the user interface for uploading two videos side-by-side.
4
+ It acts as the "input" mode for the main VideoSlider component. It uses two
5
+ instances of the InteractiveVideo component to handle the individual uploads.
6
+ -->
7
+ <script lang="ts">
8
+ import { createEventDispatcher } from "svelte";
9
+ import type { FileData, Client } from "@gradio/client";
10
+ import type { I18nFormatter } from "@gradio/utils";
11
+ import type { WebcamOptions } from "./utils";
12
+
13
+ import InteractiveVideo from "./InteractiveVideo.svelte";
14
+ import { BlockLabel } from "@gradio/atoms";
15
+ import { Video as VideoIcon } from "@gradio/icons";
16
+
17
+ // ------------------
18
+ // Props
19
+ // ------------------
20
+ /** The core value: a tuple containing the two uploaded video files. */
21
+ export let value: [FileData | null, FileData | null] = [null, null];
22
+ export let label: string | undefined = undefined;
23
+ export let show_label: boolean;
24
+ export let root: string;
25
+ export let i18n: I18nFormatter;
26
+ export let max_file_size: number | null = null;
27
+ export let upload: Client["upload"];
28
+ export let stream_handler: Client["stream"];
29
+ export let autoplay: boolean;
30
+ export let loop: boolean;
31
+
32
+ const dispatch = createEventDispatcher<{
33
+ upload: [FileData | null, FileData | null];
34
+ clear: void;
35
+ error: string;
36
+ }>();
37
+
38
+ /** Default options for webcam recording, passed down to the child component. */
39
+ const webcam_options: WebcamOptions = {
40
+ mirror: true,
41
+ constraints: {}
42
+ };
43
+
44
+ /**
45
+ * Handles the 'change' event from either of the child InteractiveVideo components.
46
+ * It updates the correct slot in the `value` tuple and dispatches an event.
47
+ * @param detail The new FileData object from the child component.
48
+ * @param slot The index (0 for left, 1 for right) of the video that changed.
49
+ */
50
+ function handle_change(
51
+ detail: FileData | null,
52
+ slot: 0 | 1
53
+ ): void {
54
+ const new_value: [FileData | null, FileData | null] = [...value];
55
+ new_value[slot] = detail;
56
+ value = new_value;
57
+
58
+ if (value[0] === null && value[1] === null) {
59
+ dispatch("clear");
60
+ } else {
61
+ dispatch("upload", new_value);
62
+ }
63
+ }
64
+ </script>
65
+
66
+ <BlockLabel {show_label} Icon={VideoIcon} label={label || "Video Slider"} />
67
+
68
+ <div class="container" data-testid="video-slider-input">
69
+ <!-- Left Video Slot -->
70
+ <div class="video-slot">
71
+ <InteractiveVideo
72
+ value={value[0]}
73
+ on:change={({ detail }) => handle_change(detail, 0)}
74
+ sources={["upload"]}
75
+ active_source="upload"
76
+ {root}
77
+ {upload}
78
+ {stream_handler}
79
+ {i18n}
80
+ {max_file_size}
81
+ show_label={false}
82
+ {webcam_options}
83
+ {autoplay}
84
+ {loop}
85
+ include_audio={true}
86
+ >
87
+ <!-- This text is displayed inside the upload box. -->
88
+ <p class="upload-text">Upload Video 1</p>
89
+ </InteractiveVideo>
90
+ </div>
91
+
92
+ <!-- Right Video Slot -->
93
+ <div class="video-slot">
94
+ <InteractiveVideo
95
+ value={value[1]}
96
+ on:change={({ detail }) => handle_change(detail, 1)}
97
+ sources={["upload"]}
98
+ active_source="upload"
99
+ {root}
100
+ {upload}
101
+ {stream_handler}
102
+ {i18n}
103
+ {max_file_size}
104
+ show_label={false}
105
+ {webcam_options}
106
+ {autoplay}
107
+ {loop}
108
+ include_audio={true}
109
+ >
110
+ <p class="upload-text">Upload Video 2</p>
111
+ </InteractiveVideo>
112
+ </div>
113
+ </div>
114
+
115
+ <style>
116
+ .container {
117
+ display: flex;
118
+ flex-direction: row;
119
+ gap: var(--spacing-lg);
120
+ width: 100%;
121
+ height: 100%;
122
+ }
123
+ .video-slot {
124
+ flex: 1;
125
+ display: flex;
126
+ justify-content: center;
127
+ align-items: center;
128
+ min-height: var(--size-60);
129
+ border: 1px solid var(--border-color-primary);
130
+ border-radius: var(--radius-lg);
131
+ overflow: hidden;
132
+ position: relative;
133
+ }
134
+ /* Use :global to style the slotted content passed to the child component. */
135
+ :global(.video-slot .upload-text) {
136
+ color: var(--body-text-color-subdued);
137
+ text-align: center;
138
+ }
139
+ </style>
src/frontend/shared/Player.svelte ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component is a self-contained video player. It wraps the base <Video>
4
+ component and adds a custom control bar for play/pause, timeline scrubbing,
5
+ and fullscreen. It also integrates with VideoControls for editing features.
6
+ -->
7
+ <script lang="ts">
8
+ import { createEventDispatcher } from "svelte";
9
+ import { Play, Pause, Maximise, Undo } from "@gradio/icons";
10
+ import Video from "./Video.svelte";
11
+ import VideoControls from "./VideoControls.svelte";
12
+ import type { FileData, Client } from "@gradio/client";
13
+ import { prepare_files } from "@gradio/client";
14
+ import { format_time } from "@gradio/utils";
15
+ import type { I18nFormatter } from "@gradio/utils";
16
+
17
+ // ------------------
18
+ // Props
19
+ // ------------------
20
+ export let root = "";
21
+ export let src: string;
22
+ export let subtitle: string | null = null;
23
+ export let mirror: boolean;
24
+ export let loop: boolean;
25
+ export let muted = false;
26
+ export let label = "test";
27
+ /** If true, shows editing controls like trim. */
28
+ export let interactive = false;
29
+ export let handle_change: (video: FileData) => void = () => {};
30
+ export let handle_reset_value: () => void = () => {};
31
+ export let upload: Client["upload"];
32
+ export let is_stream: boolean | undefined;
33
+ export let i18n: I18nFormatter;
34
+ export let show_download_button = false;
35
+ export let value: FileData | null = null;
36
+ export let handle_clear: () => void = () => {};
37
+ export let has_change_history = false;
38
+
39
+ const dispatch = createEventDispatcher<{
40
+ play: undefined;
41
+ pause: undefined;
42
+ stop: undefined;
43
+ end: undefined;
44
+ clear: undefined;
45
+ loadeddata: undefined;
46
+ }>();
47
+
48
+ // -----------------
49
+ // Internal State
50
+ // -----------------
51
+ /** The current playback time of the video, in seconds. */
52
+ let time = 0;
53
+ /** The total duration of the video, in seconds. */
54
+ let duration: number;
55
+ /** The paused state of the video. */
56
+ let paused = true;
57
+ /** A direct reference to the underlying HTML <video> element. */
58
+ let video: HTMLVideoElement;
59
+ /** A prop to export the video element reference to parent components. */
60
+ export let video_el: HTMLVideoElement;
61
+ /** A flag to show a loading state during video processing (e.g., trimming). */
62
+ let processingVideo = false;
63
+
64
+ // -----------------
65
+ // Event Handlers
66
+ // -----------------
67
+
68
+ /** Handles scrubbing the video timeline with a mouse or touch drag. */
69
+ function handleMove(e: TouchEvent | MouseEvent): void {
70
+ if (!duration) return;
71
+
72
+ if (e.type === "click") {
73
+ handle_click(e as MouseEvent);
74
+ return;
75
+ }
76
+
77
+ if (e.type !== "touchmove" && !((e as MouseEvent).buttons & 1)) return;
78
+
79
+ const clientX =
80
+ e.type === "touchmove"
81
+ ? (e as TouchEvent).touches[0].clientX
82
+ : (e as MouseEvent).clientX;
83
+ const { left, right } = (
84
+ e.currentTarget as HTMLProgressElement
85
+ ).getBoundingClientRect();
86
+ time = (duration * (clientX - left)) / (right - left);
87
+ }
88
+
89
+ /** Toggles the video between playing and paused states. */
90
+ async function play_pause(): Promise<void> {
91
+ if (document.fullscreenElement != video) {
92
+ const isPlaying =
93
+ video.currentTime > 0 &&
94
+ !video.paused &&
95
+ !video.ended &&
96
+ video.readyState > video.HAVE_CURRENT_DATA;
97
+
98
+ if (!isPlaying) {
99
+ await video.play();
100
+ } else video.pause();
101
+ }
102
+ }
103
+
104
+ /** Handles a single click on the progress bar to seek to a specific time. */
105
+ function handle_click(e: MouseEvent): void {
106
+ const { left, right } = (
107
+ e.currentTarget as HTMLProgressElement
108
+ ).getBoundingClientRect();
109
+ time = (duration * (e.clientX - left)) / (right - left);
110
+ }
111
+
112
+ /** Dispatches events when the video playback ends. */
113
+ function handle_end(): void {
114
+ dispatch("stop");
115
+ dispatch("end");
116
+ }
117
+
118
+ /** Handles the video trimming process. */
119
+ const handle_trim_video = async (videoBlob: Blob): Promise<void> => {
120
+ let _video_blob = new File([videoBlob], "video.mp4");
121
+ const val = await prepare_files([_video_blob]);
122
+ let value = ((await upload(val, root))?.filter(Boolean) as FileData[])[0];
123
+
124
+ handle_change(value);
125
+ };
126
+
127
+ /** Enters fullscreen mode for the video. */
128
+ function open_full_screen(): void {
129
+ video.requestFullscreen();
130
+ }
131
+
132
+ // -----------------
133
+ // Reactive Logic
134
+ // -----------------
135
+ /** Ensures `time` and `duration` are never NaN. */
136
+ $: time = time || 0;
137
+ $: duration = duration || 0;
138
+ /** Passes the internal video element reference to the exported prop. */
139
+ $: video_el = video;
140
+ </script>
141
+
142
+ <div class="wrap">
143
+ <div class="mirror-wrap" class:mirror>
144
+ <Video
145
+ {src}
146
+ preload="auto"
147
+ {loop}
148
+ {muted}
149
+ {is_stream}
150
+ on:click={play_pause}
151
+ on:play={() => dispatch("play")}
152
+ on:pause={() => dispatch("pause")}
153
+ on:loadeddata={() => dispatch("loadeddata")}
154
+ on:error
155
+ on:ended={handle_end}
156
+ bind:currentTime={time}
157
+ bind:duration
158
+ bind:paused
159
+ bind:node={video}
160
+ data-testid={`${label}-player`}
161
+ {processingVideo}
162
+ >
163
+ <track kind="captions" src={subtitle} default />
164
+ </Video>
165
+
166
+ </div>
167
+
168
+ <!-- The custom video controls overlay -->
169
+ <div class="controls">
170
+ <div class="inner">
171
+ <span
172
+ role="button"
173
+ tabindex="0"
174
+ class="icon"
175
+ aria-label="play-pause-replay-button"
176
+ on:click={play_pause}
177
+ on:keydown={play_pause}
178
+ >
179
+ {#if time === duration}
180
+ <Undo />
181
+ {:else if paused}
182
+ <Play />
183
+ {:else}
184
+ <Pause />
185
+ {/if}
186
+ </span>
187
+
188
+ <span class="time">{format_time(time)} / {format_time(duration)}</span>
189
+
190
+ <progress
191
+ value={time / duration || 0}
192
+ on:mousemove={handleMove}
193
+ on:touchmove|preventDefault={handleMove}
194
+ on:click|stopPropagation|preventDefault={handle_click}
195
+ />
196
+
197
+ <div
198
+ role="button"
199
+ tabindex="0"
200
+ class="icon"
201
+ aria-label="full-screen"
202
+ on:click={open_full_screen}
203
+ on:keypress={open_full_screen}
204
+ >
205
+ <Maximise />
206
+ </div>
207
+ </div>
208
+ </div>
209
+ </div>
210
+
211
+ <!-- If in interactive mode, show the additional editing controls below the player. -->
212
+ {#if interactive}
213
+ <VideoControls
214
+ videoElement={video}
215
+ showRedo
216
+ {handle_trim_video}
217
+ {handle_reset_value}
218
+ bind:processingVideo
219
+ {value}
220
+ {i18n}
221
+ {show_download_button}
222
+ {handle_clear}
223
+ {has_change_history}
224
+ />
225
+ {/if}
226
+
227
+ <style lang="postcss">
228
+ span {
229
+ text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
230
+ }
231
+
232
+ progress {
233
+ margin-right: var(--size-3);
234
+ border-radius: var(--radius-sm);
235
+ width: var(--size-full);
236
+ height: var(--size-2);
237
+ }
238
+
239
+ progress::-webkit-progress-bar {
240
+ border-radius: 2px;
241
+ background-color: rgba(255, 255, 255, 0.2);
242
+ overflow: hidden;
243
+ }
244
+
245
+ progress::-webkit-progress-value {
246
+ background-color: rgba(255, 255, 255, 0.9);
247
+ }
248
+
249
+ .mirror {
250
+ transform: scaleX(-1);
251
+ }
252
+
253
+ .mirror-wrap {
254
+ position: relative;
255
+ height: 100%;
256
+ width: 100%;
257
+ }
258
+
259
+ .controls {
260
+ position: absolute;
261
+ bottom: 0;
262
+ opacity: 0;
263
+ transition: 500ms;
264
+ margin: var(--size-2);
265
+ border-radius: var(--radius-md);
266
+ background: var(--color-grey-800);
267
+ padding: var(--size-2) var(--size-1);
268
+ width: calc(100% - var(--size-2) * 2);
269
+ }
270
+ .wrap:hover .controls {
271
+ opacity: 1;
272
+ }
273
+
274
+ .inner {
275
+ display: flex;
276
+ justify-content: space-between;
277
+ align-items: center;
278
+ padding-right: var(--size-2);
279
+ padding-left: var(--size-2);
280
+ width: var(--size-full);
281
+ height: var(--size-full);
282
+ }
283
+
284
+ .icon {
285
+ display: flex;
286
+ justify-content: center;
287
+ cursor: pointer;
288
+ width: var(--size-6);
289
+ color: white;
290
+ }
291
+
292
+ .time {
293
+ flex-shrink: 0;
294
+ margin-right: var(--size-3);
295
+ margin-left: var(--size-3);
296
+ color: white;
297
+ font-size: var(--text-sm);
298
+ font-family: var(--font-mono);
299
+ }
300
+ .wrap {
301
+ position: relative;
302
+ background-color: var(--background-fill-secondary);
303
+ height: var(--size-full);
304
+ width: var(--size-full);
305
+ border-radius: var(--radius-xl);
306
+ }
307
+ .wrap :global(video) {
308
+ height: var(--size-full);
309
+ width: var(--size-full);
310
+ }
311
+ </style>
src/frontend/shared/Slider.svelte ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ A general-purpose draggable slider component that can be laid over other content.
4
+ It uses d3-drag for robust drag handling and is designed to differentiate
5
+ between a "drag" action and a "click" action.
6
+ -->
7
+ <script lang="ts">
8
+ import { onMount, createEventDispatcher } from "svelte";
9
+ import { drag } from "d3-drag";
10
+ import { select } from "d3-selection";
11
+
12
+ /** A utility function to constrain a value within a minimum and maximum range. */
13
+ function clamp(value: number, min: number, max: number): number {
14
+ return Math.min(Math.max(value, min), max);
15
+ }
16
+
17
+ // ------------------
18
+ // Props
19
+ // ------------------
20
+ /** The slider's position as a normalized value (0 to 1). Can be two-way bound. */
21
+ export let position = 0.5;
22
+ /** If true, disables all dragging and interaction. */
23
+ export let disabled = false;
24
+ /** The color of the vertical slider line. */
25
+ export let slider_color = "var(--border-color-primary)";
26
+ /** Layout-related props, typically bound from the parent, used for calculating pixel positions. */
27
+ export let image_size: {
28
+ top: number;
29
+ left: number;
30
+ width: number;
31
+ height: number;
32
+ } = { top: 0, left: 0, width: 0, height: 0 };
33
+ export let el: HTMLDivElement | undefined = undefined;
34
+ export let parent_el: HTMLDivElement | undefined = undefined;
35
+
36
+ /** Dispatches a 'click' event ONLY if the user clicks the handle without dragging. */
37
+ const dispatch = createEventDispatcher<{ click: MouseEvent }>();
38
+
39
+ // -----------------
40
+ // Internal State
41
+ // -----------------
42
+ let inner: Element;
43
+ /** The slider's horizontal position in pixels. */
44
+ let px = 0;
45
+ /** True while the user is actively dragging the handle. */
46
+ let active = false;
47
+ let container_width = 0;
48
+
49
+ let drag_start_x: number;
50
+ /** A flag to determine if a drag action actually moved, differentiating it from a simple click. */
51
+ let was_dragged = false;
52
+
53
+ // -----------------
54
+ // Functions
55
+ // -----------------
56
+
57
+ /** Calculates the slider's pixel position based on its container's dimensions. */
58
+ function set_position(width: number): void {
59
+ container_width = parent_el?.getBoundingClientRect().width || 0;
60
+ if (width === 0) {
61
+ image_size.width = el?.getBoundingClientRect().width || 0;
62
+ }
63
+ px = clamp(
64
+ image_size.width * position + image_size.left,
65
+ 0,
66
+ container_width
67
+ );
68
+ }
69
+
70
+ function round(n: number, points: number): number {
71
+ const mod = Math.pow(10, points);
72
+ return Math.round((n + Number.EPSILON) * mod) / mod;
73
+ }
74
+
75
+ /** Updates the internal state based on the drag's x-coordinate. */
76
+ function update_position(x: number): void {
77
+ px = clamp(x, 0, container_width);
78
+ position = round((x - image_size.left) / image_size.width, 5);
79
+ }
80
+
81
+ // --- D3 Drag Event Handlers ---
82
+
83
+ function drag_start(event: any): void {
84
+ if (disabled) return;
85
+ active = true;
86
+ update_position(event.x);
87
+ drag_start_x = event.x;
88
+ was_dragged = false;
89
+ }
90
+
91
+ function drag_move(event: any): void {
92
+ if (disabled) return;
93
+ update_position(event.x);
94
+ if (Math.abs(event.x - drag_start_x) > 3) {
95
+ was_dragged = true;
96
+ }
97
+ }
98
+
99
+ function drag_end(event: any): void {
100
+ if (disabled) return;
101
+ active = false;
102
+ if (!was_dragged) {
103
+ dispatch("click", event.sourceEvent);
104
+ }
105
+ }
106
+
107
+ /** Updates the pixel position when the `position` prop changes from the parent. */
108
+ function update_position_from_pc(pc: number): void {
109
+ px = clamp(image_size.width * pc + image_size.left, 0, container_width);
110
+ }
111
+
112
+ // -----------------
113
+ // Lifecycle & Reactive Logic
114
+ // -----------------
115
+ $: set_position(image_size.width);
116
+ $: update_position_from_pc(position);
117
+
118
+ onMount(() => {
119
+ set_position(image_size.width);
120
+ const drag_handler = drag()
121
+ .on("start", drag_start)
122
+ .on("drag", drag_move)
123
+ .on("end", drag_end);
124
+ select(inner).call(drag_handler);
125
+ });
126
+ </script>
127
+
128
+ <!-- Recalculate position on window resize. -->
129
+ <svelte:window on:resize={() => set_position(image_size.width)} />
130
+
131
+ <div class="wrap" role="none" bind:this={parent_el}>
132
+ <!-- The content from the parent component is placed here. -->
133
+ <div class="content" bind:this={el}>
134
+ <slot />
135
+ </div>
136
+
137
+ <!-- This is the draggable handle area. -->
138
+ <div
139
+ class="outer"
140
+ class:disabled
141
+ bind:this={inner}
142
+ role="none"
143
+ style="transform: translateX({px}px)"
144
+ class:grab={active}
145
+ on:click={(event) => event.stopPropagation()}
146
+ >
147
+ <span class="icon-wrap" class:active class:disabled>
148
+ <span class="icon left">◢</span>
149
+ <span class="icon center" style:--color={slider_color}></span>
150
+ <span class="icon right">◢</span>
151
+ </span>
152
+ <!-- This is the visible vertical line of the slider. -->
153
+ <div class="inner" style:--color={slider_color}></div>
154
+ </div>
155
+ </div>
156
+
157
+ <style>
158
+ .wrap {
159
+ position: relative;
160
+ width: 100%;
161
+ height: 100%;
162
+ z-index: var(--layer-1);
163
+ overflow: hidden;
164
+ }
165
+
166
+ .icon-wrap {
167
+ display: block;
168
+ position: absolute;
169
+ top: 50%;
170
+ transform: translate(-20.5px, -50%);
171
+ left: 10px;
172
+ width: 40px;
173
+ transition: 0.2s;
174
+ color: var(--body-text-color);
175
+ height: 30px;
176
+ border-radius: 5px;
177
+ background-color: var(--color-accent);
178
+ display: flex;
179
+ align-items: center;
180
+ justify-content: center;
181
+ z-index: var(--layer-3);
182
+ box-shadow: 0px 0px 5px 2px rgba(0, 0, 0, 0.3);
183
+ font-size: 12px;
184
+ }
185
+
186
+ .icon.left {
187
+ transform: rotate(135deg);
188
+ text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
189
+ }
190
+
191
+ .icon.right {
192
+ transform: rotate(-45deg);
193
+ text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
194
+ }
195
+
196
+ .icon.center {
197
+ display: block;
198
+ width: 1px;
199
+ height: 100%;
200
+ background-color: var(--color);
201
+ opacity: 0.1;
202
+ }
203
+
204
+ .icon-wrap.active {
205
+ opacity: 0;
206
+ }
207
+
208
+ .icon-wrap.disabled {
209
+ opacity: 0;
210
+ }
211
+
212
+ .outer {
213
+ width: 20px;
214
+ height: 100%;
215
+ position: absolute;
216
+ cursor: grab;
217
+ top: 0;
218
+ left: -10px;
219
+ pointer-events: auto;
220
+ z-index: var(--layer-2);
221
+ }
222
+ .grab {
223
+ cursor: grabbing;
224
+ }
225
+
226
+ .inner {
227
+ width: 1px;
228
+ height: 100%;
229
+ background: var(--color);
230
+ position: absolute;
231
+ left: calc((100% - 2px) / 2);
232
+ }
233
+
234
+ .disabled {
235
+ cursor: auto;
236
+ }
237
+
238
+ .disabled .inner {
239
+ box-shadow: none;
240
+ }
241
+
242
+ .content {
243
+ width: 100%;
244
+ height: 100%;
245
+ display: flex;
246
+ justify-content: center;
247
+ align-items: center;
248
+ }
249
+ </style>
src/frontend/shared/Video.svelte ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This is the foundational video component, a wrapper around the native HTML `<video>` tag.
4
+ It adds advanced functionality like HLS streaming support and compatibility with
5
+ Gradio's WebAssembly (Wasm) environment. It also forwards native video events
6
+ to parent components.
7
+ -->
8
+ <svelte:options accessors={true} />
9
+
10
+ <script lang="ts">
11
+ import type { HTMLVideoAttributes } from "svelte/elements";
12
+ import { createEventDispatcher } from "svelte";
13
+ import { loaded } from "./utils";
14
+
15
+ import { resolve_wasm_src } from "@gradio/wasm/svelte";
16
+
17
+ import Hls from "hls.js";
18
+
19
+ // ------------------
20
+ // Props
21
+ // ------------------
22
+
23
+ // --- Standard Video Attributes ---
24
+ export let src: HTMLVideoAttributes["src"] = undefined;
25
+ export let muted: HTMLVideoAttributes["muted"] = undefined;
26
+ export let playsinline: HTMLVideoAttributes["playsinline"] = undefined;
27
+ export let preload: HTMLVideoAttributes["preload"] = undefined;
28
+ export let autoplay: HTMLVideoAttributes["autoplay"] = undefined;
29
+ export let controls: HTMLVideoAttributes["controls"] = undefined;
30
+ export let loop: boolean;
31
+
32
+ // --- Two-way Bound State ---
33
+ export let currentTime: number | undefined = undefined;
34
+ export let duration: number | undefined = undefined;
35
+ export let paused: boolean | undefined = undefined;
36
+
37
+ // --- Specialized Props ---
38
+ /** A direct reference to the underlying HTML <video> element. */
39
+ export let node: HTMLVideoElement | undefined = undefined;
40
+ /** If true, the source is an HLS stream and will be handled by hls.js. */
41
+ export let is_stream;
42
+ /** If true, displays a loading overlay on the video. */
43
+ export let processingVideo = false;
44
+
45
+ // -----------------
46
+ // Internal State
47
+ // -----------------
48
+ let resolved_src: typeof src;
49
+ let stream_active = false;
50
+
51
+ // This block handles resolving video sources in a WebAssembly (Wasm) environment.
52
+ // It prevents UI flickering by showing the original `src` immediately while the
53
+ // Wasm-compatible source is being resolved asynchronously.
54
+ let latest_src: typeof src;
55
+ $: {
56
+ resolved_src = src;
57
+ latest_src = src;
58
+ const resolving_src = src;
59
+ resolve_wasm_src(resolving_src).then((s) => {
60
+ if (latest_src === resolving_src) {
61
+ resolved_src = s;
62
+ }
63
+ });
64
+ }
65
+
66
+ const dispatch = createEventDispatcher();
67
+
68
+ /**
69
+ * Initializes and attaches an HLS.js player to the video element for streaming.
70
+ * This is only triggered when the `is_stream` prop is true.
71
+ * @param src The URL of the HLS manifest (.m3u8 file).
72
+ * @param is_stream A flag to enable or disable this functionality.
73
+ * @param node The HTML video element to attach the stream to.
74
+ */
75
+ function load_stream(
76
+ src: string | null | undefined,
77
+ is_stream: boolean,
78
+ node: HTMLVideoElement
79
+ ): void {
80
+ if (!src || !is_stream) return;
81
+
82
+ if (Hls.isSupported() && !stream_active) {
83
+ const hls = new Hls({
84
+ // Low-latency configuration
85
+ maxBufferLength: 1,
86
+ maxMaxBufferLength: 1,
87
+ lowLatencyMode: true
88
+ });
89
+ hls.loadSource(src);
90
+ hls.attachMedia(node);
91
+ hls.on(Hls.Events.MANIFEST_PARSED, function () {
92
+ (node as HTMLVideoElement).play();
93
+ });
94
+ hls.on(Hls.Events.ERROR, function (event, data) {
95
+ if (data.fatal) {
96
+ switch (data.type) {
97
+ case Hls.ErrorTypes.NETWORK_ERROR:
98
+ hls.startLoad();
99
+ break;
100
+ case Hls.ErrorTypes.MEDIA_ERROR:
101
+ hls.recoverMediaError();
102
+ break;
103
+ default:
104
+ hls.destroy();
105
+ break;
106
+ }
107
+ }
108
+ });
109
+ stream_active = true;
110
+ }
111
+ }
112
+
113
+ /** Reset the HLS stream when the video source changes. */
114
+ $: src, (stream_active = false);
115
+
116
+ /** Trigger the HLS stream loader if the source is a stream. */
117
+ $: if (node && src && is_stream) {
118
+ load_stream(src, is_stream, node);
119
+ }
120
+ </script>
121
+
122
+ <!--
123
+ A necessary comment explaining a Svelte-specific quirk:
124
+ The spread operator with `$$props` or `$$restProps` can't be used here
125
+ to pass props from the parent component to the <video> element
126
+ because of its unexpected behavior: https://github.com/sveltejs/svelte/issues/7404
127
+ -->
128
+ <div class:hidden={!processingVideo} class="overlay">
129
+ <span class="load-wrap">
130
+ <span class="loader" />
131
+ </span>
132
+ </div>
133
+ <video
134
+ src={resolved_src}
135
+ {muted}
136
+ {playsinline}
137
+ {preload}
138
+ {autoplay}
139
+ {controls}
140
+ {loop}
141
+
142
+
143
+ on:loadeddata={dispatch.bind(null, "loadeddata")}
144
+ on:click={dispatch.bind(null, "click")}
145
+ on:play={dispatch.bind(null, "play")}
146
+ on:pause={dispatch.bind(null, "pause")}
147
+ on:ended={dispatch.bind(null, "ended")}
148
+ on:error={dispatch.bind(null, "error", "Video not playable")}
149
+
150
+
151
+ bind:currentTime
152
+ bind:duration
153
+ bind:paused
154
+ bind:this={node}
155
+
156
+
157
+ use:loaded={{ autoplay: autoplay ?? false }}
158
+
159
+ data-testid={$$props["data-testid"]}
160
+ crossorigin="anonymous"
161
+ >
162
+ <slot />
163
+ </video>
164
+
165
+ <style>
166
+ .overlay {
167
+ position: absolute;
168
+ background-color: rgba(0, 0, 0, 0.4);
169
+ width: 100%;
170
+ height: 100%;
171
+ }
172
+
173
+ .hidden {
174
+ display: none;
175
+ }
176
+
177
+ .load-wrap {
178
+ display: flex;
179
+ justify-content: center;
180
+ align-items: center;
181
+ height: 100%;
182
+ }
183
+
184
+ .loader {
185
+ display: flex;
186
+ position: relative;
187
+ background-color: var(--border-color-accent-subdued);
188
+ animation: shadowPulse 2s linear infinite;
189
+ box-shadow:
190
+ -24px 0 var(--border-color-accent-subdued),
191
+ 24px 0 var(--border-color-accent-subdued);
192
+ margin: var(--spacing-md);
193
+ border-radius: 50%;
194
+ width: 10px;
195
+ height: 10px;
196
+ scale: 0.5;
197
+ }
198
+
199
+ @keyframes shadowPulse {
200
+ 33% {
201
+ box-shadow:
202
+ -24px 0 var(--border-color-accent-subdued),
203
+ 24px 0 #fff;
204
+ background: #fff;
205
+ }
206
+ 66% {
207
+ box-shadow:
208
+ -24px 0 #fff,
209
+ 24px 0 #fff;
210
+ background: var(--border-color-accent-subdued);
211
+ }
212
+ 100% {
213
+ box-shadow:
214
+ -24px 0 #fff,
215
+ 24px 0 var(--border-color-accent-subdued);
216
+ background: #fff;
217
+ }
218
+ }
219
+ </style>
src/frontend/shared/VideoControls.svelte ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component provides editing controls for a video, such as trimming.
4
+ It appears below the main player when in `interactive` mode. It uses FFmpeg
5
+ (loaded in the browser via WebAssembly) to perform the trimming operation.
6
+ -->
7
+ <script lang="ts">
8
+ import { Undo, Trim, Clear } from "@gradio/icons";
9
+ import VideoTimeline from "./VideoTimeline.svelte";
10
+ import { trimVideo } from "./utils";
11
+ import { FFmpeg } from "@ffmpeg/ffmpeg";
12
+ import loadFfmpeg from "./utils";
13
+ import { onMount } from "svelte";
14
+ import { format_time } from "@gradio/utils";
15
+ import { IconButton } from "@gradio/atoms";
16
+ import { ModifyUpload } from "@gradio/upload";
17
+ import type { FileData } from "@gradio/client";
18
+
19
+ // ------------------
20
+ // Props
21
+ // ------------------
22
+ /** A direct reference to the HTML <video> element to be controlled. */
23
+ export let videoElement: HTMLVideoElement;
24
+ /** If true, shows the 'Undo' button. */
25
+ export let showRedo = false;
26
+ export let interactive = true;
27
+ /** The current editing mode (e.g., 'edit' for trimming). */
28
+ export let mode = "";
29
+ /** A callback function to reset the video to its original state. */
30
+ export let handle_reset_value: () => void;
31
+ /** A callback function to handle the new, trimmed video blob. */
32
+ export let handle_trim_video: (videoBlob: Blob) => void;
33
+ /** Two-way bound prop to indicate if the video is currently being processed by FFmpeg. */
34
+ export let processingVideo = false;
35
+ export let i18n: (key: string) => string;
36
+ export let value: FileData | null = null;
37
+ export let show_download_button = false;
38
+ export let handle_clear: () => void = () => {};
39
+ /** True if the video has a previous state to revert to. */
40
+ export let has_change_history = false;
41
+
42
+ // -----------------
43
+ // Internal State
44
+ // -----------------
45
+ /** The FFmpeg instance. */
46
+ let ffmpeg: FFmpeg;
47
+ /** The duration of the selected trim region. */
48
+ let trimmedDuration: number | null = null;
49
+ /** The start time of the trim, in seconds. */
50
+ let dragStart = 0;
51
+ /** The end time of the trim, in seconds. */
52
+ let dragEnd = 0;
53
+ /** A flag to show a loading state while the timeline generates thumbnails. */
54
+ let loadingTimeline = false;
55
+
56
+ /** Load the FFmpeg library when the component is first mounted. */
57
+ onMount(async () => {
58
+ ffmpeg = await loadFfmpeg();
59
+ });
60
+
61
+ /** When entering edit mode, initialize the trimmed duration to the full video duration. */
62
+ $: if (mode === "edit" && trimmedDuration === null && videoElement)
63
+ trimmedDuration = videoElement.duration;
64
+
65
+ /** Toggles the video trimming UI on and off. */
66
+ const toggleTrimmingMode = (): void => {
67
+ if (mode === "edit") {
68
+ mode = "";
69
+ trimmedDuration = videoElement.duration;
70
+ } else {
71
+ mode = "edit";
72
+ }
73
+ };
74
+ </script>
75
+
76
+ <!-- The trimming UI, which is only visible when mode is 'edit'. -->
77
+ <div class="container" class:hidden={mode !== "edit"}>
78
+ {#if mode === "edit"}
79
+ <div class="timeline-wrapper">
80
+ <VideoTimeline
81
+ {videoElement}
82
+ bind:dragStart
83
+ bind:dragEnd
84
+ bind:trimmedDuration
85
+ bind:loadingTimeline
86
+ />
87
+ </div>
88
+ {/if}
89
+
90
+ <div class="controls" data-testid="waveform-controls">
91
+ {#if mode === "edit" && trimmedDuration !== null}
92
+ <time
93
+ aria-label="duration of selected region in seconds"
94
+ class:hidden={loadingTimeline}>{format_time(trimmedDuration)}</time
95
+ >
96
+ <div class="edit-buttons">
97
+ <button
98
+ class:hidden={loadingTimeline}
99
+ class="text-button"
100
+ on:click={() => {
101
+ mode = "";
102
+ processingVideo = true;
103
+ trimVideo(ffmpeg, dragStart, dragEnd, videoElement)
104
+ .then((videoBlob) => {
105
+ handle_trim_video(videoBlob);
106
+ })
107
+ .then(() => {
108
+ processingVideo = false;
109
+ });
110
+ }}>Trim</button
111
+ >
112
+ <button
113
+ class="text-button"
114
+ class:hidden={loadingTimeline}
115
+ on:click={toggleTrimmingMode}>Cancel</button
116
+ >
117
+ </div>
118
+ {:else}
119
+ <div />
120
+ {/if}
121
+ </div>
122
+ </div>
123
+
124
+ <!-- Standard controls like Clear, Download, Undo, and Trim. -->
125
+ <ModifyUpload
126
+ {i18n}
127
+ on:clear={() => handle_clear()}
128
+ download={show_download_button ? value?.url : null}
129
+ >
130
+ {#if showRedo && mode === ""}
131
+ <IconButton
132
+ Icon={Undo}
133
+ label="Reset video to initial value"
134
+ disabled={processingVideo || !has_change_history}
135
+ on:click={() => {
136
+ handle_reset_value();
137
+ mode = "";
138
+ }}
139
+ />
140
+ {/if}
141
+
142
+ {#if interactive && mode === ""}
143
+ <IconButton
144
+ Icon={Trim}
145
+ label="Trim video to selection"
146
+ disabled={processingVideo}
147
+ on:click={toggleTrimmingMode}
148
+ />
149
+ {/if}
150
+ </ModifyUpload>
151
+
152
+ <style>
153
+ .container {
154
+ width: 100%;
155
+ }
156
+ time {
157
+ color: var(--color-accent);
158
+ font-weight: bold;
159
+ padding-left: var(--spacing-xs);
160
+ }
161
+
162
+ .timeline-wrapper {
163
+ display: flex;
164
+ align-items: center;
165
+ justify-content: center;
166
+ width: 100%;
167
+ }
168
+
169
+ .text-button {
170
+ border: 1px solid var(--neutral-400);
171
+ border-radius: var(--radius-sm);
172
+ font-weight: 300;
173
+ font-size: var(--size-3);
174
+ text-align: center;
175
+ color: var(--neutral-400);
176
+ height: var(--size-5);
177
+ font-weight: bold;
178
+ padding: 0 5px;
179
+ margin-left: 5px;
180
+ }
181
+
182
+ .text-button:hover,
183
+ .text-button:focus {
184
+ color: var(--color-accent);
185
+ border-color: var(--color-accent);
186
+ }
187
+
188
+ .controls {
189
+ display: flex;
190
+ justify-content: space-between;
191
+ align-items: center;
192
+ margin: var(--spacing-lg);
193
+ overflow: hidden;
194
+ }
195
+
196
+ .edit-buttons {
197
+ display: flex;
198
+ gap: var(--spacing-sm);
199
+ }
200
+
201
+ @media (max-width: 320px) {
202
+ .controls {
203
+ flex-direction: column;
204
+ align-items: flex-start;
205
+ }
206
+
207
+ .edit-buttons {
208
+ margin-top: var(--spacing-sm);
209
+ }
210
+
211
+ .controls * {
212
+ margin: var(--spacing-sm);
213
+ }
214
+
215
+ .controls .text-button {
216
+ margin-left: 0;
217
+ }
218
+ }
219
+
220
+ .container {
221
+ display: flex;
222
+ flex-direction: column;
223
+ }
224
+
225
+ .hidden {
226
+ display: none;
227
+ }
228
+ </style>
src/frontend/shared/VideoSliderPreview.svelte ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component provides the display-only view for the VideoSlider. It shows two
4
+ videos side-by-side, with a draggable slider to reveal one over the other. It
5
+ also handles synchronized play/pause functionality for both videos.
6
+ -->
7
+ <script lang="ts">
8
+ import { createEventDispatcher } from "svelte";
9
+ import type { FileData, Client } from "@gradio/client";
10
+ import type { I18nFormatter } from "@gradio/utils";
11
+
12
+ import Slider from "./Slider.svelte";
13
+ import Player from "./Player.svelte";
14
+
15
+ import { BlockLabel, Empty, IconButton, IconButtonWrapper, FullscreenButton } from "@gradio/atoms";
16
+ import { Video as VideoIcon, Download, Clear } from "@gradio/icons";
17
+ import { DownloadLink } from "@gradio/wasm/svelte";
18
+
19
+ // ------------------
20
+ // Props
21
+ // ------------------
22
+ export let value: [FileData | null, FileData | null] = [null, null];
23
+ export let label: string | undefined = undefined;
24
+ export let show_download_button = true;
25
+ export let show_label: boolean;
26
+ export let i18n: I18nFormatter;
27
+ /** The normalized (0-1) position of the slider. */
28
+ export let position: number;
29
+ export let slider_color: string;
30
+ export let show_fullscreen_button = true;
31
+ export let fullscreen = false;
32
+ export let interactive = true;
33
+ export let autoplay = false;
34
+ export let loop = false;
35
+ export let upload: Client["upload"];
36
+
37
+ const dispatch = createEventDispatcher<{ clear: void }>();
38
+
39
+ // -----------------
40
+ // Internal State
41
+ // -----------------
42
+ /** A direct reference to the master HTML <video> element. */
43
+ let video1_el: HTMLVideoElement;
44
+ /** A direct reference to the slave HTML <video> element. */
45
+ let video2_el: HTMLVideoElement;
46
+
47
+ /** A flag that becomes true once the master video has loaded its data. */
48
+ let video_is_ready = false;
49
+ /** A flag to ensure the initial autoplay logic runs only once. */
50
+ let initial_autoplay_done = false;
51
+
52
+ /** A reactive CSS style to create the "reveal" effect based on the slider's position. */
53
+ $: style = `clip-path: inset(0 0 0 ${position * 100}%)`;
54
+
55
+ // -----------------
56
+ // Event Handlers
57
+ // -----------------
58
+
59
+ /** Sets a flag to true when the master video signals it's ready to play. */
60
+ function handle_video_ready(): void {
61
+ video_is_ready = true;
62
+ }
63
+
64
+ /** Toggles play/pause for both videos simultaneously when the user interacts. */
65
+ function toggle_playback(): void {
66
+ if (!video1_el || !video2_el) {
67
+ return;
68
+ }
69
+
70
+ const is_paused = video1_el.paused;
71
+
72
+ if (is_paused) {
73
+ video1_el.play().catch(() => {});
74
+ video2_el.play().catch(() => {});
75
+ } else {
76
+ video1_el.pause();
77
+ video2_el.pause();
78
+ }
79
+ }
80
+
81
+ // -----------------
82
+ // Reactive Logic
83
+ // -----------------
84
+ $: {
85
+ // This block handles initial autoplay once all conditions are met, preventing race conditions.
86
+ if (video1_el && video_is_ready && autoplay && !initial_autoplay_done) {
87
+ video1_el.play().catch(() => {});
88
+ initial_autoplay_done = true;
89
+ }
90
+
91
+ // This block continuously synchronizes the slave video to the master video.
92
+ if (video1_el && video2_el) {
93
+ // Sync playback time.
94
+ if (Math.abs(video1_el.currentTime - video2_el.currentTime) > 0.1) {
95
+ video2_el.currentTime = video1_el.currentTime;
96
+ }
97
+
98
+ // Sync play/pause state.
99
+ if (video1_el.paused !== video2_el.paused) {
100
+ if (video1_el.paused) {
101
+ video2_el.pause();
102
+ } else {
103
+ video2_el.play().catch(() => {});
104
+ }
105
+ }
106
+ }
107
+ }
108
+ </script>
109
+
110
+ <BlockLabel {show_label} Icon={VideoIcon} label={label || "Video Slider"} />
111
+
112
+ <!-- Show an empty state if no videos are provided. -->
113
+ {#if value === null || value[0] === null || value[1] === null}
114
+ <Empty unpadded_box={true} size="large"><VideoIcon /></Empty>
115
+ {:else}
116
+ <div class="video-container">
117
+ <IconButtonWrapper>
118
+ {#if show_fullscreen_button}
119
+ <FullscreenButton {fullscreen} on:fullscreen />
120
+ {/if}
121
+
122
+ {#if show_download_button && value[1]}
123
+ <DownloadLink href={value[1].meta?._base64 || value[1].url} download={value[1].orig_name || "video"}>
124
+ <IconButton Icon={Download} label={i18n("common.download")} />
125
+ </DownloadLink>
126
+ {/if}
127
+
128
+ {#if interactive}
129
+ <IconButton
130
+ Icon={Clear}
131
+ label="Remove Videos"
132
+ on:click={(event) => {
133
+ value = [null, null];
134
+ dispatch("clear");
135
+ event.stopPropagation();
136
+ }}
137
+ />
138
+ {/if}
139
+ </IconButtonWrapper>
140
+
141
+ <!-- This main wrapper handles clicks for the entire area and makes it accessible. -->
142
+ <div
143
+ class="main-wrapper"
144
+ on:click={toggle_playback}
145
+ on:keydown={(event) => {
146
+ if (event.key === 'Enter' || event.key === ' ') {
147
+ toggle_playback();
148
+ }
149
+ }}
150
+ role="button"
151
+ tabindex="0"
152
+ >
153
+ <!-- The first (bottom) video player. -->
154
+ <div class="player-wrapper">
155
+ {#if value[0]}
156
+ <Player
157
+ src={value[0].meta?._base64 || value[0].url}
158
+ bind:video_el={video1_el}
159
+ on:loadeddata={handle_video_ready}
160
+ {loop}
161
+ muted={true}
162
+ {i18n}
163
+ {upload}
164
+ mirror={false}
165
+ is_stream={value[0].is_stream}
166
+ interactive={false}
167
+ />
168
+ {/if}
169
+ </div>
170
+
171
+ <!-- The second (top, clipped) video player. -->
172
+ <div class="player-wrapper fixed" {style}>
173
+ {#if value[1]}
174
+ <Player
175
+ src={value[1].meta?._base64 || value[1].url}
176
+ bind:video_el={video2_el}
177
+ {loop}
178
+ muted={true}
179
+ {i18n}
180
+ {upload}
181
+ mirror={false}
182
+ is_stream={value[1].is_stream}
183
+ interactive={false}
184
+ />
185
+ {/if}
186
+ </div>
187
+
188
+ <!-- The slider is an overlay for dragging, but does not handle clicks. -->
189
+ <Slider
190
+ bind:position
191
+ {slider_color}
192
+ />
193
+ </div>
194
+ </div>
195
+ {/if}
196
+
197
+ <style>
198
+ .video-container {
199
+ height: 100%;
200
+ width: 100%;
201
+ position: relative;
202
+ display: flex;
203
+ align-items: center;
204
+ justify-content: center;
205
+ overflow: hidden;
206
+ }
207
+
208
+ .main-wrapper {
209
+ position: relative;
210
+ width: 100%;
211
+ height: 100%;
212
+ cursor: pointer;
213
+ }
214
+
215
+ .player-wrapper {
216
+ position: absolute;
217
+ top: 0;
218
+ left: 0;
219
+ width: 100%;
220
+ height: 100%;
221
+ }
222
+
223
+ .player-wrapper.fixed {
224
+ background: var(--block-background-fill);
225
+ }
226
+
227
+ /* Ensure the Slider component is layered on top of the video players. */
228
+ :global(.main-wrapper > .wrap) {
229
+ position: absolute;
230
+ top: 0;
231
+ left: 0;
232
+ z-index: 10;
233
+ cursor: default;
234
+ }
235
+ </style>
src/frontend/shared/VideoTimeline.svelte ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ @component
3
+ This component displays a visual timeline of a video, composed of generated
4
+ thumbnails. It features draggable start and end handles, allowing a user to
5
+ select a specific segment of the video for trimming.
6
+ -->
7
+ <script lang="ts">
8
+ import { onMount, onDestroy } from "svelte";
9
+
10
+ // ------------------
11
+ // Props
12
+ // ------------------
13
+ /** A direct reference to the HTML <video> element to be analyzed. */
14
+ export let videoElement: HTMLVideoElement;
15
+ /** The calculated duration of the selected trim region (two-way bound). */
16
+ export let trimmedDuration: number | null;
17
+ /** The start time of the selection in seconds (two-way bound). */
18
+ export let dragStart: number;
19
+ /** The end time of the selection in seconds (two-way bound). */
20
+ export let dragEnd: number;
21
+ /** A flag indicating if the timeline is currently being generated (two-way bound). */
22
+ export let loadingTimeline: boolean;
23
+
24
+ // -----------------
25
+ // Internal State
26
+ // -----------------
27
+ /** An array of base64-encoded thumbnail images. */
28
+ let thumbnails: string[] = [];
29
+ let numberOfThumbnails = 10;
30
+ let videoDuration: number;
31
+
32
+ /** The percentage-based position of the left and right drag handles. */
33
+ let leftHandlePosition = 0;
34
+ let rightHandlePosition = 100;
35
+
36
+ /** The currently active drag handle ('left', 'right', or null). */
37
+ let dragging: string | null = null;
38
+
39
+ // -----------------
40
+ // Functions
41
+ // -----------------
42
+
43
+ const startDragging = (side: string | null): void => {
44
+ dragging = side;
45
+ };
46
+
47
+ const stopDragging = (): void => {
48
+ dragging = null;
49
+ };
50
+
51
+ /**
52
+ * Handles the movement of a drag handle, updating its position and the
53
+ * corresponding video playback time.
54
+ * @param event The mouse event.
55
+ * @param distance Optional distance for keyboard-based movement.
56
+ */
57
+ const drag = (event: { clientX: number }, distance?: number): void => {
58
+ if (dragging) {
59
+ const timeline = document.getElementById("timeline");
60
+ if (!timeline) return;
61
+
62
+ const rect = timeline.getBoundingClientRect();
63
+ let newPercentage: number;
64
+
65
+ if (distance) {
66
+ // Move handle based on arrow key press.
67
+ newPercentage =
68
+ dragging === "left"
69
+ ? leftHandlePosition + distance
70
+ : rightHandlePosition + distance;
71
+ } else {
72
+ // Move handle based on mouse drag.
73
+ newPercentage = ((event.clientX - rect.left) / rect.width) * 100;
74
+ }
75
+
76
+ newPercentage = Math.max(0, Math.min(newPercentage, 100));
77
+
78
+ if (dragging === "left") {
79
+ leftHandlePosition = Math.min(newPercentage, rightHandlePosition);
80
+ const newTimeLeft = (leftHandlePosition / 100) * videoDuration;
81
+ videoElement.currentTime = newTimeLeft; // Seek video to new start time
82
+ dragStart = newTimeLeft;
83
+ } else if (dragging === "right") {
84
+ rightHandlePosition = Math.max(newPercentage, leftHandlePosition);
85
+ const newTimeRight = (rightHandlePosition / 100) * videoDuration;
86
+ videoElement.currentTime = newTimeRight; // Seek video to new end time
87
+ dragEnd = newTimeRight;
88
+ }
89
+
90
+ const startTime = (leftHandlePosition / 100) * videoDuration;
91
+ const endTime = (rightHandlePosition / 100) * videoDuration;
92
+ trimmedDuration = endTime - startTime;
93
+ }
94
+ };
95
+
96
+ /** Handles moving the drag handles with the arrow keys for accessibility. */
97
+ const moveHandle = (e: KeyboardEvent): void => {
98
+ if (dragging) {
99
+ const distance = (1 / videoDuration) * 100;
100
+
101
+ if (e.key === "ArrowLeft") {
102
+ drag({ clientX: 0 }, -distance);
103
+ } else if (e.key === "ArrowRight") {
104
+ drag({ clientX: 0 }, distance);
105
+ }
106
+ }
107
+ };
108
+
109
+ /** Generates a single thumbnail by drawing the current video frame to a canvas. */
110
+ const generateThumbnail = (): void => {
111
+ const canvas = document.createElement("canvas");
112
+ const ctx = canvas.getContext("2d");
113
+ if (!ctx) return;
114
+
115
+ canvas.width = videoElement.videoWidth;
116
+ canvas.height = videoElement.videoHeight;
117
+ ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
118
+
119
+ const thumbnail: string = canvas.toDataURL("image/jpeg", 0.7);
120
+ thumbnails = [...thumbnails, thumbnail];
121
+ };
122
+
123
+ // -----------------
124
+ // Lifecycle
125
+ // -----------------
126
+
127
+ /** A reactive statement that updates the loading state based on thumbnail generation. */
128
+ $: loadingTimeline = thumbnails.length !== numberOfThumbnails;
129
+
130
+ onMount(() => {
131
+ /**
132
+ * Orchestrates the thumbnail generation process by seeking the video to
133
+ * different time points and capturing a frame at each point.
134
+ */
135
+ const loadMetadata = (): void => {
136
+ videoDuration = videoElement.duration;
137
+ dragEnd = videoDuration;
138
+ const interval = videoDuration / numberOfThumbnails;
139
+ let captures = 0;
140
+
141
+ const onSeeked = (): void => {
142
+ generateThumbnail();
143
+ captures++;
144
+
145
+ if (captures < numberOfThumbnails) {
146
+ videoElement.currentTime += interval;
147
+ } else {
148
+ videoElement.removeEventListener("seeked", onSeeked);
149
+ }
150
+ };
151
+
152
+ videoElement.addEventListener("seeked", onSeeked);
153
+ videoElement.currentTime = 0; // Start the seeking process
154
+ };
155
+
156
+ // Wait for the video's metadata to be loaded before starting.
157
+ if (videoElement.readyState >= 1) {
158
+ loadMetadata();
159
+ } else {
160
+ videoElement.addEventListener("loadedmetadata", loadMetadata);
161
+ }
162
+
163
+ // Add global event listeners for dragging.
164
+ window.addEventListener("mousemove", drag);
165
+ window.addEventListener("mouseup", stopDragging);
166
+ window.addEventListener("keydown", moveHandle);
167
+ });
168
+
169
+ onDestroy(() => {
170
+ // Clean up global event listeners to prevent memory leaks.
171
+ window.removeEventListener("mousemove", drag);
172
+ window.removeEventListener("mouseup", stopDragging);
173
+ window.removeEventListener("keydown", moveHandle);
174
+ });
175
+ </script>
176
+
177
+ <div class="container">
178
+ <!-- Show a loader while thumbnails are being generated. -->
179
+ {#if loadingTimeline}
180
+ <div class="load-wrap">
181
+ <span aria-label="loading timeline" class="loader" />
182
+ </div>
183
+ <!-- Once loaded, display the timeline. -->
184
+ {:else}
185
+ <div id="timeline" class="thumbnail-wrapper">
186
+ <!-- The left (start) drag handle. -->
187
+ <button
188
+ aria-label="start drag handle for trimming video"
189
+ class="handle left"
190
+ on:mousedown={() => startDragging("left")}
191
+ on:blur={stopDragging}
192
+ on:keydown={(e) => {
193
+ if (e.key === 'ArrowLeft' || e.key == 'ArrowRight') {
194
+ startDragging("left");
195
+ }
196
+ }}
197
+ style="left: {leftHandlePosition}%;"
198
+ />
199
+
200
+ <!-- The colored overlay indicating the selected region. -->
201
+ <div
202
+ class="opaque-layer"
203
+ style="left: {leftHandlePosition}%; right: {100 - rightHandlePosition}%"
204
+ />
205
+
206
+ <!-- The generated video frame thumbnails. -->
207
+ {#each thumbnails as thumbnail, i (i)}
208
+ <img src={thumbnail} alt={`frame-${i}`} draggable="false" />
209
+ {/each}
210
+
211
+ <!-- The right (end) drag handle. -->
212
+ <button
213
+ aria-label="end drag handle for trimming video"
214
+ class="handle right"
215
+ on:mousedown={() => startDragging("right")}
216
+ on:blur={stopDragging}
217
+ on:keydown={(e) => {
218
+ if (e.key === 'ArrowLeft' || e.key == 'ArrowRight') {
219
+ startDragging("right");
220
+ }
221
+ }}
222
+ style="left: {rightHandlePosition}%;"
223
+ />
224
+ </div>
225
+ {/if}
226
+ </div>
227
+
228
+ <style>
229
+ .load-wrap {
230
+ display: flex;
231
+ justify-content: center;
232
+ align-items: center;
233
+ height: 100%;
234
+ }
235
+ .loader {
236
+ display: flex;
237
+ position: relative;
238
+ background-color: var(--border-color-accent-subdued);
239
+ animation: shadowPulse 2s linear infinite;
240
+ box-shadow:
241
+ -24px 0 var(--border-color-accent-subdued),
242
+ 24px 0 var(--border-color-accent-subdued);
243
+ margin: var(--spacing-md);
244
+ border-radius: 50%;
245
+ width: 10px;
246
+ height: 10px;
247
+ scale: 0.5;
248
+ }
249
+
250
+ @keyframes shadowPulse {
251
+ 33% {
252
+ box-shadow:
253
+ -24px 0 var(--border-color-accent-subdued),
254
+ 24px 0 #fff;
255
+ background: #fff;
256
+ }
257
+ 66% {
258
+ box-shadow:
259
+ -24px 0 #fff,
260
+ 24px 0 #fff;
261
+ background: var(--border-color-accent-subdued);
262
+ }
263
+ 100% {
264
+ box-shadow:
265
+ -24px 0 #fff,
266
+ 24px 0 var(--border-color-accent-subdued);
267
+ background: #fff;
268
+ }
269
+ }
270
+
271
+ .container {
272
+ display: flex;
273
+ flex-direction: column;
274
+ align-items: center;
275
+ justify-content: center;
276
+ margin: var(--spacing-lg) var(--spacing-lg) 0 var(--spacing-lg);
277
+ }
278
+
279
+ #timeline {
280
+ display: flex;
281
+ height: var(--size-10);
282
+ flex: 1;
283
+ position: relative;
284
+ }
285
+
286
+ img {
287
+ flex: 1 1 auto;
288
+ min-width: 0;
289
+ object-fit: cover;
290
+ height: var(--size-12);
291
+ border: 1px solid var(--block-border-color);
292
+ user-select: none;
293
+ z-index: 1;
294
+ }
295
+
296
+ .handle {
297
+ width: 3px;
298
+ background-color: var(--color-accent);
299
+ cursor: ew-resize;
300
+ height: var(--size-12);
301
+ z-index: 3;
302
+ position: absolute;
303
+ }
304
+
305
+ .opaque-layer {
306
+ background-color: rgba(230, 103, 40, 0.25);
307
+ border: 1px solid var(--color-accent);
308
+ height: var(--size-12);
309
+ position: absolute;
310
+ z-index: 2;
311
+ }
312
+ </style>
src/frontend/shared/utils.ts ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toBlobURL } from "@ffmpeg/util";
2
+ import { FFmpeg } from "@ffmpeg/ffmpeg";
3
+ import { lookup } from "mrmime";
4
+
5
+ export const prettyBytes = (bytes: number): string => {
6
+ let units = ["B", "KB", "MB", "GB", "PB"];
7
+ let i = 0;
8
+ while (bytes > 1024) {
9
+ bytes /= 1024;
10
+ i++;
11
+ }
12
+ let unit = units[i];
13
+ return bytes.toFixed(1) + " " + unit;
14
+ };
15
+
16
+ export const playable = (): boolean => {
17
+ // TODO: Fix this
18
+ // let video_element = document.createElement("video");
19
+ // let mime_type = mime.lookup(filename);
20
+ // return video_element.canPlayType(mime_type) != "";
21
+ return true; // FIX BEFORE COMMIT - mime import causing issues
22
+ };
23
+
24
+ export function loaded(
25
+ node: HTMLVideoElement,
26
+ { autoplay }: { autoplay: boolean }
27
+ ): any {
28
+ async function handle_playback(): Promise<void> {
29
+ if (!autoplay) return;
30
+ await node.play();
31
+ }
32
+
33
+ node.addEventListener("loadeddata", handle_playback);
34
+
35
+ return {
36
+ destroy(): void {
37
+ node.removeEventListener("loadeddata", handle_playback);
38
+ }
39
+ };
40
+ }
41
+
42
+ export default async function loadFfmpeg(): Promise<FFmpeg> {
43
+ const ffmpeg = new FFmpeg();
44
+ const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm";
45
+
46
+ await ffmpeg.load({
47
+ coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
48
+ wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, "application/wasm")
49
+ });
50
+
51
+ return ffmpeg;
52
+ }
53
+
54
+ export function blob_to_data_url(blob: Blob): Promise<string> {
55
+ return new Promise((fulfill, reject) => {
56
+ let reader = new FileReader();
57
+ reader.onerror = reject;
58
+ reader.onload = () => fulfill(reader.result as string);
59
+ reader.readAsDataURL(blob);
60
+ });
61
+ }
62
+
63
+ export async function trimVideo(
64
+ ffmpeg: FFmpeg,
65
+ startTime: number,
66
+ endTime: number,
67
+ videoElement: HTMLVideoElement
68
+ ): Promise<any> {
69
+ const videoUrl = videoElement.src;
70
+ const mimeType = lookup(videoElement.src) || "video/mp4";
71
+ const blobUrl = await toBlobURL(videoUrl, mimeType);
72
+ const response = await fetch(blobUrl);
73
+ const vidBlob = await response.blob();
74
+ const type = getVideoExtensionFromMimeType(mimeType) || "mp4";
75
+ const inputName = `input.${type}`;
76
+ const outputName = `output.${type}`;
77
+
78
+ try {
79
+ if (startTime === 0 && endTime === 0) {
80
+ return vidBlob;
81
+ }
82
+
83
+ await ffmpeg.writeFile(
84
+ inputName,
85
+ new Uint8Array(await vidBlob.arrayBuffer())
86
+ );
87
+
88
+ let command = [
89
+ "-i",
90
+ inputName,
91
+ ...(startTime !== 0 ? ["-ss", startTime.toString()] : []),
92
+ ...(endTime !== 0 ? ["-to", endTime.toString()] : []),
93
+ "-c:a",
94
+ "copy",
95
+ outputName
96
+ ];
97
+
98
+ await ffmpeg.exec(command);
99
+ const outputData = await ffmpeg.readFile(outputName);
100
+ const outputBlob = new Blob([outputData], {
101
+ type: `video/${type}`
102
+ });
103
+
104
+ return outputBlob;
105
+ } catch (error) {
106
+ console.error("Error initializing FFmpeg:", error);
107
+ return vidBlob;
108
+ }
109
+ }
110
+
111
+ const getVideoExtensionFromMimeType = (mimeType: string): string | null => {
112
+ const videoMimeToExtensionMap: { [key: string]: string } = {
113
+ "video/mp4": "mp4",
114
+ "video/webm": "webm",
115
+ "video/ogg": "ogv",
116
+ "video/quicktime": "mov",
117
+ "video/x-msvideo": "avi",
118
+ "video/x-matroska": "mkv",
119
+ "video/mpeg": "mpeg",
120
+ "video/3gpp": "3gp",
121
+ "video/3gpp2": "3g2",
122
+ "video/h261": "h261",
123
+ "video/h263": "h263",
124
+ "video/h264": "h264",
125
+ "video/jpeg": "jpgv",
126
+ "video/jpm": "jpm",
127
+ "video/mj2": "mj2",
128
+ "video/mpv": "mpv",
129
+ "video/vnd.ms-playready.media.pyv": "pyv",
130
+ "video/vnd.uvvu.mp4": "uvu",
131
+ "video/vnd.vivo": "viv",
132
+ "video/x-f4v": "f4v",
133
+ "video/x-fli": "fli",
134
+ "video/x-flv": "flv",
135
+ "video/x-m4v": "m4v",
136
+ "video/x-ms-asf": "asf",
137
+ "video/x-ms-wm": "wm",
138
+ "video/x-ms-wmv": "wmv",
139
+ "video/x-ms-wmx": "wmx",
140
+ "video/x-ms-wvx": "wvx",
141
+ "video/x-sgi-movie": "movie",
142
+ "video/x-smv": "smv"
143
+ };
144
+
145
+ return videoMimeToExtensionMap[mimeType] || null;
146
+ };
147
+
148
+ export interface WebcamOptions {
149
+ mirror: boolean;
150
+ constraints: Record<string, any>;
151
+ }
src/frontend/tsconfig.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "resolveJsonModule": true,
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "strict": true,
11
+ "verbatimModuleSyntax": true
12
+ },
13
+ "exclude": ["node_modules", "dist", "./gradio.config.js"]
14
+ }
src/pyproject.toml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = [
3
+ "hatchling",
4
+ "hatch-requirements-txt",
5
+ "hatch-fancy-pypi-readme>=22.5.0",
6
+ ]
7
+ build-backend = "hatchling.build"
8
+
9
+ [project]
10
+ name = "gradio_videoslider"
11
+ version = "0.0.1"
12
+ description = "VideoSlider Component for Gradio"
13
+ readme = "README.md"
14
+ license = "apache-2.0"
15
+ requires-python = ">=3.10"
16
+ authors = [{ name = "YOUR NAME", email = "[email protected]" }]
17
+ keywords = ["gradio-custom-component", "gradio-template-ImageSlider"]
18
+ # Add dependencies here
19
+ dependencies = ["gradio>=4.0,<6.0"]
20
+ classifiers = [
21
+ 'Development Status :: 3 - Alpha',
22
+ 'Operating System :: OS Independent',
23
+ 'Programming Language :: Python :: 3',
24
+ 'Programming Language :: Python :: 3 :: Only',
25
+ 'Programming Language :: Python :: 3.8',
26
+ 'Programming Language :: Python :: 3.9',
27
+ 'Programming Language :: Python :: 3.10',
28
+ 'Programming Language :: Python :: 3.11',
29
+ 'Topic :: Scientific/Engineering',
30
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
31
+ 'Topic :: Scientific/Engineering :: Visualization',
32
+ ]
33
+
34
+ # The repository and space URLs are optional, but recommended.
35
+ # Adding a repository URL will create a badge in the auto-generated README that links to the repository.
36
+ # Adding a space URL will create a badge in the auto-generated README that links to the space.
37
+ # This will make it easy for people to find your deployed demo or source code when they
38
+ # encounter your project in the wild.
39
+
40
+ # [project.urls]
41
+ # repository = "your github repository"
42
+ # space = "your space url"
43
+
44
+ [project.optional-dependencies]
45
+ dev = ["build", "twine"]
46
+
47
+ [tool.hatch.build]
48
+ artifacts = ["/backend/gradio_videoslider/templates", "*.pyi", "/\\backend\\gradio_videoslider\\templates"]
49
+
50
+ [tool.hatch.build.targets.wheel]
51
+ packages = ["/backend/gradio_videoslider"]