fffiloni
commited on
Commit
•
ce026c7
0
Parent(s):
Duplicate from nanomenta/sketch_frame_interpolation
Browse files- .gitattributes +27 -0
- README.md +13 -0
- app.py +122 -0
- packages.txt +1 -0
- requirements.txt +14 -0
- style.css +3 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
19 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Sketch Frame Interpolation
|
3 |
+
emoji: 🐠🐠
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.24.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: nanomenta/sketch_frame_interpolation
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
6 |
+
import cv2
|
7 |
+
import numpy as np
|
8 |
+
import tensorflow as tf
|
9 |
+
import mediapy
|
10 |
+
from PIL import Image
|
11 |
+
from eval import interpolator, util
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
from huggingface_hub import snapshot_download
|
15 |
+
|
16 |
+
from image_tools.sizes import resize_and_crop
|
17 |
+
|
18 |
+
|
19 |
+
model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style")
|
20 |
+
|
21 |
+
interpolator = interpolator.Interpolator(model, None)
|
22 |
+
|
23 |
+
ffmpeg_path = util.get_ffmpeg_path()
|
24 |
+
mediapy.set_ffmpeg(ffmpeg_path)
|
25 |
+
|
26 |
+
def resize(width,img):
|
27 |
+
basewidth = width
|
28 |
+
img = Image.open(img)
|
29 |
+
wpercent = (basewidth/float(img.size[0]))
|
30 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
31 |
+
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
|
32 |
+
return img
|
33 |
+
|
34 |
+
|
35 |
+
def resize_img(img1,img2):
|
36 |
+
img_target_size = Image.open(img1)
|
37 |
+
img_to_resize = resize_and_crop(
|
38 |
+
img2,
|
39 |
+
(img_target_size.size[0],img_target_size.size[1]), #set width and height to match img1
|
40 |
+
crop_origin="middle"
|
41 |
+
)
|
42 |
+
img_to_resize.save('resized_img2.png')
|
43 |
+
|
44 |
+
|
45 |
+
sketch1 = gr.Image(image_mode="RGB",
|
46 |
+
source="canvas",
|
47 |
+
tool='color-sketch',
|
48 |
+
type="filepath",
|
49 |
+
shape=None,
|
50 |
+
invert_colors=False)
|
51 |
+
|
52 |
+
sketch2 = gr.Image(image_mode="RGB",
|
53 |
+
source="canvas",
|
54 |
+
tool='color-sketch',
|
55 |
+
type="filepath",
|
56 |
+
shape=None,
|
57 |
+
invert_colors=False)
|
58 |
+
|
59 |
+
slider = gr.inputs.Slider(minimum=2,maximum=4,step=1)
|
60 |
+
|
61 |
+
|
62 |
+
def predict(frame1, frame2, times_to_interpolate):
|
63 |
+
|
64 |
+
frame1 = resize(512,frame1)
|
65 |
+
frame2 = resize(512,frame2)
|
66 |
+
|
67 |
+
frame1.save("test1.png")
|
68 |
+
frame2.save("test2.png")
|
69 |
+
|
70 |
+
resize_img("test1.png","test2.png")
|
71 |
+
input_frames = ["test1.png", "resized_img2.png"]
|
72 |
+
|
73 |
+
frames = list(
|
74 |
+
util.interpolate_recursively_from_files(
|
75 |
+
input_frames, times_to_interpolate, interpolator))
|
76 |
+
print(frames)
|
77 |
+
mediapy.write_video("out.mp4", frames, fps=24)
|
78 |
+
|
79 |
+
# video.mp4 is a video of 9 seconds
|
80 |
+
filename = "out.mp4"
|
81 |
+
|
82 |
+
cap = cv2.VideoCapture(filename)
|
83 |
+
cap.set(cv2.CAP_PROP_POS_AVI_RATIO,0)
|
84 |
+
frameCount = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
85 |
+
frameWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
86 |
+
frameHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
87 |
+
videoFPS = int(cap.get(cv2.CAP_PROP_FPS))
|
88 |
+
|
89 |
+
print (f"frameCount: {frameCount}")
|
90 |
+
print (f"frameWidth: {frameWidth}")
|
91 |
+
print (f"frameHeight: {frameHeight}")
|
92 |
+
print (f"videoFPS: {videoFPS}")
|
93 |
+
|
94 |
+
buf = np.empty((
|
95 |
+
frameCount,
|
96 |
+
frameHeight,
|
97 |
+
frameWidth,
|
98 |
+
3), np.dtype('uint8'))
|
99 |
+
|
100 |
+
fc = 0
|
101 |
+
ret = True
|
102 |
+
|
103 |
+
while (fc < frameCount):
|
104 |
+
ret, buf[fc] = cap.read()
|
105 |
+
fc += 1
|
106 |
+
|
107 |
+
cap.release()
|
108 |
+
videoArray = buf
|
109 |
+
|
110 |
+
print (f"DURATION: {frameCount/videoFPS}")
|
111 |
+
print (videoArray)
|
112 |
+
|
113 |
+
return "out.mp4", videoArray
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
title="sketch-frame-interpolation"
|
118 |
+
description="<p style='text-align: center'>This is a fork of the Gradio demo for FILM: Frame Interpolation for Large Scene Motion from @akhaliq, but using sketches instead of images. This could be very useful for the animation industry :) <br /> To use it, simply draw your sketches and add the times to interpolate number. Read more at the links below. <br /> <img id='visitor-badge' alt='visitor badge' src='https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.sketch_frame_interpolation' style='display: inline-block'/></p>"
|
119 |
+
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>"
|
120 |
+
custom_css = "style.css"
|
121 |
+
|
122 |
+
gr.Interface(predict,[sketch1,sketch2,slider],outputs=[gr.Video(label="video output"),gr.Gallery(label="list of frames output").style(grid=5)],title=title,description=description,article=article,css=custom_css).launch(enable_queue=True)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
tensorflow-datasets
|
3 |
+
tensorflow-addons
|
4 |
+
absl-py
|
5 |
+
gin-config
|
6 |
+
parameterized
|
7 |
+
mediapy
|
8 |
+
opencv-python
|
9 |
+
scikit-image
|
10 |
+
apache-beam
|
11 |
+
google-cloud-bigquery-storage # Suppresses a harmless error from beam
|
12 |
+
natsort
|
13 |
+
image-tools
|
14 |
+
numpy
|
style.css
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.h-60 {
|
2 |
+
height: 35rem;
|
3 |
+
}
|