ledetele commited on
Commit
7540394
·
1 Parent(s): ccad50b

Rename pages/02_输入Youtube链接.py to pages/02_輸入Youtube鏈接.py

Browse files
pages/{02_输入Youtube链接.py → 02_輸入Youtube鏈接.py} 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("图像和视频着色器")
22
 
23
  st.write("""
24
- ##### 输入 YouTube 黑白视频链接并获取其彩色版本。
25
- ###### ➠ 空间使用 CPU Basic,因此可能需要一段时间才能对视频进行着色。""")
26
 
27
  @st.cache_data()
28
  def download_video(link):
@@ -33,13 +33,13 @@ 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)
@@ -47,10 +47,10 @@ def main():
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 = []
@@ -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("剩余时间:") # 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"剩余时间: {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
@@ -113,7 +113,7 @@ def main():
113
 
114
  # Add a download button for the colorized video
115
  st.download_button(
116
- label="Download Colorized Video",
117
  data=open(converted_filename, "rb").read(),
118
  file_name="colorized_video.mp4"
119
  )
@@ -121,7 +121,7 @@ def main():
121
  # Close and delete the temporary file after processing
122
  video.release()
123
  else:
124
- st.warning('请输入链接', 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)
 
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 = []
 
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
 
113
 
114
  # Add a download button for the colorized video
115
  st.download_button(
116
+ label="下載彩色影片",
117
  data=open(converted_filename, "rb").read(),
118
  file_name="colorized_video.mp4"
119
  )
 
121
  # Close and delete the temporary file after processing
122
  video.release()
123
  else:
124
+ st.warning('請輸入鏈接', icon="⚠️")
125
 
126
 
127
  if __name__ == "__main__":