Spaces:
Runtime error
Runtime error
Rename 01_B&W_Videos_Colorizer.py to 01_黑白影视着色器.py
Browse files
01_B&W_Videos_Colorizer.py → 01_黑白影视着色器.py
RENAMED
@@ -14,28 +14,28 @@ from tqdm import tqdm
|
|
14 |
from models.deep_colorization.colorizers import eccv16
|
15 |
from utils import load_lottieurl, format_time, colorize_frame, change_model
|
16 |
|
17 |
-
st.title("
|
18 |
|
19 |
st.write("""
|
20 |
-
#####
|
21 |
-
###### ➠
|
22 |
|
23 |
-
#st.set_page_config(page_title="
|
24 |
|
25 |
loaded_model = eccv16(pretrained=True).eval()
|
26 |
current_model = "None"
|
27 |
|
28 |
def main():
|
29 |
model = st.selectbox(
|
30 |
-
"
|
31 |
["ECCV16", "SIGGRAPH17"], index=0)
|
32 |
|
33 |
loaded_model = change_model(current_model, model)
|
34 |
-
st.write(f"
|
35 |
|
36 |
-
uploaded_file = st.file_uploader("
|
37 |
|
38 |
-
if st.button("
|
39 |
if uploaded_file is not None:
|
40 |
file_extension = os.path.splitext(uploaded_file.name)[1].lower()
|
41 |
if file_extension in ['.mp4', '.avi', '.mov', '.mkv']:
|
@@ -53,20 +53,20 @@ def main():
|
|
53 |
|
54 |
col1, col2 = st.columns([0.5, 0.5])
|
55 |
with col1:
|
56 |
-
st.markdown('<p style="text-align: center;"
|
57 |
st.video(temp_file.name)
|
58 |
|
59 |
with col2:
|
60 |
-
st.markdown('<p style="text-align: center;"
|
61 |
|
62 |
-
with st.spinner("
|
63 |
# Colorize video frames and store in a list
|
64 |
output_frames = []
|
65 |
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
66 |
progress_bar = st.progress(0) # Create a progress bar
|
67 |
|
68 |
start_time = time.time()
|
69 |
-
time_text = st.text("
|
70 |
|
71 |
for _ in tqdm(range(total_frames), unit='frame', desc="Progress"):
|
72 |
ret, frame = video.read()
|
@@ -89,7 +89,7 @@ def main():
|
|
89 |
time_text.empty() # Remove text value
|
90 |
progress_bar.empty()
|
91 |
|
92 |
-
with st.spinner("
|
93 |
frame_size = output_frames[0].shape[:2]
|
94 |
output_filename = "output.mp4"
|
95 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
|
@@ -116,7 +116,7 @@ def main():
|
|
116 |
|
117 |
# Add a download button for the colorized video
|
118 |
st.download_button(
|
119 |
-
label="
|
120 |
data=open(converted_filename, "rb").read(),
|
121 |
file_name="colorized_video.mp4"
|
122 |
)
|
|
|
14 |
from models.deep_colorization.colorizers import eccv16
|
15 |
from utils import load_lottieurl, format_time, colorize_frame, change_model
|
16 |
|
17 |
+
st.title("黑白影视着色器")
|
18 |
|
19 |
st.write("""
|
20 |
+
##### 上传黑白视频并获得其彩色版本。
|
21 |
+
###### ➠ 空间使用的是 CPU Basic,因此对视频进行彩色化可能需要一些时间。""")
|
22 |
|
23 |
+
#st.set_page_config(page_title="黑白影视着色器", page_icon="🎨", layout="wide")
|
24 |
|
25 |
loaded_model = eccv16(pretrained=True).eval()
|
26 |
current_model = "None"
|
27 |
|
28 |
def main():
|
29 |
model = st.selectbox(
|
30 |
+
"选择模型(两种模型都有其优点和缺点,建议尝试两种模型并保持最适合您的任务)",
|
31 |
["ECCV16", "SIGGRAPH17"], index=0)
|
32 |
|
33 |
loaded_model = change_model(current_model, model)
|
34 |
+
st.write(f"现在是 {model}")
|
35 |
|
36 |
+
uploaded_file = st.file_uploader("在这里上传您的视频...", type=['mp4', 'mov', 'avi', 'mkv'])
|
37 |
|
38 |
+
if st.button("着色"):
|
39 |
if uploaded_file is not None:
|
40 |
file_extension = os.path.splitext(uploaded_file.name)[1].lower()
|
41 |
if file_extension in ['.mp4', '.avi', '.mov', '.mkv']:
|
|
|
53 |
|
54 |
col1, col2 = st.columns([0.5, 0.5])
|
55 |
with col1:
|
56 |
+
st.markdown('<p style="text-align: center;">之前</p>', unsafe_allow_html=True)
|
57 |
st.video(temp_file.name)
|
58 |
|
59 |
with col2:
|
60 |
+
st.markdown('<p style="text-align: center;">之后</p>', unsafe_allow_html=True)
|
61 |
|
62 |
+
with st.spinner("上色中..."):
|
63 |
# Colorize video frames and store in a list
|
64 |
output_frames = []
|
65 |
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
66 |
progress_bar = st.progress(0) # Create a progress bar
|
67 |
|
68 |
start_time = time.time()
|
69 |
+
time_text = st.text("剩余时间:") # Initialize text value
|
70 |
|
71 |
for _ in tqdm(range(total_frames), unit='frame', desc="Progress"):
|
72 |
ret, frame = video.read()
|
|
|
89 |
time_text.empty() # Remove text value
|
90 |
progress_bar.empty()
|
91 |
|
92 |
+
with st.spinner("将帧合并到视频..."):
|
93 |
frame_size = output_frames[0].shape[:2]
|
94 |
output_filename = "output.mp4"
|
95 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
|
|
|
116 |
|
117 |
# Add a download button for the colorized video
|
118 |
st.download_button(
|
119 |
+
label="下载彩色视频",
|
120 |
data=open(converted_filename, "rb").read(),
|
121 |
file_name="colorized_video.mp4"
|
122 |
)
|