Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,86 +1,86 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from gradio_videoslider import VideoSlider
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
# --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
|
| 6 |
-
#
|
| 7 |
-
# IMPORTANT: Replace the values below with the paths to YOUR video files.
|
| 8 |
-
#
|
| 9 |
-
# Option A: Relative Path (if the video is in the same folder as this app.py)
|
| 10 |
-
# video_path_1 = "video_before.mp4"
|
| 11 |
-
# video_path_2 = "video_after.mp4"
|
| 12 |
-
#
|
| 13 |
-
# Option B: Absolute Path (the full path to the file on your computer)
|
| 14 |
-
# Example for Windows:
|
| 15 |
-
# video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
|
| 16 |
-
#
|
| 17 |
-
# Example for Linux/macOS:
|
| 18 |
-
# video_path_1 = "/home/yourname/videos/my_video_1.mp4"
|
| 19 |
-
|
| 20 |
-
# Set your file paths here:
|
| 21 |
-
video_path_1 = "examples/SampleVideo 720x480.mp4"
|
| 22 |
-
video_path_2 = "examples/SampleVideo 1280x720.mp4"
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# --- 2. FUNCTION FOR THE UPLOAD EXAMPLE ---
|
| 26 |
-
def process_uploaded_videos(video_inputs):
|
| 27 |
-
"""This function handles the uploaded videos."""
|
| 28 |
-
print("Received videos from upload:", video_inputs)
|
| 29 |
-
return video_inputs
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# --- 3. GRADIO INTERFACE ---
|
| 33 |
-
with gr.Blocks() as demo:
|
| 34 |
-
gr.Markdown("# Video Slider Component Usage Examples")
|
| 35 |
-
gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
|
| 36 |
-
|
| 37 |
-
with gr.Tabs():
|
| 38 |
-
# --- TAB 1: UPLOAD EXAMPLE ---
|
| 39 |
-
with gr.TabItem("1. Compare via Upload"):
|
| 40 |
-
gr.Markdown("## Upload two videos to compare them side-by-side.")
|
| 41 |
-
video_slider_input = VideoSlider(label="Your Videos", height=400, width=700, video_mode="upload")
|
| 42 |
-
video_slider_output = VideoSlider(
|
| 43 |
-
label="Video comparision",
|
| 44 |
-
interactive=False,
|
| 45 |
-
autoplay=True,
|
| 46 |
-
video_mode="preview",
|
| 47 |
-
show_download_button=False,
|
| 48 |
-
loop=True,
|
| 49 |
-
height=400,
|
| 50 |
-
width=700
|
| 51 |
-
)
|
| 52 |
-
submit_btn = gr.Button("Submit")
|
| 53 |
-
submit_btn.click(
|
| 54 |
-
fn=process_uploaded_videos,
|
| 55 |
-
inputs=[video_slider_input],
|
| 56 |
-
outputs=[video_slider_output]
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
# --- TAB 2: LOCAL FILE EXAMPLE ---
|
| 60 |
-
with gr.TabItem("2. Compare Local Files"):
|
| 61 |
-
gr.Markdown("## Example with videos pre-loaded from your local disk.")
|
| 62 |
-
|
| 63 |
-
# This is the key part: we pass a tuple of your local file paths to the `value` parameter.
|
| 64 |
-
VideoSlider(
|
| 65 |
-
label="Video comparision",
|
| 66 |
-
value=(video_path_1, video_path_2),
|
| 67 |
-
interactive=False,
|
| 68 |
-
show_download_button=False,
|
| 69 |
-
autoplay=True,
|
| 70 |
-
video_mode="preview",
|
| 71 |
-
loop=True,
|
| 72 |
-
height=400,
|
| 73 |
-
width=700
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
# A check to give a helpful error message if files are not found.
|
| 77 |
-
if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
|
| 78 |
-
print("---")
|
| 79 |
-
print(f"WARNING: Could not find one or both video files.")
|
| 80 |
-
print(f"Please make sure these paths are correct in your app.py file:")
|
| 81 |
-
print(f" - '{os.path.abspath(video_path_1)}'")
|
| 82 |
-
print(f" - '{os.path.abspath(video_path_2)}'")
|
| 83 |
-
print("---")
|
| 84 |
-
|
| 85 |
-
if __name__ == '__main__':
|
| 86 |
-
demo.launch(debug=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_videoslider import VideoSlider
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# --- 1. DEFINE THE PATHS TO YOUR LOCAL VIDEOS ---
|
| 6 |
+
#
|
| 7 |
+
# IMPORTANT: Replace the values below with the paths to YOUR video files.
|
| 8 |
+
#
|
| 9 |
+
# Option A: Relative Path (if the video is in the same folder as this app.py)
|
| 10 |
+
# video_path_1 = "video_before.mp4"
|
| 11 |
+
# video_path_2 = "video_after.mp4"
|
| 12 |
+
#
|
| 13 |
+
# Option B: Absolute Path (the full path to the file on your computer)
|
| 14 |
+
# Example for Windows:
|
| 15 |
+
# video_path_1 = "C:\\Users\\YourName\\Videos\\my_video_1.mp4"
|
| 16 |
+
#
|
| 17 |
+
# Example for Linux/macOS:
|
| 18 |
+
# video_path_1 = "/home/yourname/videos/my_video_1.mp4"
|
| 19 |
+
|
| 20 |
+
# Set your file paths here:
|
| 21 |
+
video_path_1 = "src/examples/SampleVideo 720x480.mp4"
|
| 22 |
+
video_path_2 = "src/examples/SampleVideo 1280x720.mp4"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# --- 2. FUNCTION FOR THE UPLOAD EXAMPLE ---
|
| 26 |
+
def process_uploaded_videos(video_inputs):
|
| 27 |
+
"""This function handles the uploaded videos."""
|
| 28 |
+
print("Received videos from upload:", video_inputs)
|
| 29 |
+
return video_inputs
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# --- 3. GRADIO INTERFACE ---
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("# Video Slider Component Usage Examples")
|
| 35 |
+
gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_videoslider'>Component GitHub Code</a></span>")
|
| 36 |
+
|
| 37 |
+
with gr.Tabs():
|
| 38 |
+
# --- TAB 1: UPLOAD EXAMPLE ---
|
| 39 |
+
with gr.TabItem("1. Compare via Upload"):
|
| 40 |
+
gr.Markdown("## Upload two videos to compare them side-by-side.")
|
| 41 |
+
video_slider_input = VideoSlider(label="Your Videos", height=400, width=700, video_mode="upload")
|
| 42 |
+
video_slider_output = VideoSlider(
|
| 43 |
+
label="Video comparision",
|
| 44 |
+
interactive=False,
|
| 45 |
+
autoplay=True,
|
| 46 |
+
video_mode="preview",
|
| 47 |
+
show_download_button=False,
|
| 48 |
+
loop=True,
|
| 49 |
+
height=400,
|
| 50 |
+
width=700
|
| 51 |
+
)
|
| 52 |
+
submit_btn = gr.Button("Submit")
|
| 53 |
+
submit_btn.click(
|
| 54 |
+
fn=process_uploaded_videos,
|
| 55 |
+
inputs=[video_slider_input],
|
| 56 |
+
outputs=[video_slider_output]
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# --- TAB 2: LOCAL FILE EXAMPLE ---
|
| 60 |
+
with gr.TabItem("2. Compare Local Files"):
|
| 61 |
+
gr.Markdown("## Example with videos pre-loaded from your local disk.")
|
| 62 |
+
|
| 63 |
+
# This is the key part: we pass a tuple of your local file paths to the `value` parameter.
|
| 64 |
+
VideoSlider(
|
| 65 |
+
label="Video comparision",
|
| 66 |
+
value=(video_path_1, video_path_2),
|
| 67 |
+
interactive=False,
|
| 68 |
+
show_download_button=False,
|
| 69 |
+
autoplay=True,
|
| 70 |
+
video_mode="preview",
|
| 71 |
+
loop=True,
|
| 72 |
+
height=400,
|
| 73 |
+
width=700
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# A check to give a helpful error message if files are not found.
|
| 77 |
+
if not os.path.exists(video_path_1) or not os.path.exists(video_path_2):
|
| 78 |
+
print("---")
|
| 79 |
+
print(f"WARNING: Could not find one or both video files.")
|
| 80 |
+
print(f"Please make sure these paths are correct in your app.py file:")
|
| 81 |
+
print(f" - '{os.path.abspath(video_path_1)}'")
|
| 82 |
+
print(f" - '{os.path.abspath(video_path_2)}'")
|
| 83 |
+
print("---")
|
| 84 |
+
|
| 85 |
+
if __name__ == '__main__':
|
| 86 |
+
demo.launch(debug=True)
|