Spaces:
Runtime error
Runtime error
Commit
·
cc4e696
1
Parent(s):
45770d1
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,9 @@ import torch
|
|
| 16 |
from tools.painter import mask_painter
|
| 17 |
import psutil
|
| 18 |
import time
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
from mmcv.cnn import ConvModule
|
| 21 |
except:
|
|
@@ -69,7 +72,20 @@ def get_prompt(click_state, click_input):
|
|
| 69 |
}
|
| 70 |
return prompt
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# extract frames from upload video
|
| 75 |
def get_frames_from_video(video_input, video_state):
|
|
@@ -541,7 +557,7 @@ with gr.Blocks() as iface:
|
|
| 541 |
outputs=[video_demo_operation],
|
| 542 |
# cache_examples=True,
|
| 543 |
)
|
| 544 |
-
|
| 545 |
# first step: get the video information
|
| 546 |
extract_frames_button.click(
|
| 547 |
fn=get_frames_from_video,
|
|
|
|
| 16 |
from tools.painter import mask_painter
|
| 17 |
import psutil
|
| 18 |
import time
|
| 19 |
+
import urllib.request
|
| 20 |
+
import tempfile
|
| 21 |
+
|
| 22 |
try:
|
| 23 |
from mmcv.cnn import ConvModule
|
| 24 |
except:
|
|
|
|
| 72 |
}
|
| 73 |
return prompt
|
| 74 |
|
| 75 |
+
def download_video(video_url):
|
| 76 |
+
tmp_dir = tempfile.gettempdir()
|
| 77 |
+
video_path = f"{tmp_dir}/input_video.mp4"
|
| 78 |
+
|
| 79 |
+
urllib.request.urlretrieve(video_url, video_path)
|
| 80 |
+
|
| 81 |
+
return video_path
|
| 82 |
+
|
| 83 |
+
@app.route("/api/process_video")
|
| 84 |
+
def api_process_video(video_url):
|
| 85 |
|
| 86 |
+
video_path = download_video(video_url)
|
| 87 |
+
|
| 88 |
+
return get_frames_from_video(video_path)
|
| 89 |
|
| 90 |
# extract frames from upload video
|
| 91 |
def get_frames_from_video(video_input, video_state):
|
|
|
|
| 557 |
outputs=[video_demo_operation],
|
| 558 |
# cache_examples=True,
|
| 559 |
)
|
| 560 |
+
iface.route("/api/process_video", api_process_video)
|
| 561 |
# first step: get the video information
|
| 562 |
extract_frames_button.click(
|
| 563 |
fn=get_frames_from_video,
|