Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,12 +40,15 @@ if uploaded_video is not None:
|
|
40 |
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
41 |
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
42 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
|
43 |
|
44 |
# Create a VideoWriter object to save the colorized video
|
45 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
46 |
out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
|
47 |
|
|
|
48 |
frame_count = 0
|
|
|
49 |
stframe = st.empty() # Placeholder for showing frames in Streamlit
|
50 |
|
51 |
# Process each frame
|
@@ -55,7 +58,8 @@ if uploaded_video is not None:
|
|
55 |
break
|
56 |
|
57 |
frame_count += 1
|
58 |
-
|
|
|
59 |
# Convert frame to LAB color space and preprocess
|
60 |
normalized = frame.astype("float32") / 255.0
|
61 |
lab = cv2.cvtColor(normalized, cv2.COLOR_BGR2LAB)
|
@@ -74,7 +78,9 @@ if uploaded_video is not None:
|
|
74 |
colorized = cv2.cvtColor(colorized, cv2.COLOR_LAB2BGR)
|
75 |
colorized = (255 * colorized).astype("uint8")
|
76 |
|
77 |
-
|
|
|
|
|
78 |
|
79 |
# Write colorized frame to output
|
80 |
out.write(colorized)
|
@@ -86,4 +92,4 @@ if uploaded_video is not None:
|
|
86 |
# Provide a download link for the colorized video
|
87 |
st.success("Video colorization completed!")
|
88 |
with open(output_path, "rb") as file:
|
89 |
-
|
|
|
40 |
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
41 |
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
42 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
43 |
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
44 |
|
45 |
# Create a VideoWriter object to save the colorized video
|
46 |
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
47 |
out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
|
48 |
|
49 |
+
# Initialize progress bar and frame counter
|
50 |
frame_count = 0
|
51 |
+
progress_bar = st.progress(0)
|
52 |
stframe = st.empty() # Placeholder for showing frames in Streamlit
|
53 |
|
54 |
# Process each frame
|
|
|
58 |
break
|
59 |
|
60 |
frame_count += 1
|
61 |
+
st.write(f"Processing frame {frame_count} of {total_frames}")
|
62 |
+
|
63 |
# Convert frame to LAB color space and preprocess
|
64 |
normalized = frame.astype("float32") / 255.0
|
65 |
lab = cv2.cvtColor(normalized, cv2.COLOR_BGR2LAB)
|
|
|
78 |
colorized = cv2.cvtColor(colorized, cv2.COLOR_LAB2BGR)
|
79 |
colorized = (255 * colorized).astype("uint8")
|
80 |
|
81 |
+
# Update the progress bar and display the current frame in Streamlit
|
82 |
+
progress_bar.progress(frame_count / total_frames)
|
83 |
+
stframe.image(colorized, channels="BGR", caption=f"Colorized Frame {frame_count}")
|
84 |
|
85 |
# Write colorized frame to output
|
86 |
out.write(colorized)
|
|
|
92 |
# Provide a download link for the colorized video
|
93 |
st.success("Video colorization completed!")
|
94 |
with open(output_path, "rb") as file:
|
95 |
+
st.download_button(label="Download Colorized Video", data=file, file_name="colorized_video.mp4", mime="video/mp4")
|