tstone87 commited on
Commit
d1d880d
·
verified ·
1 Parent(s): b6a85bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -50,45 +50,53 @@ with st.sidebar:
50
  st.title("Fire Watch: AI-Powered Fire and Smoke Detection")
51
  col1, col2 = st.columns(2)
52
  with col1:
53
- st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_4.jpeg", use_column_width=True)
54
  with col2:
55
  st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_3.png", use_column_width=True)
56
 
57
  st.markdown("""
58
  Early wildfire detection using YOLOv8 AI vision model. See examples below or upload your own content!
 
59
  """)
60
 
61
- # Function to create synchronized video pair HTML
62
- def create_synced_video_pair(orig_url, proc_url, pair_id):
63
  try:
64
  orig_bytes = requests.get(orig_url).content
65
  proc_bytes = requests.get(proc_url).content
 
66
  orig_b64 = base64.b64encode(orig_bytes).decode('utf-8')
67
  proc_b64 = base64.b64encode(proc_bytes).decode('utf-8')
 
68
 
69
  html = f"""
70
- <div style="display: flex; gap: 10px; margin-bottom: 20px;">
71
- <div style="flex: 1;">
72
  <h4>Original</h4>
73
  <video id="orig_{pair_id}" width="100%" controls preload="metadata">
74
  <source src="data:video/mp4;base64,{orig_b64}" type="video/mp4">
75
  Your browser does not support the video tag.
76
  </video>
77
  </div>
78
- <div style="flex: 1;">
79
  <h4>Processed</h4>
80
  <video id="proc_{pair_id}" width="100%" controls preload="metadata">
81
  <source src="data:video/mp4;base64,{proc_b64}" type="video/mp4">
82
  Your browser does not support the video tag.
83
  </video>
84
  </div>
 
 
 
85
  </div>
86
  <script>
87
  document.addEventListener('DOMContentLoaded', function() {{
88
  const origVideo = document.getElementById('orig_{pair_id}');
89
  const procVideo = document.getElementById('proc_{pair_id}');
 
 
90
 
91
- if (origVideo && procVideo) {{
92
  origVideo.addEventListener('play', function() {{
93
  procVideo.currentTime = origVideo.currentTime;
94
  procVideo.play().catch(e => console.log('Play error:', e));
@@ -111,15 +119,23 @@ def create_synced_video_pair(orig_url, proc_url, pair_id):
111
  procVideo.addEventListener('seeked', function() {{
112
  origVideo.currentTime = procVideo.currentTime;
113
  }});
 
 
 
 
 
 
 
 
114
  }} else {{
115
- console.log('Video elements not found for {pair_id}');
116
  }}
117
  }});
118
  </script>
119
  """
120
  return html
121
  except Exception as e:
122
- return f"<p>Error loading videos: {str(e)}</p>"
123
 
124
  if not source_file:
125
  st.info("Please upload a file to begin.")
@@ -128,18 +144,19 @@ st.header("Your Results")
128
  result_cols = st.columns(2)
129
  viewer_slot = st.empty()
130
 
131
- # Example videos with synchronization
132
  st.header("Example Results")
133
  examples = [
134
- ("T Example", "T1.mp4", "T2.mp4"),
135
- ("LA Example", "LA1.mp4", "LA2.mp4")
136
  ]
137
- for title, orig_file, proc_file in examples:
138
  st.subheader(title)
139
  orig_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{orig_file}"
140
  proc_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{proc_file}"
 
141
  pair_id = title.replace(" ", "").lower()
142
- video_html = create_synced_video_pair(orig_url, proc_url, pair_id)
143
  st.markdown(video_html, unsafe_allow_html=True)
144
 
145
  # Load model
@@ -237,7 +254,7 @@ if process_button and source_file and model:
237
  download_slot.download_button(
238
  label="Download Processed Video",
239
  data=st.session_state.processed_video,
240
- file_name="processed_fire_video.mp4",
241
  mime="video/mp4"
242
  )
243
 
 
50
  st.title("Fire Watch: AI-Powered Fire and Smoke Detection")
51
  col1, col2 = st.columns(2)
52
  with col1:
53
+ st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_1.jpeg", use_column_width=True)
54
  with col2:
55
  st.image("https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/Fire_3.png", use_column_width=True)
56
 
