Clement Delteil
huge modif
70b0b9d
raw
history blame
1.28 kB
import requests
import numpy as np
from models.deep_colorization.colorizers import postprocess_tens, preprocess_img
# Define a function that we can use to load lottie files from a link.
def load_lottieurl(url: str):
r = requests.get(url)
if r.status_code != 200:
return None
return r.json()
def format_time(seconds: float) -> str:
"""Formats time in seconds to a human readable format"""
if seconds < 60:
return f"{int(seconds)} seconds"
elif seconds < 3600:
minutes = seconds // 60
seconds %= 60
return f"{minutes} minutes and {int(seconds)} seconds"
elif seconds < 86400:
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds %= 60
return f"{hours} hours, {minutes} minutes, and {int(seconds)} seconds"
else:
days = seconds // 86400
hours = (seconds % 86400) // 3600
minutes = (seconds % 3600) // 60
seconds %= 60
return f"{days} days, {hours} hours, {minutes} minutes, and {int(seconds)} seconds"
# Function to colorize video frames
def colorize_frame(frame, colorizer) -> np.ndarray:
tens_l_orig, tens_l_rs = preprocess_img(frame, HW=(256, 256))
return postprocess_tens(tens_l_orig, colorizer(tens_l_rs).cpu())