Spaces:
Runtime error
Runtime error
import os | |
os.system("git clone https://github.com/google-research/frame-interpolation") | |
import sys | |
sys.path.append("frame-interpolation") | |
import numpy as np | |
import tensorflow as tf | |
import mediapy | |
from PIL import Image | |
from eval import interpolator, util | |
import gradio as gr | |
from huggingface_hub import snapshot_download | |
from image_tools.sizes import resize_and_crop | |
model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style") | |
interpolator = interpolator.Interpolator(model, None) | |
ffmpeg_path = util.get_ffmpeg_path() | |
mediapy.set_ffmpeg(ffmpeg_path) | |
def resize(width,img): | |
basewidth = width | |
img = Image.open(img) | |
wpercent = (basewidth/float(img.size[0])) | |
hsize = int((float(img.size[1])*float(wpercent))) | |
img = img.resize((basewidth,hsize), Image.ANTIALIAS) | |
return img | |
def resize_img(img1,img2): | |
img_target_size = Image.open(img1) | |
img_to_resize = resize_and_crop( | |
img2, | |
(img_target_size.size[0],img_target_size.size[1]), #set width and height to match img1 | |
crop_origin="middle" | |
) | |
img_to_resize.save('resized_img2.png') | |
sketch1 = gr.Image(image_mode="RGB", | |
source="canvas", | |
type="filepath", | |
shape=None, | |
invert_colors=False) | |
sketch2 = gr.Image(image_mode="RGB", | |
source="canvas", | |
type="filepath", | |
shape=None, | |
invert_colors=False) | |
slider = gr.inputs.Slider(minimum=2,maximum=4,step=1) | |
def predict(frame1, frame2, times_to_interpolate): | |
frame1 = resize(256,frame1) | |
frame2 = resize(256,frame2) | |
frame1.save("test1.png") | |
frame2.save("test2.png") | |
resize_img("test1.png","test2.png") | |
input_frames = ["test1.png", "resized_img2.png"] | |
frames = list( | |
util.interpolate_recursively_from_files( | |
input_frames, times_to_interpolate, interpolator)) | |
print(frames) | |
#mediapy.write_video("out.mp4", frames, fps=30) | |
#return "out.mp4" | |
return frames | |
title="sketch-frame-interpolation" | |
description="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." | |
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>" | |
custom_css = "style.css" | |
gr.Interface(predict,[sketch1,sketch2,slider],gr.Gallery(frames),title=title,description=description,article=article, css=custom_css).launch(enable_queue=True) |