Spaces:
Running
Running
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)
|
@@ -57,18 +57,68 @@ st.markdown("""
|
|
57 |
Early wildfire detection using YOLOv8 AI vision model. See examples below or upload your own content!
|
58 |
""")
|
59 |
|
60 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
st.header("Example Results")
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
st.header("Your Results")
|
74 |
result_cols = st.columns(2)
|
@@ -115,7 +165,6 @@ 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 |
-
# 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)
|
|
|
11 |
|
12 |
# Page config first
|
13 |
st.set_page_config(
|
14 |
+
page_title="WildfireWatch: AI Detection",
|
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", 25, 100, 40)) / 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 Wildfire")
|
44 |
progress_bar = st.progress(0)
|
45 |
progress_text = st.empty()
|
46 |
download_slot = st.empty()
|
47 |
|
48 |
# Main page
|
49 |
+
st.title("WildfireWatch: AI-Powered 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)
|
|
|
57 |
Early wildfire detection using YOLOv8 AI vision model. See examples below or upload your own content!
|
58 |
""")
|
59 |
|
60 |
+
# Function to create synchronized video pair HTML
|
61 |
+
def create_synced_video_pair(orig_data, proc_data, pair_id):
|
62 |
+
orig_b64 = requests.get(orig_data).content.encode('base64').decode()
|
63 |
+
proc_b64 = requests.get(proc_data).content.encode('base64').decode()
|
64 |
+
html = f"""
|
65 |
+
<div style="display: flex; justify-content: space-between;">
|
66 |
+
<div style="width: 48%;">
|
67 |
+
<h4>Original</h4>
|
68 |
+
<video id="orig_{pair_id}" width="100%" controls>
|
69 |
+
<source src="data:video/mp4;base64,{orig_b64}" type="video/mp4">
|
70 |
+
</video>
|
71 |
+
</div>
|
72 |
+
<div style="width: 48%;">
|
73 |
+
<h4>Processed</h4>
|
74 |
+
<video id="proc_{pair_id}" width="100%" controls>
|
75 |
+
<source src="data:video/mp4;base64,{proc_b64}" type="video/mp4">
|
76 |
+
</video>
|
77 |
+
</div>
|
78 |
+
</div>
|
79 |
+
<script>
|
80 |
+
const origVideo_{pair_id} = document.getElementById('orig_{pair_id}');
|
81 |
+
const procVideo_{pair_id} = document.getElementById('proc_{pair_id}');
|
82 |
+
|
83 |
+
origVideo_{pair_id}.addEventListener('play', function() {{
|
84 |
+
procVideo_{pair_id}.currentTime = origVideo_{pair_id}.currentTime;
|
85 |
+
procVideo_{pair_id}.play();
|
86 |
+
}});
|
87 |
+
procVideo_{pair_id}.addEventListener('play', function() {{
|
88 |
+
origVideo_{pair_id}.currentTime = procVideo_{pair_id}.currentTime;
|
89 |
+
origVideo_{pair_id}.play();
|
90 |
+
}});
|
91 |
+
|
92 |
+
origVideo_{pair_id}.addEventListener('pause', function() {{
|
93 |
+
procVideo_{pair_id}.pause();
|
94 |
+
}});
|
95 |
+
procVideo_{pair_id}.addEventListener('pause', function() {{
|
96 |
+
origVideo_{pair_id}.pause();
|
97 |
+
}});
|
98 |
+
|
99 |
+
origVideo_{pair_id}.addEventListener('seeked', function() {{
|
100 |
+
procVideo_{pair_id}.currentTime = origVideo_{pair_id}.currentTime;
|
101 |
+
}});
|
102 |
+
procVideo_{pair_id}.addEventListener('seeked', function() {{
|
103 |
+
origVideo_{pair_id}.currentTime = procVideo_{pair_id}.currentTime;
|
104 |
+
}});
|
105 |
+
</script>
|
106 |
+
"""
|
107 |
+
return html
|
108 |
+
|
109 |
+
# Example videos with synchronization
|
110 |
st.header("Example Results")
|
111 |
+
examples = [
|
112 |
+
("T Example", "T1.mp4", "T2.mpg"),
|
113 |
+
("LA Example", "LA1.mp4", "LA2.mp4")
|
114 |
+
]
|
115 |
+
for title, orig_file, proc_file in examples:
|
116 |
+
st.subheader(title)
|
117 |
+
orig_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{orig_file}"
|
118 |
+
proc_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{proc_file}"
|
119 |
+
pair_id = title.replace(" ", "").lower()
|
120 |
+
video_html = create_synced_video_pair(orig_url, proc_url, pair_id)
|
121 |
+
st.markdown(video_html, unsafe_allow_html=True)
|
122 |
|
123 |
st.header("Your Results")
|
124 |
result_cols = st.columns(2)
|
|
|
165 |
if frame_count % sample_interval == 0:
|
166 |
res = model.predict(frame, conf=confidence)
|
167 |
processed_frame = res[0].plot()[:, :, ::-1]
|
|
|
168 |
if not processed_frame.flags['C_CONTIGUOUS']:
|
169 |
processed_frame = np.ascontiguousarray(processed_frame)
|
170 |
st.session_state.processed_frames.append(processed_frame)
|