Update app.py
Browse files
app.py
CHANGED
|
@@ -93,15 +93,13 @@ def create_video(frames, fps, type):
|
|
| 93 |
mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
|
| 94 |
return type + "_result.mp4"
|
| 95 |
|
| 96 |
-
def sortFiles(e):
|
| 97 |
-
return e[0]
|
| 98 |
|
| 99 |
-
def infer(
|
| 100 |
|
| 101 |
fps_output = logscale(fps_output)
|
| 102 |
# 1. break video into frames and get FPS
|
| 103 |
#break_vid = get_frames(url_in, "vid_input_frame", "origin", resize_n)
|
| 104 |
-
frames_list =
|
| 105 |
fps = 1 #break_vid[1]
|
| 106 |
print(f"ORIGIN FPS: {fps}")
|
| 107 |
n_frame = int(300) #limited to 300 frames
|
|
@@ -119,7 +117,7 @@ def infer(glr_in, interpolation, fps_output):
|
|
| 119 |
if idx < len(frames_list) - 1:
|
| 120 |
next_frame = frames_list[idx+1]
|
| 121 |
|
| 122 |
-
interpolated_frames = do_interpolation(frame
|
| 123 |
break_interpolated_video = get_frames(interpolated_frames, "interpol", f"{idx}_", 0)
|
| 124 |
print(break_interpolated_video[0])
|
| 125 |
for j, img in enumerate(break_interpolated_video[0][0:len(break_interpolated_video[0])-1]):
|
|
@@ -129,7 +127,7 @@ def infer(glr_in, interpolation, fps_output):
|
|
| 129 |
|
| 130 |
print("frames " + str(idx) + " & " + str(idx+1) + "/" + str(n_frame) + ": done;")
|
| 131 |
#print(f"CURRENT FRAMES: {result_frames}")
|
| 132 |
-
result_frames.append(f"{frames_list[n_frame-1]
|
| 133 |
final_vid = create_video(result_frames, fps_output, "interpolated")
|
| 134 |
|
| 135 |
files = final_vid
|
|
@@ -145,8 +143,9 @@ def logscale(linear):
|
|
| 145 |
def linscale(linear):
|
| 146 |
return int(math.log2(linear))
|
| 147 |
|
| 148 |
-
def
|
| 149 |
-
|
|
|
|
| 150 |
|
| 151 |
|
| 152 |
title="""
|
|
@@ -177,8 +176,9 @@ with gr.Blocks() as demo:
|
|
| 177 |
gr.HTML(title)
|
| 178 |
with gr.Row():
|
| 179 |
with gr.Column():
|
| 180 |
-
|
| 181 |
-
|
|
|
|
| 182 |
with gr.Row():
|
| 183 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 184 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
@@ -196,11 +196,11 @@ with gr.Blocks() as demo:
|
|
| 196 |
gr.Examples(
|
| 197 |
examples=[[["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"], 1, 0]],
|
| 198 |
fn=infer,
|
| 199 |
-
inputs=[
|
| 200 |
outputs=[video_output, file_output],
|
| 201 |
cache_examples=True
|
| 202 |
)
|
| 203 |
|
| 204 |
-
submit_btn.click(fn=infer, inputs=[
|
| 205 |
|
| 206 |
demo.launch()
|
|
|
|
| 93 |
mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
|
| 94 |
return type + "_result.mp4"
|
| 95 |
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
def infer(f_in, interpolation, fps_output):
|
| 98 |
|
| 99 |
fps_output = logscale(fps_output)
|
| 100 |
# 1. break video into frames and get FPS
|
| 101 |
#break_vid = get_frames(url_in, "vid_input_frame", "origin", resize_n)
|
| 102 |
+
frames_list = f_in #break_vid[0]
|
| 103 |
fps = 1 #break_vid[1]
|
| 104 |
print(f"ORIGIN FPS: {fps}")
|
| 105 |
n_frame = int(300) #limited to 300 frames
|
|
|
|
| 117 |
if idx < len(frames_list) - 1:
|
| 118 |
next_frame = frames_list[idx+1]
|
| 119 |
|
| 120 |
+
interpolated_frames = do_interpolation(frame, next_frame, interpolation, idx) # should return a list of interpolated frames
|
| 121 |
break_interpolated_video = get_frames(interpolated_frames, "interpol", f"{idx}_", 0)
|
| 122 |
print(break_interpolated_video[0])
|
| 123 |
for j, img in enumerate(break_interpolated_video[0][0:len(break_interpolated_video[0])-1]):
|
|
|
|
| 127 |
|
| 128 |
print("frames " + str(idx) + " & " + str(idx+1) + "/" + str(n_frame) + ": done;")
|
| 129 |
#print(f"CURRENT FRAMES: {result_frames}")
|
| 130 |
+
result_frames.append(f"{frames_list[n_frame-1]}")
|
| 131 |
final_vid = create_video(result_frames, fps_output, "interpolated")
|
| 132 |
|
| 133 |
files = final_vid
|
|
|
|
| 143 |
def linscale(linear):
|
| 144 |
return int(math.log2(linear))
|
| 145 |
|
| 146 |
+
def loadf(f):
|
| 147 |
+
f = f.sort()
|
| 148 |
+
return f
|
| 149 |
|
| 150 |
|
| 151 |
title="""
|
|
|
|
| 176 |
gr.HTML(title)
|
| 177 |
with gr.Row():
|
| 178 |
with gr.Column():
|
| 179 |
+
files_input = gr.File(file_count="directory")
|
| 180 |
+
gallery_input = gr.Gallery(label="Slides", preview=True, columns=8192, interactive=False)
|
| 181 |
+
files_input.change(fn=loadf, inputs=[files_input], outputs=[gallery_input])
|
| 182 |
with gr.Row():
|
| 183 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 184 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
|
|
| 196 |
gr.Examples(
|
| 197 |
examples=[[["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"], 1, 0]],
|
| 198 |
fn=infer,
|
| 199 |
+
inputs=[files_input, interpolation_slider, fps_output_slider],
|
| 200 |
outputs=[video_output, file_output],
|
| 201 |
cache_examples=True
|
| 202 |
)
|
| 203 |
|
| 204 |
+
submit_btn.click(fn=infer, inputs=[files_input, interpolation_slider, fps_output_slider], outputs=[video_output, file_output])
|
| 205 |
|
| 206 |
demo.launch()
|