Spaces:
Runtime error
Runtime error
NimaBoscarino
commited on
Commit
•
eed8d18
1
Parent(s):
3f908f4
Allow choosing choosing from multiple model options
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import os
|
|
|
2 |
os.system("git clone https://github.com/google-research/frame-interpolation")
|
3 |
import sys
|
|
|
4 |
sys.path.append("frame-interpolation")
|
5 |
import numpy as np
|
6 |
import tensorflow as tf
|
@@ -14,51 +16,83 @@ from huggingface_hub import snapshot_download
|
|
14 |
from image_tools.sizes import resize_and_crop
|
15 |
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
ffmpeg_path = util.get_ffmpeg_path()
|
22 |
mediapy.set_ffmpeg(ffmpeg_path)
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
|
47 |
frame1.save("test1.png")
|
48 |
frame2.save("test2.png")
|
49 |
|
50 |
-
resize_img("test1.png","test2.png")
|
51 |
input_frames = ["test1.png", "resized_img2.png"]
|
52 |
|
53 |
frames = list(
|
54 |
util.interpolate_recursively_from_files(
|
55 |
-
input_frames, times_to_interpolate,
|
56 |
|
57 |
mediapy.write_video("out.mp4", frames, fps=30)
|
58 |
return "out.mp4"
|
59 |
|
60 |
-
|
61 |
-
|
|
|
62 |
article = "<p style='text-align: center'><a href='https://film-net.github.io/' target='_blank'>FILM: Frame Interpolation for Large Motion</a> | <a href='https://github.com/google-research/frame-interpolation' target='_blank'>Github Repo</a></p>"
|
63 |
-
examples=[
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
|
3 |
os.system("git clone https://github.com/google-research/frame-interpolation")
|
4 |
import sys
|
5 |
+
|
6 |
sys.path.append("frame-interpolation")
|
7 |
import numpy as np
|
8 |
import tensorflow as tf
|
|
|
16 |
from image_tools.sizes import resize_and_crop
|
17 |
|
18 |
|
19 |
+
def load_model(model_name):
|
20 |
+
interpolator = interpolator.Interpolator(snapshot_download(repo_id=model_name), None)
|
21 |
+
|
22 |
+
return model
|
23 |
+
|
24 |
|
25 |
+
model_names = [
|
26 |
+
"akhaliq/frame-interpolation-film-style",
|
27 |
+
"akhaliq/frame-interpolation_film_l1",
|
28 |
+
"akhaliq/frame_interpolation_film_vgg",
|
29 |
+
"akhaliq/frame-interpolation-film-imagenet-vgg-verydeep-19"
|
30 |
+
]
|
31 |
+
|
32 |
+
models = {model_name: load_model(model_name) for model_name in model_names}
|
33 |
|
34 |
ffmpeg_path = util.get_ffmpeg_path()
|
35 |
mediapy.set_ffmpeg(ffmpeg_path)
|
36 |
|
37 |
+
|
38 |
+
def resize(width, img):
|
39 |
+
basewidth = width
|
40 |
+
img = Image.open(img)
|
41 |
+
wpercent = (basewidth / float(img.size[0]))
|
42 |
+
hsize = int((float(img.size[1]) * float(wpercent)))
|
43 |
+
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
44 |
+
return img
|
45 |
+
|
46 |
+
|
47 |
+
def resize_img(img1, img2):
|
48 |
+
img_target_size = Image.open(img1)
|
49 |
+
img_to_resize = resize_and_crop(
|
50 |
+
img2,
|
51 |
+
(img_target_size.size[0], img_target_size.size[1]), # set width and height to match img1
|
52 |
+
crop_origin="middle"
|
53 |
+
)
|
54 |
+
img_to_resize.save('resized_img2.png')
|
55 |
+
|
56 |
+
|
57 |
+
def predict(frame1, frame2, times_to_interpolate, model_name):
|
58 |
+
model = models[model_name]
|
59 |
+
|
60 |
+
frame1 = resize(256, frame1)
|
61 |
+
frame2 = resize(256, frame2)
|
62 |
|
63 |
frame1.save("test1.png")
|
64 |
frame2.save("test2.png")
|
65 |
|
66 |
+
resize_img("test1.png", "test2.png")
|
67 |
input_frames = ["test1.png", "resized_img2.png"]
|
68 |
|
69 |
frames = list(
|
70 |
util.interpolate_recursively_from_files(
|
71 |
+
input_frames, times_to_interpolate, model))
|
72 |
|
73 |
mediapy.write_video("out.mp4", frames, fps=30)
|
74 |
return "out.mp4"
|
75 |
|
76 |
+
|
77 |
+
title = "frame-interpolation"
|
78 |
+
description = "Gradio demo for FILM: Frame Interpolation for Large Scene Motion. To use it, simply upload your images and add the times to interpolate number or click on one of the examples to load them. Read more at the links below."
|
79 |
article = "<p style='text-align: center'><a href='https://film-net.github.io/' target='_blank'>FILM: Frame Interpolation for Large Motion</a> | <a href='https://github.com/google-research/frame-interpolation' target='_blank'>Github Repo</a></p>"
|
80 |
+
examples = [
|
81 |
+
['cat3.jpeg', 'cat4.jpeg', 2, model_names[0]],
|
82 |
+
['cat1.jpeg', 'cat2.jpeg', 2, model_names[1]],
|
83 |
+
]
|
84 |
+
|
85 |
+
gr.Interface(
|
86 |
+
predict,
|
87 |
+
[
|
88 |
+
gr.inputs.Image(type='filepath'),
|
89 |
+
gr.inputs.Image(type='filepath'),
|
90 |
+
gr.inputs.Slider(minimum=2, maximum=4, step=1),
|
91 |
+
gr.inputs.Dropdown(choices=model_names, default=model_names[0])
|
92 |
+
],
|
93 |
+
"playable_video",
|
94 |
+
title=title,
|
95 |
+
description=description,
|
96 |
+
article=article,
|
97 |
+
examples=examples
|
98 |
+
).launch(enable_queue=True)
|