Commit
·
f6813a8
1
Parent(s):
bbcdff1
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,9 @@ import numpy as np
|
|
| 8 |
import tensorflow as tf
|
| 9 |
import mediapy
|
| 10 |
from PIL import Image
|
| 11 |
-
|
| 12 |
import gradio as gr
|
| 13 |
-
|
| 14 |
from huggingface_hub import snapshot_download
|
| 15 |
|
| 16 |
from image_tools.sizes import resize_and_crop
|
|
@@ -26,6 +26,12 @@ mediapy.set_ffmpeg(ffmpeg_path)
|
|
| 26 |
|
| 27 |
SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def do_interpolation(frame1, frame2, times_to_interpolate):
|
| 30 |
print(frame1, frame2)
|
| 31 |
input_frames = [frame1, frame2]
|
|
@@ -84,10 +90,15 @@ def create_video(frames, fps, type):
|
|
| 84 |
return type + "_result.mp4"
|
| 85 |
|
| 86 |
|
| 87 |
-
def infer(secret_token,
|
| 88 |
|
| 89 |
if secret_token != SECRET_TOKEN:
|
| 90 |
raise gr.Error(f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# 1. break video into frames and get FPS
|
| 93 |
break_vid = get_frames(video_in, "vid_input_frame", "origin")
|
|
@@ -103,9 +114,7 @@ def infer(secret_token, video_in,interpolation,fps_output):
|
|
| 103 |
|
| 104 |
# 2. prepare frames result arrays
|
| 105 |
result_frames = []
|
| 106 |
-
print("set stop frames to: " + str(n_frame))
|
| 107 |
-
|
| 108 |
-
|
| 109 |
|
| 110 |
|
| 111 |
for idx, frame in enumerate(frames_list[0:int(n_frame)]):
|
|
@@ -138,7 +147,7 @@ with gr.Blocks() as demo:
|
|
| 138 |
</div>
|
| 139 |
</div>""")
|
| 140 |
secret_token = gr.Textbox(label="Secret token")
|
| 141 |
-
video_input = gr.Video(source="upload", type="
|
| 142 |
|
| 143 |
interpolation = gr.Slider(minimum=1,maximum=4,step=1, value=3, label="Interpolation Steps")
|
| 144 |
fps_output = gr.Radio([8, 12, 24], label="FPS output", value=24)
|
|
|
|
| 8 |
import tensorflow as tf
|
| 9 |
import mediapy
|
| 10 |
from PIL import Image
|
| 11 |
+
import base64
|
| 12 |
import gradio as gr
|
| 13 |
+
import tempfile
|
| 14 |
from huggingface_hub import snapshot_download
|
| 15 |
|
| 16 |
from image_tools.sizes import resize_and_crop
|
|
|
|
| 26 |
|
| 27 |
SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
|
| 28 |
|
| 29 |
+
|
| 30 |
+
def base64_to_video(base64_string, output_file):
|
| 31 |
+
video_data = base64.b64decode(base64_string)
|
| 32 |
+
with open(output_file, 'wb') as f:
|
| 33 |
+
f.write(video_data)
|
| 34 |
+
|
| 35 |
def do_interpolation(frame1, frame2, times_to_interpolate):
|
| 36 |
print(frame1, frame2)
|
| 37 |
input_frames = [frame1, frame2]
|
|
|
|
| 90 |
return type + "_result.mp4"
|
| 91 |
|
| 92 |
|
| 93 |
+
def infer(secret_token, video_in_base64, interpolation, fps_output):
|
| 94 |
|
| 95 |
if secret_token != SECRET_TOKEN:
|
| 96 |
raise gr.Error(f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Decode the base64 string to a video file
|
| 100 |
+
video_in = "video_in.mp4" # or choose any other filename/path
|
| 101 |
+
base64_to_video(video_in_base64, video_in)
|
| 102 |
|
| 103 |
# 1. break video into frames and get FPS
|
| 104 |
break_vid = get_frames(video_in, "vid_input_frame", "origin")
|
|
|
|
| 114 |
|
| 115 |
# 2. prepare frames result arrays
|
| 116 |
result_frames = []
|
| 117 |
+
# print("set stop frames to: " + str(n_frame))
|
|
|
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
for idx, frame in enumerate(frames_list[0:int(n_frame)]):
|
|
|
|
| 147 |
</div>
|
| 148 |
</div>""")
|
| 149 |
secret_token = gr.Textbox(label="Secret token")
|
| 150 |
+
video_input = gr.Video(source="upload", type="base64")
|
| 151 |
|
| 152 |
interpolation = gr.Slider(minimum=1,maximum=4,step=1, value=3, label="Interpolation Steps")
|
| 153 |
fps_output = gr.Radio([8, 12, 24], label="FPS output", value=24)
|