Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import subprocess
|
2 |
import re
|
3 |
from typing import List, Tuple, Optional
|
4 |
-
|
5 |
|
6 |
# Define the command to be executed
|
7 |
command = ["python", "setup.py", "build_ext", "--inplace"]
|
@@ -9,26 +9,6 @@ command = ["python", "setup.py", "build_ext", "--inplace"]
|
|
9 |
# Execute the command
|
10 |
result = subprocess.run(command, capture_output=True, text=True)
|
11 |
|
12 |
-
|
13 |
-
def install_cuda_toolkit():
|
14 |
-
# CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
|
15 |
-
CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
|
16 |
-
CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
|
17 |
-
subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
|
18 |
-
subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
|
19 |
-
subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
|
20 |
-
|
21 |
-
os.environ["CUDA_HOME"] = "/usr/local/cuda"
|
22 |
-
os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
|
23 |
-
os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
|
24 |
-
os.environ["CUDA_HOME"],
|
25 |
-
"" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
|
26 |
-
)
|
27 |
-
# Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
|
28 |
-
os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
|
29 |
-
|
30 |
-
install_cuda_toolkit()
|
31 |
-
|
32 |
css="""
|
33 |
div#component-18, div#component-25, div#component-35, div#component-41{
|
34 |
align-items: stretch!important;
|
@@ -333,6 +313,7 @@ def get_mask_sam_process(
|
|
333 |
# return gr.update(visible=True), "output_first_frame.jpg", frame_names, predictor, inference_state, gr.update(choices=available_frames_to_check, value=working_frame, visible=True)
|
334 |
return "output_first_frame.jpg", frame_names, predictor, inference_state, gr.update(choices=available_frames_to_check, value=working_frame, visible=False)
|
335 |
|
|
|
336 |
def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_names, video_frames_dir, vis_frame_type, available_frames_to_check, working_frame, progress=gr.Progress(track_tqdm=True)):
|
337 |
#### PROPAGATION ####
|
338 |
sam2_checkpoint, model_cfg = load_model(checkpoint)
|
@@ -465,9 +446,7 @@ with gr.Blocks(css=css) as demo:
|
|
465 |
gr.Markdown(
|
466 |
"""
|
467 |
### 📋 Instructions:
|
468 |
-
|
469 |
It is largely built on the [SAM2-Video-Predictor](https://huggingface.co/spaces/fffiloni/SAM2-Video-Predictor).
|
470 |
-
|
471 |
1. **Upload your video** [MP4-24fps]
|
472 |
2. With **'include' point type** selected, click on the object to mask on the first frame
|
473 |
3. Switch to **'exclude' point type** if you want to specify an area to avoid
|
@@ -475,7 +454,6 @@ with gr.Blocks(css=css) as demo:
|
|
475 |
5. **Check Propagation** every 15 frames
|
476 |
6. **Propagate with "render"** to render the final masked video
|
477 |
7. **Hit Reset** button if you want to refresh and start again
|
478 |
-
|
479 |
*Note: Input video will be processed for up to 10 seconds only for demo purposes.*
|
480 |
"""
|
481 |
)
|
@@ -631,5 +609,4 @@ with gr.Blocks(css=css) as demo:
|
|
631 |
outputs = [output_propagated, output_video, working_frame, available_frames_to_check, reset_prpgt_brn]
|
632 |
)
|
633 |
|
634 |
-
demo.launch(show_api=False, show_error=True)
|
635 |
-
# demo.queue().launch(show_api=False, show_error=True, share=True, server_name="0.0.0.0", server_port=11111)
|
|
|
1 |
import subprocess
|
2 |
import re
|
3 |
from typing import List, Tuple, Optional
|
4 |
+
import spaces
|
5 |
|
6 |
# Define the command to be executed
|
7 |
command = ["python", "setup.py", "build_ext", "--inplace"]
|
|
|
9 |
# Execute the command
|
10 |
result = subprocess.run(command, capture_output=True, text=True)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
css="""
|
13 |
div#component-18, div#component-25, div#component-35, div#component-41{
|
14 |
align-items: stretch!important;
|
|
|
313 |
# return gr.update(visible=True), "output_first_frame.jpg", frame_names, predictor, inference_state, gr.update(choices=available_frames_to_check, value=working_frame, visible=True)
|
314 |
return "output_first_frame.jpg", frame_names, predictor, inference_state, gr.update(choices=available_frames_to_check, value=working_frame, visible=False)
|
315 |
|
316 |
+
@spaces.GPU(duration=180)
|
317 |
def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_names, video_frames_dir, vis_frame_type, available_frames_to_check, working_frame, progress=gr.Progress(track_tqdm=True)):
|
318 |
#### PROPAGATION ####
|
319 |
sam2_checkpoint, model_cfg = load_model(checkpoint)
|
|
|
446 |
gr.Markdown(
|
447 |
"""
|
448 |
### 📋 Instructions:
|
|
|
449 |
It is largely built on the [SAM2-Video-Predictor](https://huggingface.co/spaces/fffiloni/SAM2-Video-Predictor).
|
|
|
450 |
1. **Upload your video** [MP4-24fps]
|
451 |
2. With **'include' point type** selected, click on the object to mask on the first frame
|
452 |
3. Switch to **'exclude' point type** if you want to specify an area to avoid
|
|
|
454 |
5. **Check Propagation** every 15 frames
|
455 |
6. **Propagate with "render"** to render the final masked video
|
456 |
7. **Hit Reset** button if you want to refresh and start again
|
|
|
457 |
*Note: Input video will be processed for up to 10 seconds only for demo purposes.*
|
458 |
"""
|
459 |
)
|
|
|
609 |
outputs = [output_propagated, output_video, working_frame, available_frames_to_check, reset_prpgt_brn]
|
610 |
)
|
611 |
|
612 |
+
demo.launch(show_api=False, show_error=True)
|
|