fffiloni commited on
Commit
1425010
1 Parent(s): b1a1462

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -82
app.py CHANGED
@@ -14,6 +14,7 @@ import gradio as gr
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")
@@ -23,94 +24,18 @@ interpolator = interpolator.Interpolator(model, None)
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
 
@@ -119,4 +44,4 @@ description="<p style='text-align: center'>This is a fork of the Gradio demo for
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)
 
14
  from huggingface_hub import snapshot_download
15
 
16
  from image_tools.sizes import resize_and_crop
17
+ from moviepy.editor import *
18
 
19
 
20
  model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style")
 
24
  ffmpeg_path = util.get_ffmpeg_path()
25
  mediapy.set_ffmpeg(ffmpeg_path)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
 
29
+ def interpolate(frame1, frame2, times_to_interpolate):
30
+
31
+ input_frames = [frame1, frame2]
 
 
 
 
 
 
 
32
 
33
  frames = list(
34
  util.interpolate_recursively_from_files(
35
  input_frames, times_to_interpolate, interpolator))
36
  print(frames)
37
+
38
+ return "done"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
 
 
44
  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>"
45
  custom_css = "style.css"
46
 
47
+ gr.Interface(interpolate,[gr.Image(source="upload", type="filepath"),gr.Image(source="upload", type="filepath"),2],outputs=[gr.Textbox()],title=title,description=description,article=article,css=custom_css).launch(enable_queue=True)