57
  st.markdown("""
58
  Early wildfire detection using YOLOv8 AI vision model. See examples below or upload your own content!
59
+ Hover over example videos to see detection results!
60
  """)
61
 
62
+ # Function to create synchronized video pair HTML with hover images
63
+ def create_synced_video_pair(orig_url, proc_url, pair_id, hover_image_url):
64
  try:
65
  orig_bytes = requests.get(orig_url).content
66
  proc_bytes = requests.get(proc_url).content
67
+ hover_bytes = requests.get(hover_image_url).content
68
  orig_b64 = base64.b64encode(orig_bytes).decode('utf-8')
69
  proc_b64 = base64.b64encode(proc_bytes).decode('utf-8')
70
+ hover_b64 = base64.b64encode(hover_bytes).decode('utf-8')
71
 
72
  html = f"""
73
+ <div style="display: flex; gap: 10px; margin-bottom: 20px; position: relative;">
74
+ <div style="flex: 1; position: relative;">
75
  <h4>Original</h4>
76
  <video id="orig_{pair_id}" width="100%" controls preload="metadata">
77
  <source src="data:video/mp4;base64,{orig_b64}" type="video/mp4">
78
  Your browser does not support the video tag.
79
  </video>
80
  </div>
81
+ <div style="flex: 1; position: relative;">
82
  <h4>Processed</h4>
83
  <video id="proc_{pair_id}" width="100%" controls preload="metadata">
84
  <source src="data:video/mp4;base64,{proc_b64}" type="video/mp4">
85
  Your browser does not support the video tag.
86
  </video>
87
  </div>
88
+ <img id="hover_{pair_id}" src="data:image/jpeg;base64,{hover_b64}"
89
+ style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
90
+ max-width: 80%; max-height: 80%; display: none; z-index: 10;">
91
  </div>
92
  <script>
93
  document.addEventListener('DOMContentLoaded', function() {{
94
  const origVideo = document.getElementById('orig_{pair_id}');
95
  const procVideo = document.getElementById('proc_{pair_id}');
96
+ const hoverImg = document.getElementById('hover_{pair_id}');
97
+ const container = origVideo.parentElement.parentElement;
98
 
99
+ if (origVideo && procVideo && hoverImg) {{
100
  origVideo.addEventListener('play', function() {{
101
  procVideo.currentTime = origVideo.currentTime;
102
  procVideo.play().catch(e => console.log('Play error:', e));
 
119
  procVideo.addEventListener('seeked', function() {{
120
  origVideo.currentTime = procVideo.currentTime;
121
  }});
122
+
123
+ // Hover events
124
+ container.addEventListener('mouseover', function() {{
125
+ hoverImg.style.display = 'block';
126
+ }});
127
+ container.addEventListener('mouseout', function() {{
128
+ hoverImg.style.display = 'none';
129
+ }});
130
  }} else {{
131
+ console.log('Elements not found for {pair_id}');
132
  }}
133
  }});
134
  </script>
135
  """
136
  return html
137
  except Exception as e:
138
+ return f"<p>Error loading videos or hover image: {str(e)}</p>"
139
 
140
  if not source_file:
141
  st.info("Please upload a file to begin.")
 
144
  result_cols = st.columns(2)
145
  viewer_slot = st.empty()
146
 
147
+ # Example videos with synchronization and hover images
148
  st.header("Example Results")
149
  examples = [
150
+ ("T Example", "T1.mp4", "T2.mp4", "File_3a.jpg"),
151
+ ("LA Example", "LA1.mp4", "LA2.mp4", "File_4a.jpg")
152
  ]
153
+ for title, orig_file, proc_file, hover_file in examples:
154
  st.subheader(title)
155
  orig_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{orig_file}"
156
  proc_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{proc_file}"
157
+ hover_url = f"https://huggingface.co/spaces/tstone87/ccr-colorado/resolve/main/{hover_file}"
158
  pair_id = title.replace(" ", "").lower()
159
+ video_html = create_synced_video_pair(orig_url, proc_url, pair_id, hover_url)
160
  st.markdown(video_html, unsafe_allow_html=True)
161
 
162
  # Load model
 
254
  download_slot.download_button(
255
  label="Download Processed Video",
256
  data=st.session_state.processed_video,
257
+ file_name="processed_wildfire.mp4",
258
  mime="video/mp4"
259
  )
260