Wazzzabeee commited on
Commit
abe6b41
โ€ข
1 Parent(s): acdcc6a

Update 01_๐Ÿ“ผ_Upload_Video_File.py

Browse files
Files changed (1) hide show
  1. 01_๐Ÿ“ผ_Upload_Video_File.py +16 -23
01_๐Ÿ“ผ_Upload_Video_File.py CHANGED
@@ -1,32 +1,22 @@
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")
@@ -36,7 +26,7 @@ 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
- ###### โž  If you want to colorize multiple videos just upload them one by one.
40
  ###### โž  This space is using CPU Basic so it might take a while to colorize a video.
41
  ###### โž  If you want more models and GPU available please support this space by donating.""")
42
 
@@ -79,10 +69,12 @@ def main():
79
  # Colorize video frames and store in a list
80
  output_frames = []
81
  total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
82
- progress_bar = st.empty()
83
 
84
  start_time = time.time()
85
- for i in tqdm(range(total_frames), unit='frame', desc="Progress"):
 
 
86
  ret, frame = video.read()
87
  if not ret:
88
  break
@@ -95,11 +87,12 @@ def main():
95
  frames_remaining = total_frames - frames_completed
96
  time_remaining = (frames_remaining / frames_completed) * elapsed_time
97
 
98
- progress_bar.progress(frames_completed / total_frames)
99
 
100
  if frames_completed < total_frames:
101
- progress_bar.text(f"Time Remaining: {format_time(time_remaining)}")
102
  else:
 
103
  progress_bar.empty()
104
 
105
  with st.spinner("Merging frames to video..."):
 
 
 
 
 
1
  import os
2
  import tempfile
3
+ import time
4
+
5
  import cv2
6
  import moviepy.editor as mp
7
+ import numpy as np
8
+ import streamlit as st
9
+ from streamlit_lottie import st_lottie
10
  from tqdm import tqdm
11
 
12
+ from models.deep_colorization.colorizers import eccv16
13
+ from utils import load_lottieurl, format_time, colorize_frame, change_model
14
 
15
+ st.set_page_config(page_title="Image & Video Colorizer", page_icon="๐ŸŽจ", layout="wide")
16
 
17
  loaded_model = eccv16(pretrained=True).eval()
18
  current_model = "None"
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  col1, col2 = st.columns([1, 3])
21
  with col1:
22
  lottie = load_lottieurl("https://assets5.lottiefiles.com/packages/lf20_RHdEuzVfEL.json")
 
26
  st.write("""
27
  ## B&W Videos Colorizer
28
  ##### Upload a black and white video and get a colorized version of it.
29
+ ###### โž  If you want to colorize multiple videos just upload them all at once.
30
  ###### โž  This space is using CPU Basic so it might take a while to colorize a video.
31
  ###### โž  If you want more models and GPU available please support this space by donating.""")
32
 
 
69
  # Colorize video frames and store in a list
70
  output_frames = []
71
  total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
72
+ progress_bar = st.progress(0) # Create a progress bar
73
 
74
  start_time = time.time()
75
+ time_text = st.text("Time Remaining: ") # Initialize text value
76
+
77
+ for _ in tqdm(range(total_frames), unit='frame', desc="Progress"):
78
  ret, frame = video.read()
79
  if not ret:
80
  break
 
87
  frames_remaining = total_frames - frames_completed
88
  time_remaining = (frames_remaining / frames_completed) * elapsed_time
89
 
90
+ progress_bar.progress(frames_completed / total_frames) # Update progress bar
91
 
92
  if frames_completed < total_frames:
93
+ time_text.text(f"Time Remaining: {format_time(time_remaining)}") # Update text value
94
  else:
95
+ time_text.empty() # Remove text value
96
  progress_bar.empty()
97
 
98
  with st.spinner("Merging frames to video..."):