fffiloni commited on
Commit
10aeea5
β€’
1 Parent(s): 9d11980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -5
app.py CHANGED
@@ -2,6 +2,7 @@ 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
7
  import mediapy
@@ -70,14 +71,48 @@ def predict(frame1, frame2, times_to_interpolate):
70
  util.interpolate_recursively_from_files(
71
  input_frames, times_to_interpolate, interpolator))
72
  print(frames)
73
- #mediapy.write_video("out.mp4", frames, fps=30)
74
- #return "out.mp4"
75
- mediapy.to_uint8(frames)
76
- return frames
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  title="sketch-frame-interpolation"
79
  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."
80
  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>"
81
  custom_css = "style.css"
82
 
83
- gr.Interface(predict,[sketch1,sketch2,slider],outputs=gr.outputs.Carousel([gr.outputs.Image(type="list")]),title=title,description=description,article=article, css=custom_css).launch(enable_queue=True)
 
2
  os.system("git clone https://github.com/google-research/frame-interpolation")
3
  import sys
4
  sys.path.append("frame-interpolation")
5
+ import cv2
6
  import numpy as np
7
  import tensorflow as tf
8
  import mediapy
 
71
  util.interpolate_recursively_from_files(
72
  input_frames, times_to_interpolate, interpolator))
73
  print(frames)
74
+ mediapy.write_video("out.mp4", frames, fps=30)
75
+
76
+ # video.mp4 is a video of 9 seconds
77
+ filename = "out.mp4"
78
+
79
+ cap = cv2.VideoCapture(filename)
80
+ cap.set(cv2.CAP_PROP_POS_AVI_RATIO,0)
81
+ frameCount = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
82
+ frameWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
83
+ frameHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
84
+ videoFPS = int(cap.get(cv2.CAP_PROP_FPS))
85
+
86
+ print (f"frameCount: {frameCount}")
87
+ print (f"frameWidth: {frameWidth}")
88
+ print (f"frameHeight: {frameHeight}")
89
+ print (f"videoFPS: {videoFPS}")
90
+
91
+ buf = np.empty((
92
+ frameCount,
93
+ frameHeight,
94
+ frameWidth,
95
+ 3), np.dtype('uint8'))
96
+
97
+ fc = 0
98
+ ret = True
99
+
100
+ while (fc < frameCount):
101
+ ret, buf[fc] = cap.read()
102
+ fc += 1
103
+
104
+ cap.release()
105
+ videoArray = buf
106
+
107
+ print (f"DURATION: {frameCount/videoFPS}")
108
+
109
+ return "out.mp4"
110
+
111
+
112
 
113
  title="sketch-frame-interpolation"
114
  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."
115
  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>"
116
  custom_css = "style.css"
117
 
118
+ gr.Interface(predict,[sketch1,sketch2,slider],'playable_video',title=title,description=description,article=article, css=custom_css).launch(enable_queue=True)