Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
-
|
2 |
-
|
3 |
import os
|
4 |
import pathlib
|
5 |
import tempfile
|
6 |
-
|
7 |
import gradio as gr
|
8 |
import torch
|
9 |
from huggingface_hub import snapshot_download
|
@@ -11,24 +9,18 @@ from modelscope.outputs import OutputKeys
|
|
11 |
from modelscope.pipelines import pipeline
|
12 |
|
13 |
DESCRIPTION = "# ModelScope-Image2Video"
|
14 |
-
|
15 |
-
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
16 |
-
|
17 |
-
if torch.cuda.is_available():
|
18 |
-
model_cache_dir = os.getenv("MODEL_CACHE_DIR", "./models")
|
19 |
-
model_dir = pathlib.Path(model_cache_dir) / "MS-Image2Video"
|
20 |
-
snapshot_download(repo_id="damo-vilab/MS-Image2Video", repo_type="model", local_dir=model_dir)
|
21 |
-
pipe = pipeline(task="image-to-video", model=model_dir.as_posix(), model_revision="v1.1.0", device="cuda:0")
|
22 |
-
else:
|
23 |
-
pipe = None
|
24 |
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def image_to_video(image_path: str) -> str:
|
27 |
output_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
28 |
pipe(image_path, output_video=output_file.name)[OutputKeys.OUTPUT_VIDEO]
|
29 |
return output_file.name
|
30 |
|
31 |
-
|
32 |
with gr.Blocks(css="style.css") as demo:
|
33 |
gr.Markdown(DESCRIPTION)
|
34 |
gr.DuplicateButton(
|
@@ -40,7 +32,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
40 |
input_image = gr.Image(label="Input image", type="filepath")
|
41 |
run_button = gr.Button()
|
42 |
output_video = gr.Video(label="Output video")
|
43 |
-
|
44 |
run_button.click(
|
45 |
fn=image_to_video,
|
46 |
inputs=input_image,
|
@@ -49,4 +40,4 @@ with gr.Blocks(css="style.css") as demo:
|
|
49 |
)
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
-
demo.queue(max_size=10).launch()
|
|
|
1 |
+
##!/usr/bin/env python
|
|
|
2 |
import os
|
3 |
import pathlib
|
4 |
import tempfile
|
|
|
5 |
import gradio as gr
|
6 |
import torch
|
7 |
from huggingface_hub import snapshot_download
|
|
|
9 |
from modelscope.pipelines import pipeline
|
10 |
|
11 |
DESCRIPTION = "# ModelScope-Image2Video"
|
12 |
+
DESCRIPTION += "\n<p>Running on CPU. Performance may be slower compared to GPU.</p>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
model_cache_dir = os.getenv("MODEL_CACHE_DIR", "./models")
|
15 |
+
model_dir = pathlib.Path(model_cache_dir) / "MS-Image2Video"
|
16 |
+
snapshot_download(repo_id="damo-vilab/MS-Image2Video", repo_type="model", local_dir=model_dir)
|
17 |
+
pipe = pipeline(task="image-to-video", model=model_dir.as_posix(), model_revision="v1.1.0", device="cpu")
|
18 |
|
19 |
def image_to_video(image_path: str) -> str:
|
20 |
output_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
21 |
pipe(image_path, output_video=output_file.name)[OutputKeys.OUTPUT_VIDEO]
|
22 |
return output_file.name
|
23 |
|
|
|
24 |
with gr.Blocks(css="style.css") as demo:
|
25 |
gr.Markdown(DESCRIPTION)
|
26 |
gr.DuplicateButton(
|
|
|
32 |
input_image = gr.Image(label="Input image", type="filepath")
|
33 |
run_button = gr.Button()
|
34 |
output_video = gr.Video(label="Output video")
|
|
|
35 |
run_button.click(
|
36 |
fn=image_to_video,
|
37 |
inputs=input_image,
|
|
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
+
demo.queue(max_size=10).launch()
|