Spaces:
Sleeping
Sleeping
Clement Delteil
commited on
Commit
·
70b0b9d
1
Parent(s):
b55565e
huge modif
Browse files- .streamlit/config.toml +8 -0
- 01_📼_Upload_Video_File.py +142 -0
- app.py +0 -196
- img/color_revive.png +0 -0
- img/streamlit.png +0 -0
- pages/02_🎥_Input_Youtube_Link.py +60 -0
- pages/03_🖼️_Input_Images.py +60 -0
- requirements.txt +3 -1
- utils.py +38 -0
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
primaryColor="#F63366"
|
| 3 |
+
backgroundColor="#FFFFFF"
|
| 4 |
+
secondaryBackgroundColor="#F0F2F6"
|
| 5 |
+
textColor="#262730"
|
| 6 |
+
font="sans serif"
|
| 7 |
+
[server]
|
| 8 |
+
maxUploadSize=1028
|
01_📼_Upload_Video_File.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_lottie import st_lottie
|
| 3 |
+
from models.deep_colorization.colorizers import *
|
| 4 |
+
from utils import load_lottieurl, format_time, colorize_frame
|
| 5 |
+
import os
|
| 6 |
+
import tempfile
|
| 7 |
+
import cv2
|
| 8 |
+
import moviepy.editor as mp
|
| 9 |
+
import time
|
| 10 |
+
from tqdm import tqdm
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title="Image & Video Colorizer", page_icon="🎨", layout="wide")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 16 |
+
current_model = "None"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def change_model(current_model, model):
|
| 20 |
+
if current_model != model:
|
| 21 |
+
if model == "ECCV16":
|
| 22 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 23 |
+
elif model == "SIGGRAPH17":
|
| 24 |
+
loaded_model = siggraph17(pretrained=True).eval()
|
| 25 |
+
return loaded_model
|
| 26 |
+
else:
|
| 27 |
+
raise Exception("Model is the same as the current one.")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
col1, col2 = st.columns([1, 3])
|
| 31 |
+
with col1:
|
| 32 |
+
lottie = load_lottieurl("https://assets5.lottiefiles.com/packages/lf20_RHdEuzVfEL.json")
|
| 33 |
+
st_lottie(lottie)
|
| 34 |
+
|
| 35 |
+
with col2:
|
| 36 |
+
st.write("""
|
| 37 |
+
## B&W Videos Colorizer
|
| 38 |
+
##### Upload a black and white video and get a colorized version of it.
|
| 39 |
+
###### I recommend starting with the first model and then experimenting with the second one.""")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def main():
|
| 43 |
+
model = st.selectbox(
|
| 44 |
+
"Select Model (Both models have their pros and cons, I recommend to try both and keep the best for your task)",
|
| 45 |
+
["ECCV16", "SIGGRAPH17"], index=0)
|
| 46 |
+
|
| 47 |
+
loaded_model = change_model(current_model, model)
|
| 48 |
+
st.write(f"Model is now {model}")
|
| 49 |
+
|
| 50 |
+
uploaded_file = st.file_uploader("Upload your video here...", type=['mp4'])
|
| 51 |
+
|
| 52 |
+
if st.button("Colorize"):
|
| 53 |
+
if uploaded_file is not None:
|
| 54 |
+
file_extension = os.path.splitext(uploaded_file.name)[1].lower()
|
| 55 |
+
if file_extension == '.mp4':
|
| 56 |
+
# Save the video file to a temporary location
|
| 57 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
| 58 |
+
temp_file.write(uploaded_file.read())
|
| 59 |
+
|
| 60 |
+
audio = mp.AudioFileClip(temp_file.name)
|
| 61 |
+
|
| 62 |
+
# Open the video using cv2.VideoCapture
|
| 63 |
+
video = cv2.VideoCapture(temp_file.name)
|
| 64 |
+
|
| 65 |
+
# Get video information
|
| 66 |
+
fps = video.get(cv2.CAP_PROP_FPS)
|
| 67 |
+
|
| 68 |
+
col1, col2 = st.columns([0.5, 0.5])
|
| 69 |
+
with col1:
|
| 70 |
+
st.markdown('<p style="text-align: center;">Before</p>', unsafe_allow_html=True)
|
| 71 |
+
st.video(temp_file.name)
|
| 72 |
+
|
| 73 |
+
with col2:
|
| 74 |
+
st.markdown('<p style="text-align: center;">After</p>', unsafe_allow_html=True)
|
| 75 |
+
|
| 76 |
+
with st.spinner("Colorizing frames..."):
|
| 77 |
+
# Colorize video frames and store in a list
|
| 78 |
+
output_frames = []
|
| 79 |
+
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 80 |
+
progress_bar = st.empty()
|
| 81 |
+
|
| 82 |
+
start_time = time.time()
|
| 83 |
+
for i in tqdm(range(total_frames), unit='frame', desc="Progress"):
|
| 84 |
+
ret, frame = video.read()
|
| 85 |
+
if not ret:
|
| 86 |
+
break
|
| 87 |
+
|
| 88 |
+
colorized_frame = colorize_frame(frame, loaded_model)
|
| 89 |
+
output_frames.append((colorized_frame * 255).astype(np.uint8))
|
| 90 |
+
|
| 91 |
+
elapsed_time = time.time() - start_time
|
| 92 |
+
frames_completed = len(output_frames)
|
| 93 |
+
frames_remaining = total_frames - frames_completed
|
| 94 |
+
time_remaining = (frames_remaining / frames_completed) * elapsed_time
|
| 95 |
+
|
| 96 |
+
progress_bar.progress(frames_completed / total_frames)
|
| 97 |
+
|
| 98 |
+
if frames_completed < total_frames:
|
| 99 |
+
progress_bar.text(f"Time Remaining: {format_time(time_remaining)}")
|
| 100 |
+
else:
|
| 101 |
+
progress_bar.empty()
|
| 102 |
+
|
| 103 |
+
with st.spinner("Merging frames to video..."):
|
| 104 |
+
frame_size = output_frames[0].shape[:2]
|
| 105 |
+
output_filename = "output.mp4"
|
| 106 |
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
|
| 107 |
+
out = cv2.VideoWriter(output_filename, fourcc, fps, (frame_size[1], frame_size[0]))
|
| 108 |
+
|
| 109 |
+
# Display the colorized video using st.video
|
| 110 |
+
for frame in output_frames:
|
| 111 |
+
frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
| 112 |
+
|
| 113 |
+
out.write(frame_bgr)
|
| 114 |
+
|
| 115 |
+
out.release()
|
| 116 |
+
|
| 117 |
+
# Convert the output video to a format compatible with Streamlit
|
| 118 |
+
converted_filename = "converted_output.mp4"
|
| 119 |
+
clip = mp.VideoFileClip(output_filename)
|
| 120 |
+
clip = clip.set_audio(audio)
|
| 121 |
+
|
| 122 |
+
clip.write_videofile(converted_filename, codec="libx264")
|
| 123 |
+
|
| 124 |
+
# Display the converted video using st.video()
|
| 125 |
+
st.video(converted_filename)
|
| 126 |
+
|
| 127 |
+
# Add a download button for the colorized video
|
| 128 |
+
st.download_button(
|
| 129 |
+
label="Download Colorized Video",
|
| 130 |
+
data=open(converted_filename, "rb").read(),
|
| 131 |
+
file_name="colorized_video.mp4"
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# Close and delete the temporary file after processing
|
| 135 |
+
video.release()
|
| 136 |
+
temp_file.close()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
main()
|
| 141 |
+
st.markdown(
|
| 142 |
+
"###### Made with :heart: by [Clément Delteil](https://www.linkedin.com/in/clementdelteil/) [](https://www.buymeacoffee.com/clementdelteil)")
|
app.py
DELETED
|
@@ -1,196 +0,0 @@
|
|
| 1 |
-
import os.path
|
| 2 |
-
|
| 3 |
-
import streamlit as st
|
| 4 |
-
from models.deep_colorization.colorizers import *
|
| 5 |
-
import cv2
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import tempfile
|
| 8 |
-
import moviepy.editor as mp
|
| 9 |
-
import time
|
| 10 |
-
from tqdm import tqdm
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def format_time(seconds: float) -> str:
|
| 14 |
-
"""Formats time in seconds to a human readable format"""
|
| 15 |
-
if seconds < 60:
|
| 16 |
-
return f"{int(seconds)} seconds"
|
| 17 |
-
elif seconds < 3600:
|
| 18 |
-
minutes = seconds // 60
|
| 19 |
-
seconds %= 60
|
| 20 |
-
return f"{minutes} minutes and {int(seconds)} seconds"
|
| 21 |
-
elif seconds < 86400:
|
| 22 |
-
hours = seconds // 3600
|
| 23 |
-
minutes = (seconds % 3600) // 60
|
| 24 |
-
seconds %= 60
|
| 25 |
-
return f"{hours} hours, {minutes} minutes, and {int(seconds)} seconds"
|
| 26 |
-
else:
|
| 27 |
-
days = seconds // 86400
|
| 28 |
-
hours = (seconds % 86400) // 3600
|
| 29 |
-
minutes = (seconds % 3600) // 60
|
| 30 |
-
seconds %= 60
|
| 31 |
-
return f"{days} days, {hours} hours, {minutes} minutes, and {int(seconds)} seconds"
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# Function to colorize video frames
|
| 35 |
-
def colorize_frame(frame, colorizer) -> np.ndarray:
|
| 36 |
-
tens_l_orig, tens_l_rs = preprocess_img(frame, HW=(256, 256))
|
| 37 |
-
return postprocess_tens(tens_l_orig, colorizer(tens_l_rs).cpu())
|
| 38 |
-
|
| 39 |
-
image = Image.open(r'img/streamlit.png') # Brand logo image (optional)
|
| 40 |
-
|
| 41 |
-
# Create two columns with different width
|
| 42 |
-
col1, col2 = st.columns([0.8, 0.2])
|
| 43 |
-
with col1: # To display the header text using css style
|
| 44 |
-
st.markdown(""" <style> .font {
|
| 45 |
-
font-size:35px ; font-family: 'Cooper Black'; color: #FF4B4B;}
|
| 46 |
-
</style> """, unsafe_allow_html=True)
|
| 47 |
-
st.markdown('<p class="font">Upload your photo or video here...</p>', unsafe_allow_html=True)
|
| 48 |
-
|
| 49 |
-
with col2: # To display brand logo
|
| 50 |
-
st.image(image, width=100)
|
| 51 |
-
|
| 52 |
-
# Add a header and expander in side bar
|
| 53 |
-
st.sidebar.markdown('<p class="font">Color Revive App</p>', unsafe_allow_html=True)
|
| 54 |
-
with st.sidebar.expander("About the App"):
|
| 55 |
-
st.write("""
|
| 56 |
-
Use this simple app to colorize your black and white images and videos with state of the art models.
|
| 57 |
-
""")
|
| 58 |
-
|
| 59 |
-
# Add file uploader to allow users to upload photos
|
| 60 |
-
uploaded_file = st.file_uploader("", type=['jpg', 'png', 'jpeg', 'mp4'])
|
| 61 |
-
|
| 62 |
-
# Add 'before' and 'after' columns
|
| 63 |
-
if uploaded_file is not None:
|
| 64 |
-
file_extension = os.path.splitext(uploaded_file.name)[1].lower()
|
| 65 |
-
|
| 66 |
-
if file_extension in ['jpg', 'png', 'jpeg']:
|
| 67 |
-
image = Image.open(uploaded_file)
|
| 68 |
-
|
| 69 |
-
col1, col2 = st.columns([0.5, 0.5])
|
| 70 |
-
with col1:
|
| 71 |
-
st.markdown('<p style="text-align: center;">Before</p>', unsafe_allow_html=True)
|
| 72 |
-
st.image(image, width=300)
|
| 73 |
-
|
| 74 |
-
# Add conditional statements to take the user input values
|
| 75 |
-
with col2:
|
| 76 |
-
st.markdown('<p style="text-align: center;">After</p>', unsafe_allow_html=True)
|
| 77 |
-
filter = st.sidebar.radio('Colorize your image with:',
|
| 78 |
-
['Original', 'ECCV 16', 'SIGGRAPH 17'])
|
| 79 |
-
if filter == 'ECCV 16':
|
| 80 |
-
colorizer_eccv16 = eccv16(pretrained=True).eval()
|
| 81 |
-
img = load_img(uploaded_file)
|
| 82 |
-
tens_l_orig, tens_l_rs = preprocess_img(img, HW=(256, 256))
|
| 83 |
-
out_img_eccv16 = postprocess_tens(tens_l_orig, colorizer_eccv16(tens_l_rs).cpu())
|
| 84 |
-
st.image(out_img_eccv16, width=300)
|
| 85 |
-
elif filter == 'SIGGRAPH 17':
|
| 86 |
-
colorizer_siggraph17 = siggraph17(pretrained=True).eval()
|
| 87 |
-
img = load_img(uploaded_file)
|
| 88 |
-
tens_l_orig, tens_l_rs = preprocess_img(img, HW=(256, 256))
|
| 89 |
-
out_img_siggraph17 = postprocess_tens(tens_l_orig, colorizer_siggraph17(tens_l_rs).cpu())
|
| 90 |
-
st.image(out_img_siggraph17, width=300)
|
| 91 |
-
else:
|
| 92 |
-
st.image(image, width=300)
|
| 93 |
-
elif file_extension == 'mp4': # If uploaded file is a video
|
| 94 |
-
# Save the video file to a temporary location
|
| 95 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
| 96 |
-
temp_file.write(uploaded_file.read())
|
| 97 |
-
|
| 98 |
-
# Open the video using cv2.VideoCapture
|
| 99 |
-
video = cv2.VideoCapture(temp_file.name)
|
| 100 |
-
|
| 101 |
-
# Get video information
|
| 102 |
-
fps = video.get(cv2.CAP_PROP_FPS)
|
| 103 |
-
|
| 104 |
-
# Create two columns for video display
|
| 105 |
-
col1, col2 = st.columns([0.5, 0.5])
|
| 106 |
-
with col1:
|
| 107 |
-
st.markdown('<p style="text-align: center;">Before</p>', unsafe_allow_html=True)
|
| 108 |
-
st.video(temp_file.name)
|
| 109 |
-
|
| 110 |
-
with col2:
|
| 111 |
-
st.markdown('<p style="text-align: center;">After</p>', unsafe_allow_html=True)
|
| 112 |
-
filter = st.sidebar.radio('Colorize your video with:',
|
| 113 |
-
['Original', 'ECCV 16', 'SIGGRAPH 17'])
|
| 114 |
-
if filter == 'ECCV 16':
|
| 115 |
-
colorizer = eccv16(pretrained=True).eval()
|
| 116 |
-
elif filter == 'SIGGRAPH 17':
|
| 117 |
-
colorizer = siggraph17(pretrained=True).eval()
|
| 118 |
-
|
| 119 |
-
if filter != 'Original':
|
| 120 |
-
with st.spinner("Colorizing frames..."):
|
| 121 |
-
# Colorize video frames and store in a list
|
| 122 |
-
output_frames = []
|
| 123 |
-
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 124 |
-
progress_bar = st.empty()
|
| 125 |
-
|
| 126 |
-
start_time = time.time()
|
| 127 |
-
for i in tqdm(range(total_frames), unit='frame', desc="Progress"):
|
| 128 |
-
ret, frame = video.read()
|
| 129 |
-
if not ret:
|
| 130 |
-
break
|
| 131 |
-
|
| 132 |
-
colorized_frame = colorize_frame(frame, colorizer)
|
| 133 |
-
output_frames.append((colorized_frame * 255).astype(np.uint8))
|
| 134 |
-
|
| 135 |
-
elapsed_time = time.time() - start_time
|
| 136 |
-
frames_completed = len(output_frames)
|
| 137 |
-
frames_remaining = total_frames - frames_completed
|
| 138 |
-
time_remaining = (frames_remaining / frames_completed) * elapsed_time
|
| 139 |
-
|
| 140 |
-
progress_bar.progress(frames_completed / total_frames)
|
| 141 |
-
|
| 142 |
-
if frames_completed < total_frames:
|
| 143 |
-
progress_bar.text(f"Time Remaining: {format_time(time_remaining)}")
|
| 144 |
-
else:
|
| 145 |
-
progress_bar.empty()
|
| 146 |
-
|
| 147 |
-
with st.spinner("Merging frames to video..."):
|
| 148 |
-
frame_size = output_frames[0].shape[:2]
|
| 149 |
-
output_filename = "output.mp4"
|
| 150 |
-
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
|
| 151 |
-
out = cv2.VideoWriter(output_filename, fourcc, fps, (frame_size[1], frame_size[0]))
|
| 152 |
-
|
| 153 |
-
# Display the colorized video using st.video
|
| 154 |
-
for frame in output_frames:
|
| 155 |
-
frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
| 156 |
-
|
| 157 |
-
out.write(frame_bgr)
|
| 158 |
-
|
| 159 |
-
out.release()
|
| 160 |
-
|
| 161 |
-
# Convert the output video to a format compatible with Streamlit
|
| 162 |
-
converted_filename = "converted_output.mp4"
|
| 163 |
-
clip = mp.VideoFileClip(output_filename)
|
| 164 |
-
clip.write_videofile(converted_filename, codec="libx264")
|
| 165 |
-
|
| 166 |
-
# Display the converted video using st.video()
|
| 167 |
-
st.video(converted_filename)
|
| 168 |
-
|
| 169 |
-
# Add a download button for the colorized video
|
| 170 |
-
st.download_button(
|
| 171 |
-
label="Download Colorized Video",
|
| 172 |
-
data=open(converted_filename, "rb").read(),
|
| 173 |
-
file_name="colorized_video.mp4"
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
# Close and delete the temporary file after processing
|
| 177 |
-
video.release()
|
| 178 |
-
temp_file.close()
|
| 179 |
-
|
| 180 |
-
# Add a feedback section in the sidebar
|
| 181 |
-
st.sidebar.title(' ') # Used to create some space between the filter widget and the comments section
|
| 182 |
-
st.sidebar.markdown(' ') # Used to create some space between the filter widget and the comments section
|
| 183 |
-
st.sidebar.subheader('Please help us improve!')
|
| 184 |
-
with st.sidebar.form(key='columns_in_form',
|
| 185 |
-
clear_on_submit=True): # set clear_on_submit=True so that the form will be reset/cleared once
|
| 186 |
-
# it's submitted
|
| 187 |
-
rating = st.slider("Please rate the app", min_value=1, max_value=5, value=3,
|
| 188 |
-
help='Drag the slider to rate the app. This is a 1-5 rating scale where 5 is the highest rating')
|
| 189 |
-
text = st.text_input(label='Please leave your feedback here')
|
| 190 |
-
submitted = st.form_submit_button('Submit')
|
| 191 |
-
if submitted:
|
| 192 |
-
st.write('Thanks for your feedback!')
|
| 193 |
-
st.markdown('Your Rating:')
|
| 194 |
-
st.markdown(rating)
|
| 195 |
-
st.markdown('Your Feedback:')
|
| 196 |
-
st.markdown(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img/color_revive.png
DELETED
|
Binary file (13.3 kB)
|
|
|
img/streamlit.png
DELETED
|
Binary file (6.12 kB)
|
|
|
pages/02_🎥_Input_Youtube_Link.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_lottie import st_lottie
|
| 3 |
+
from models.deep_colorization.colorizers import *
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Image & Video Colorizer", page_icon="🎨", layout="wide")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Define a function that we can use to load lottie files from a link.
|
| 10 |
+
def load_lottieurl(url: str):
|
| 11 |
+
r = requests.get(url)
|
| 12 |
+
if r.status_code != 200:
|
| 13 |
+
return None
|
| 14 |
+
return r.json()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 18 |
+
current_model = "None"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def change_model(current_model, model):
|
| 22 |
+
if current_model != model:
|
| 23 |
+
if model == "ECCV16":
|
| 24 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 25 |
+
elif model == "SIGGRAPH17":
|
| 26 |
+
loaded_model = siggraph17(pretrained=True).eval()
|
| 27 |
+
return loaded_model
|
| 28 |
+
else:
|
| 29 |
+
raise Exception("Model is the same as the current one.")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
col1, col2 = st.columns([1, 3])
|
| 33 |
+
with col1:
|
| 34 |
+
lottie = load_lottieurl("https://assets5.lottiefiles.com/packages/lf20_RHdEuzVfEL.json")
|
| 35 |
+
st_lottie(lottie)
|
| 36 |
+
|
| 37 |
+
with col2:
|
| 38 |
+
st.write("""
|
| 39 |
+
## B&W Videos Colorizer
|
| 40 |
+
##### Input a YouTube black and white video link and get a colorized version of it.
|
| 41 |
+
###### I recommend starting with the first model and then experimenting with the second one.""")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
model = st.selectbox(
|
| 46 |
+
"Select Model (Both models have their pros and cons, I recommend to try both and keep the best for you task)",
|
| 47 |
+
["ECCV16", "SIGGRAPH17"], index=0)
|
| 48 |
+
|
| 49 |
+
loaded_model = change_model(current_model, model)
|
| 50 |
+
st.write(f"Model is now {model}")
|
| 51 |
+
|
| 52 |
+
link = st.text_input("YouTube Link (The longer the video, the longer the processing time)")
|
| 53 |
+
if st.button("Colorize"):
|
| 54 |
+
print("yo")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
| 59 |
+
st.markdown(
|
| 60 |
+
"###### Made with :heart: by [Clément Delteil](https://www.linkedin.com/in/clementdelteil/) [](https://www.buymeacoffee.com/clementdelteil)")
|
pages/03_🖼️_Input_Images.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_lottie import st_lottie
|
| 3 |
+
from models.deep_colorization.colorizers import *
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Image & Video Colorizer", page_icon="🎨", layout="wide")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Define a function that we can use to load lottie files from a link.
|
| 10 |
+
def load_lottieurl(url: str):
|
| 11 |
+
r = requests.get(url)
|
| 12 |
+
if r.status_code != 200:
|
| 13 |
+
return None
|
| 14 |
+
return r.json()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 18 |
+
current_model = "None"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def change_model(current_model, model):
|
| 22 |
+
if current_model != model:
|
| 23 |
+
if model == "ECCV16":
|
| 24 |
+
loaded_model = eccv16(pretrained=True).eval()
|
| 25 |
+
elif model == "SIGGRAPH17":
|
| 26 |
+
loaded_model = siggraph17(pretrained=True).eval()
|
| 27 |
+
return loaded_model
|
| 28 |
+
else:
|
| 29 |
+
raise Exception("Model is the same as the current one.")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
col1, col2 = st.columns([1, 3])
|
| 33 |
+
with col1:
|
| 34 |
+
lottie = load_lottieurl("https://assets5.lottiefiles.com/packages/lf20_RHdEuzVfEL.json")
|
| 35 |
+
st_lottie(lottie)
|
| 36 |
+
|
| 37 |
+
with col2:
|
| 38 |
+
st.write("""
|
| 39 |
+
## B&W Videos Colorizer
|
| 40 |
+
##### Input a YouTube black and white video link and get a colorized version of it.
|
| 41 |
+
###### I recommend starting with the first model and then experimenting with the second one.""")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
model = st.selectbox(
|
| 46 |
+
"Select Model (Both models have their pros and cons, I recommend to try both and keep the best for you task)",
|
| 47 |
+
["ECCV16", "SIGGRAPH17"], index=0)
|
| 48 |
+
|
| 49 |
+
loaded_model = change_model(current_model, model)
|
| 50 |
+
st.write(f"Model is now {model}")
|
| 51 |
+
|
| 52 |
+
link = st.text_input("YouTube Link (The longer the video, the longer the processing time)")
|
| 53 |
+
if st.button("Colorize"):
|
| 54 |
+
print("yo")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
| 59 |
+
st.markdown(
|
| 60 |
+
"###### Made with :heart: by [Clément Delteil](https://www.linkedin.com/in/clementdelteil/) [](https://www.buymeacoffee.com/clementdelteil)")
|
requirements.txt
CHANGED
|
@@ -2,10 +2,12 @@ ipython==8.5.0
|
|
| 2 |
moviepy==1.0.3
|
| 3 |
numpy==1.23.2
|
| 4 |
opencv_python==4.7.0.68
|
|
|
|
| 5 |
Pillow==9.5.0
|
| 6 |
-
|
| 7 |
streamlit==1.22.0
|
| 8 |
torch==1.13.1
|
|
|
|
| 9 |
tqdm==4.64.1
|
| 10 |
|
| 11 |
|
|
|
|
| 2 |
moviepy==1.0.3
|
| 3 |
numpy==1.23.2
|
| 4 |
opencv_python==4.7.0.68
|
| 5 |
+
Pillow==9.4.0
|
| 6 |
Pillow==9.5.0
|
| 7 |
+
skimage==0.0
|
| 8 |
streamlit==1.22.0
|
| 9 |
torch==1.13.1
|
| 10 |
+
requests==2.28.1
|
| 11 |
tqdm==4.64.1
|
| 12 |
|
| 13 |
|
utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import numpy as np
|
| 3 |
+
from models.deep_colorization.colorizers import postprocess_tens, preprocess_img
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Define a function that we can use to load lottie files from a link.
|
| 7 |
+
def load_lottieurl(url: str):
|
| 8 |
+
r = requests.get(url)
|
| 9 |
+
if r.status_code != 200:
|
| 10 |
+
return None
|
| 11 |
+
return r.json()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def format_time(seconds: float) -> str:
|
| 15 |
+
"""Formats time in seconds to a human readable format"""
|
| 16 |
+
if seconds < 60:
|
| 17 |
+
return f"{int(seconds)} seconds"
|
| 18 |
+
elif seconds < 3600:
|
| 19 |
+
minutes = seconds // 60
|
| 20 |
+
seconds %= 60
|
| 21 |
+
return f"{minutes} minutes and {int(seconds)} seconds"
|
| 22 |
+
elif seconds < 86400:
|
| 23 |
+
hours = seconds // 3600
|
| 24 |
+
minutes = (seconds % 3600) // 60
|
| 25 |
+
seconds %= 60
|
| 26 |
+
return f"{hours} hours, {minutes} minutes, and {int(seconds)} seconds"
|
| 27 |
+
else:
|
| 28 |
+
days = seconds // 86400
|
| 29 |
+
hours = (seconds % 86400) // 3600
|
| 30 |
+
minutes = (seconds % 3600) // 60
|
| 31 |
+
seconds %= 60
|
| 32 |
+
return f"{days} days, {hours} hours, {minutes} minutes, and {int(seconds)} seconds"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Function to colorize video frames
|
| 36 |
+
def colorize_frame(frame, colorizer) -> np.ndarray:
|
| 37 |
+
tens_l_orig, tens_l_rs = preprocess_img(frame, HW=(256, 256))
|
| 38 |
+
return postprocess_tens(tens_l_orig, colorizer(tens_l_rs).cpu())
|