tstone87 commited on
Commit
aaa9c0f
·
verified ·
1 Parent(s): 229d71d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -50
app.py CHANGED
@@ -50,7 +50,7 @@ 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_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
 
@@ -60,54 +60,69 @@ Early wildfire detection using YOLOv8 AI vision model. See examples below or upl
60
 
61
  # Function to create synchronized video pair HTML
62
  def create_synced_video_pair(orig_url, proc_url, pair_id):
63
- orig_bytes = requests.get(orig_url).content
64
- proc_bytes = requests.get(proc_url).content
65
- orig_b64 = base64.b64encode(orig_bytes).decode('utf-8')
66
- proc_b64 = base64.b64encode(proc_bytes).decode('utf-8')
67
- html = f"""
68
- <div style="display: flex; justify-content: space-between;">
69
- <div style="width: 48%;">
70
- <h4>Original</h4>
71
- <video id="orig_{pair_id}" width="100%" controls>
72
- <source src="data:video/mp4;base64,{orig_b64}" type="video/mp4">
73
- </video>
74
- </div>
75
- <div style="width: 48%;">
76
- <h4>Processed</h4>
77
- <video id="proc_{pair_id}" width="100%" controls>
78
- <source src="data:video/mp4;base64,{proc_b64}" type="video/mp4">
79
- </video>
80
- </div>
81
- </div>
82
- <script>
83
- const origVideo_{pair_id} = document.getElementById('orig_{pair_id}');
84
- const procVideo_{pair_id} = document.getElementById('proc_{pair_id}');
85
-
86
- origVideo_{pair_id}.addEventListener('play', function() {{
87
- procVideo_{pair_id}.currentTime = origVideo_{pair_id}.currentTime;
88
- procVideo_{pair_id}.play();
89
- }});
90
- procVideo_{pair_id}.addEventListener('play', function() {{
91
- origVideo_{pair_id}.currentTime = procVideo_{pair_id}.currentTime;
92
- origVideo_{pair_id}.play();
93
- }});
94
 
95
- origVideo_{pair_id}.addEventListener('pause', function() {{
96
- procVideo_{pair_id}.pause();
97
- }});
98
- procVideo_{pair_id}.addEventListener('pause', function() {{
99
- origVideo_{pair_id}.pause();
100
- }});
101
-
102
- origVideo_{pair_id}.addEventListener('seeked', function() {{
103
- procVideo_{pair_id}.currentTime = origVideo_{pair_id}.currentTime;
104
- }});
105
- procVideo_{pair_id}.addEventListener('seeked', function() {{
106
- origVideo_{pair_id}.currentTime = procVideo_{pair_id}.currentTime;
107
- }});
108
- </script>
109
- """
110
- return html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  st.header("Your Results")
113
  result_cols = st.columns(2)
@@ -127,8 +142,6 @@ for title, orig_file, proc_file in examples:
127
  video_html = create_synced_video_pair(orig_url, proc_url, pair_id)
128
  st.markdown(video_html, unsafe_allow_html=True)
129
 
130
-
131
-
132
  # Load model
133
  try:
134
  model = YOLO(model_path)
 
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
 
 
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));
95
+ }});
96
+ procVideo.addEventListener('play', function() {{
97
+ origVideo.currentTime = procVideo.currentTime;
98
+ origVideo.play().catch(e => console.log('Play error:', e));
99
+ }});
100
+
101
+ origVideo.addEventListener('pause', function() {{
102
+ procVideo.pause();
103
+ }});
104
+ procVideo.addEventListener('pause', function() {{
105
+ origVideo.pause();
106
+ }});
107
+
108
+ origVideo.addEventListener('seeked', function() {{
109
+ procVideo.currentTime = origVideo.currentTime;
110
+ }});
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.")
126
 
127
  st.header("Your Results")
128
  result_cols = st.columns(2)
 
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
146
  try:
147
  model = YOLO(model_path)