Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ import imageio_ffmpeg as ffmpeg
|
|
| 11 |
|
| 12 |
# Page config first
|
| 13 |
st.set_page_config(
|
| 14 |
-
page_title="
|
| 15 |
page_icon="🔥",
|
| 16 |
layout="wide",
|
| 17 |
initial_sidebar_state="expanded"
|
|
@@ -29,7 +29,7 @@ for key in ["processed_frames", "slider_value", "processed_video", "start_time"]
|
|
| 29 |
with st.sidebar:
|
| 30 |
st.header("Upload & Settings")
|
| 31 |
source_file = st.file_uploader("Upload image/video", type=["jpg", "jpeg", "png", "bmp", "webp", "mp4"])
|
| 32 |
-
confidence = float(st.slider("Confidence Threshold",
|
| 33 |
fps_options = {
|
| 34 |
"Original FPS": None,
|
| 35 |
"3 FPS": 3,
|
|
@@ -40,13 +40,13 @@ with st.sidebar:
|
|
| 40 |
"1 frame/30s": 0.0333
|
| 41 |
}
|
| 42 |
video_option = st.selectbox("Output Frame Rate", list(fps_options.keys()))
|
| 43 |
-
process_button = st.button("Detect
|
| 44 |
progress_bar = st.progress(0)
|
| 45 |
progress_text = st.empty()
|
| 46 |
download_slot = st.empty()
|
| 47 |
|
| 48 |
# Main page
|
| 49 |
-
st.title("
|
| 50 |
col1, col2 = st.columns(2)
|
| 51 |
with col1:
|
| 52 |
st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_1.jpeg", use_column_width=True)
|
|
@@ -115,6 +115,9 @@ if process_button and source_file and model:
|
|
| 115 |
if frame_count % sample_interval == 0:
|
| 116 |
res = model.predict(frame, conf=confidence)
|
| 117 |
processed_frame = res[0].plot()[:, :, ::-1]
|
|
|
|
|
|
|
|
|
|
| 118 |
st.session_state.processed_frames.append(processed_frame)
|
| 119 |
|
| 120 |
processed_count += 1
|
|
@@ -140,14 +143,13 @@ if process_button and source_file and model:
|
|
| 140 |
|
| 141 |
if st.session_state.processed_frames:
|
| 142 |
out_path = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False).name
|
| 143 |
-
# Use imageio-ffmpeg instead of cv2 for more reliable MP4 output
|
| 144 |
writer = ffmpeg.write_frames(
|
| 145 |
out_path,
|
| 146 |
(width, height),
|
| 147 |
fps=output_fps or orig_fps,
|
| 148 |
-
codec='libx264',
|
| 149 |
-
pix_fmt_in='bgr24',
|
| 150 |
-
pix_fmt_out='yuv420p'
|
| 151 |
)
|
| 152 |
writer.send(None) # Initialize writer
|
| 153 |
|
|
|
|
| 11 |
|
| 12 |
# Page config first
|
| 13 |
st.set_page_config(
|
| 14 |
+
page_title="Fire Watch: AI model detection of fire and smoke",
|
| 15 |
page_icon="🔥",
|
| 16 |
layout="wide",
|
| 17 |
initial_sidebar_state="expanded"
|
|
|
|
| 29 |
with st.sidebar:
|
| 30 |
st.header("Upload & Settings")
|
| 31 |
source_file = st.file_uploader("Upload image/video", type=["jpg", "jpeg", "png", "bmp", "webp", "mp4"])
|
| 32 |
+
confidence = float(st.slider("Confidence Threshold", 10, 100, 20)) / 100
|
| 33 |
fps_options = {
|
| 34 |
"Original FPS": None,
|
| 35 |
"3 FPS": 3,
|
|
|
|
| 40 |
"1 frame/30s": 0.0333
|
| 41 |
}
|
| 42 |
video_option = st.selectbox("Output Frame Rate", list(fps_options.keys()))
|
| 43 |
+
process_button = st.button("Detect fire and smoke")
|
| 44 |
progress_bar = st.progress(0)
|
| 45 |
progress_text = st.empty()
|
| 46 |
download_slot = st.empty()
|
| 47 |
|
| 48 |
# Main page
|
| 49 |
+
st.title("Fire Watch: AI-Powered Fire Detection")
|
| 50 |
col1, col2 = st.columns(2)
|
| 51 |
with col1:
|
| 52 |
st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_1.jpeg", use_column_width=True)
|
|
|
|
| 115 |
if frame_count % sample_interval == 0:
|
| 116 |
res = model.predict(frame, conf=confidence)
|
| 117 |
processed_frame = res[0].plot()[:, :, ::-1]
|
| 118 |
+
# Ensure frame is C-contiguous
|
| 119 |
+
if not processed_frame.flags['C_CONTIGUOUS']:
|
| 120 |
+
processed_frame = np.ascontiguousarray(processed_frame)
|
| 121 |
st.session_state.processed_frames.append(processed_frame)
|
| 122 |
|
| 123 |
processed_count += 1
|
|
|
|
| 143 |
|
| 144 |
if st.session_state.processed_frames:
|
| 145 |
out_path = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False).name
|
|
|
|
| 146 |
writer = ffmpeg.write_frames(
|
| 147 |
out_path,
|
| 148 |
(width, height),
|
| 149 |
fps=output_fps or orig_fps,
|
| 150 |
+
codec='libx264',
|
| 151 |
+
pix_fmt_in='bgr24',
|
| 152 |
+
pix_fmt_out='yuv420p'
|
| 153 |
)
|
| 154 |
writer.send(None) # Initialize writer
|
| 155 |
|