fffiloni commited on
Commit
378846e
1 Parent(s): ea75193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -26,10 +26,10 @@ mediapy.set_ffmpeg(ffmpeg_path)
26
 
27
 
28
 
29
- def do_interpolation(frame1, frame2):
30
  print(frame1, frame2)
31
  input_frames = [frame1, frame2]
32
- times_to_interpolate = 2
33
  frames = list(
34
  util.interpolate_recursively_from_files(
35
  input_frames, times_to_interpolate, interpolator))
@@ -83,12 +83,8 @@ def create_video(frames, fps, type):
83
 
84
  return type + "_result.mp4"
85
 
86
- def convertG2V(imported_gif):
87
- clip = VideoFileClip(imported_gif.name)
88
- clip.write_videofile("my_gif_video.mp4")
89
- return "my_gif_video.mp4"
90
 
91
- def infer(video_in):
92
 
93
 
94
  # 1. break video into frames and get FPS
@@ -112,7 +108,7 @@ def infer(video_in):
112
  for idx, frame in enumerate(frames_list):
113
  if idx < len(frames_list) - 1:
114
  next_frame = frames_list[idx+1]
115
- interpolated_frames = do_interpolation(frame, next_frame) # should return a list of 3 interpolated frames
116
  break_interpolated_video = get_frames(interpolated_frames, "interpol")
117
  print(break_interpolated_video[0])
118
  for j, img in enumerate(break_interpolated_video[0]):
@@ -121,7 +117,7 @@ def infer(video_in):
121
  result_frames.append(f"{frame}_to_{next_frame}_{j}.jpg")
122
  print("frames " + str(idx) + " & " + str(idx+1) + "/" + str(n_frame) + ": done;")
123
 
124
- final_vid = create_video(result_frames, 8, "interpolated")
125
 
126
  files = [final_vid]
127
 
@@ -153,8 +149,8 @@ with gr.Blocks() as demo:
153
  with gr.Row():
154
  with gr.Column():
155
  video_input = gr.Video(source="upload", type="filepath")
156
- gif_input = gr.File(label="import a GIF instead", file_types=['.gif'])
157
- gif_input.change(fn=convertG2V, inputs=gif_input, outputs=video_input)
158
  submit_btn = gr.Button("Submit")
159
 
160
  with gr.Column():
@@ -169,6 +165,6 @@ with gr.Blocks() as demo:
169
  #cache_examples=False
170
  #)
171
 
172
- submit_btn.click(fn=infer, inputs=[video_input], outputs=[video_output, file_output])
173
 
174
  demo.launch()
 
26
 
27
 
28
 
29
+ def do_interpolation(frame1, frame2, times_to_interpolate):
30
  print(frame1, frame2)
31
  input_frames = [frame1, frame2]
32
+ #times_to_interpolate = 2
33
  frames = list(
34
  util.interpolate_recursively_from_files(
35
  input_frames, times_to_interpolate, interpolator))
 
83
 
84
  return type + "_result.mp4"
85
 
 
 
 
 
86
 
87
+ def infer(video_in,interpolation,fps_output):
88
 
89
 
90
  # 1. break video into frames and get FPS
 
108
  for idx, frame in enumerate(frames_list):
109
  if idx < len(frames_list) - 1:
110
  next_frame = frames_list[idx+1]
111
+ interpolated_frames = do_interpolation(frame, next_frame,interpolation) # should return a list of 3 interpolated frames
112
  break_interpolated_video = get_frames(interpolated_frames, "interpol")
113
  print(break_interpolated_video[0])
114
  for j, img in enumerate(break_interpolated_video[0]):
 
117
  result_frames.append(f"{frame}_to_{next_frame}_{j}.jpg")
118
  print("frames " + str(idx) + " & " + str(idx+1) + "/" + str(n_frame) + ": done;")
119
 
120
+ final_vid = create_video(result_frames, fps_output, "interpolated")
121
 
122
  files = [final_vid]
123
 
 
149
  with gr.Row():
150
  with gr.Column():
151
  video_input = gr.Video(source="upload", type="filepath")
152
+ interpolation = gr.Slider(minimum=2,maximum=4,step=1, value=1, label="Interpolation Steps")
153
+ fps_output = gr.Radio([8, 12, 24], label="FPS output")
154
  submit_btn = gr.Button("Submit")
155
 
156
  with gr.Column():
 
165
  #cache_examples=False
166
  #)
167
 
168
+ submit_btn.click(fn=infer, inputs=[video_input,interpolation,fps_output], outputs=[video_output, file_output])
169
 
170
  demo.launch()