ledetele commited on
Commit
2d0131e
·
1 Parent(s): fbd128f

Rename pages/02_Input_Youtube_Link.py to pages/输入Youtube链接

Browse files
pages/{02_Input_Youtube_Link.py → 输入Youtube链接} RENAMED
@@ -18,11 +18,11 @@ from utils import load_lottieurl, change_model
18
  loaded_model = eccv16(pretrained=True).eval()
19
  current_model = "None"
20
 
21
- st.title("Image & Video Colorizer")
22
 
23
  st.write("""
24
- ##### Input a YouTube black and white video link and get a colorized version of it.
25
- ###### ➠ This space is using CPU Basic so it might take a while to colorize a video.""")
26
 
27
  @st.cache_data()
28
  def download_video(link):
@@ -33,25 +33,25 @@ def download_video(link):
33
 
34
  def main():
35
  model = st.selectbox(
36
- "Select Model (Both models have their pros and cons, I recommend trying both and keeping the best for you task)",
37
  ["ECCV16", "SIGGRAPH17"], index=0)
38
 
39
  loaded_model = change_model(current_model, model)
40
- st.write(f"Model is now {model}")
41
 
42
- link = st.text_input("YouTube Link (The longer the video, the longer the processing time)")
43
- if st.button("Colorize"):
44
  if link is not "":
45
  print(link)
46
  yt_video = download_video(link)
47
  print(yt_video)
48
  col1, col2 = st.columns([0.5, 0.5])
49
  with col1:
50
- st.markdown('<p style="text-align: center;">Before</p>', unsafe_allow_html=True)
51
  st.video(yt_video)
52
  with col2:
53
- st.markdown('<p style="text-align: center;">After</p>', unsafe_allow_html=True)
54
- with st.spinner("Colorizing frames..."):
55
  # Colorize video frames and store in a list
56
  output_frames = []
57
 
@@ -63,7 +63,7 @@ def main():
63
 
64
  progress_bar = st.progress(0) # Create a progress bar
65
  start_time = time.time()
66
- time_text = st.text("Time Remaining: ") # Initialize text value
67
 
68
  for _ in tqdm(range(total_frames), unit='frame', desc="Progress"):
69
  ret, frame = video.read()
@@ -81,12 +81,12 @@ def main():
81
  progress_bar.progress(frames_completed / total_frames) # Update progress bar
82
 
83
  if frames_completed < total_frames:
84
- time_text.text(f"Time Remaining: {format_time(time_remaining)}") # Update text value
85
  else:
86
  time_text.empty() # Remove text value
87
  progress_bar.empty()
88
 
89
- with st.spinner("Merging frames to video..."):
90
  frame_size = output_frames[0].shape[:2]
91
  output_filename = "output.mp4"
92
  fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
@@ -121,7 +121,7 @@ def main():
121
  # Close and delete the temporary file after processing
122
  video.release()
123
  else:
124
- st.warning('Please Type a link', icon="⚠️")
125
 
126
 
127
  if __name__ == "__main__":
 
18
  loaded_model = eccv16(pretrained=True).eval()
19
  current_model = "None"
20
 
21
+ st.title("图像和视频着色器")
22
 
23
  st.write("""
24
+ ##### 输入 YouTube 黑白视频链接并获取其彩色版本。
25
+ ###### ➠ 空间使用 CPU Basic,因此可能需要一段时间才能对视频进行着色。""")
26
 
27
  @st.cache_data()
28
  def download_video(link):
 
33
 
34
  def main():
35
  model = st.selectbox(
36
+ "选择模型(两种模型都有其优点和缺点,建议尝试两种模型并保持最适合您的任务)",
37
  ["ECCV16", "SIGGRAPH17"], index=0)
38
 
39
  loaded_model = change_model(current_model, model)
40
+ st.write(f"现在是 {model}")
41
 
42
+ link = st.text_input("YouTube链接(视频越长,处理时间越长)")
43
+ if st.button("着色"):
44
  if link is not "":
45
  print(link)
46
  yt_video = download_video(link)
47
  print(yt_video)
48
  col1, col2 = st.columns([0.5, 0.5])
49
  with col1:
50
+ st.markdown('<p style="text-align: center;">处理前</p>', unsafe_allow_html=True)
51
  st.video(yt_video)
52
  with col2:
53
+ st.markdown('<p style="text-align: center;">处理后</p>', unsafe_allow_html=True)
54
+ with st.spinner("上色中..."):
55
  # Colorize video frames and store in a list
56
  output_frames = []
57
 
 
63
 
64
  progress_bar = st.progress(0) # Create a progress bar
65
  start_time = time.time()
66
+ time_text = st.text("剩余时间:") # Initialize text value
67
 
68
  for _ in tqdm(range(total_frames), unit='frame', desc="Progress"):
69
  ret, frame = video.read()
 
81
  progress_bar.progress(frames_completed / total_frames) # Update progress bar
82
 
83
  if frames_completed < total_frames:
84
+ time_text.text(f"剩余时间: {format_time(time_remaining)}") # Update text value
85
  else:
86
  time_text.empty() # Remove text value
87
  progress_bar.empty()
88
 
89
+ with st.spinner("将帧合并成视频..."):
90
  frame_size = output_frames[0].shape[:2]
91
  output_filename = "output.mp4"
92
  fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
 
121
  # Close and delete the temporary file after processing
122
  video.release()
123
  else:
124
+ st.warning('请输入链接', icon="⚠️")
125
 
126
 
127
  if __name__ == "__main__":