Spaces:
Build error
Build error
Kazuki Nakayashiki
commited on
Commit
β’
ee43993
1
Parent(s):
ba74a59
Add initial commit
Browse files- README.md +4 -4
- app.py +105 -0
- packages.txt +1 -0
- requirements.txt +16 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title: Images
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.16.1
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
+
title: Images to Video
|
3 |
+
emoji: π
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.16.1
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import io, base64
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
import tensorflow as tf
|
7 |
+
import mediapy
|
8 |
+
import os
|
9 |
+
import sys
|
10 |
+
from huggingface_hub import snapshot_download
|
11 |
+
from image_tools.sizes import resize_and_crop
|
12 |
+
|
13 |
+
os.system("git clone https://github.com/google-research/frame-interpolation")
|
14 |
+
sys.path.append("frame-interpolation")
|
15 |
+
from eval import interpolator, util
|
16 |
+
|
17 |
+
ffmpeg_path = util.get_ffmpeg_path()
|
18 |
+
mediapy.set_ffmpeg(ffmpeg_path)
|
19 |
+
|
20 |
+
model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style")
|
21 |
+
interpolator = interpolator.Interpolator(model, None)
|
22 |
+
|
23 |
+
def resize(width, img):
|
24 |
+
basewidth = width
|
25 |
+
img = Image.open(img)
|
26 |
+
wpercent = (basewidth / float(img.size[0]))
|
27 |
+
hsize = int((float(img.size[1]) * float(wpercent)))
|
28 |
+
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
29 |
+
return img
|
30 |
+
|
31 |
+
def resize_img(img1, img2, output_name):
|
32 |
+
img_target_size = Image.open(img1)
|
33 |
+
img_to_resize = resize_and_crop(
|
34 |
+
img2,
|
35 |
+
(img_target_size.size[0], img_target_size.size[1]),
|
36 |
+
crop_origin="middle"
|
37 |
+
)
|
38 |
+
img_to_resize.save(output_name)
|
39 |
+
|
40 |
+
def generate_interpolation(frame1, frame2, frame3, frame4, frame5, frame6, times_to_interpolate):
|
41 |
+
|
42 |
+
frame1 = resize(256, frame1)
|
43 |
+
frame2 = resize(256, frame2)
|
44 |
+
frame3 = resize(256, frame3)
|
45 |
+
frame4 = resize(256, frame4)
|
46 |
+
frame5 = resize(256, frame5)
|
47 |
+
frame6 = resize(256, frame6)
|
48 |
+
|
49 |
+
frame1.save("test1.png")
|
50 |
+
frame2.save("test2.png")
|
51 |
+
frame3.save("test3.png")
|
52 |
+
frame4.save("test4.png")
|
53 |
+
frame5.save("test5.png")
|
54 |
+
frame6.save("test6.png")
|
55 |
+
|
56 |
+
resize_img("test1.png", "test2.png", "resized_img2.png")
|
57 |
+
resize_img("test1.png", "test3.png", "resized_img3.png")
|
58 |
+
resize_img("test1.png", "test4.png", "resized_img4.png")
|
59 |
+
resize_img("test1.png", "test5.png", "resized_img5.png")
|
60 |
+
resize_img("test1.png", "test6.png", "resized_img6.png")
|
61 |
+
|
62 |
+
input_frames = ["test1.png", "resized_img2.png", "resized_img3.png", "resized_img4.png", "resized_img5.png", "resized_img6.png"]
|
63 |
+
|
64 |
+
frames = list(util.interpolate_recursively_from_files(input_frames, times_to_interpolate, interpolator))
|
65 |
+
|
66 |
+
mediapy.write_video("out.mp4", frames, fps=30)
|
67 |
+
|
68 |
+
return "out.mp4"
|
69 |
+
|
70 |
+
demo = gr.Blocks()
|
71 |
+
|
72 |
+
with demo:
|
73 |
+
with gr.Row():
|
74 |
+
|
75 |
+
# Left column (inputs)
|
76 |
+
with gr.Column():
|
77 |
+
|
78 |
+
with gr.Row():
|
79 |
+
# upload images and get image strings
|
80 |
+
input_arr = [
|
81 |
+
gr.inputs.Image(type='filepath'),
|
82 |
+
gr.inputs.Image(type='filepath'),
|
83 |
+
gr.inputs.Image(type='filepath'),
|
84 |
+
gr.inputs.Image(type='filepath'),
|
85 |
+
gr.inputs.Image(type='filepath'),
|
86 |
+
gr.inputs.Image(type='filepath'),
|
87 |
+
]
|
88 |
+
|
89 |
+
with gr.Row():
|
90 |
+
input_arr.append(gr.inputs.Slider(minimum=2, maximum=4, step=1))
|
91 |
+
|
92 |
+
# Rows of instructions & buttons
|
93 |
+
with gr.Row():
|
94 |
+
gr.Markdown("After uploading some images, hit the 'Generate Video' button to create a short video!")
|
95 |
+
button_gen_video = gr.Button("Generate Video")
|
96 |
+
|
97 |
+
|
98 |
+
# Right column (outputs)
|
99 |
+
with gr.Column():
|
100 |
+
output_interpolation = gr.Video(label="Generated Video")
|
101 |
+
|
102 |
+
# Bind functions to buttons
|
103 |
+
button_gen_video.click(fn=generate_interpolation, inputs=input_arr, outputs=output_interpolation)
|
104 |
+
|
105 |
+
demo.launch(debug=True, enable_queue=True)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
|
4 |
+
tensorflow==2.11.0
|
5 |
+
tensorflow-gpu==2.11.0
|
6 |
+
tensorflow-datasets==4.4.0
|
7 |
+
tensorflow-addons==0.15.0
|
8 |
+
absl-py==1.4.0
|
9 |
+
gin-config==0.5.0
|
10 |
+
parameterized==0.8.1
|
11 |
+
mediapy==1.0.3
|
12 |
+
scikit-image==0.19.1
|
13 |
+
apache-beam==2.34.0
|
14 |
+
google-cloud-bigquery-storage==1.1.0
|
15 |
+
natsort==8.1.0
|
16 |
+
image-tools
|