space-sue commited on
Commit
54450d9
Β·
1 Parent(s): 180daf4

added links for test videos

Browse files
Files changed (2) hide show
  1. LICENSE +21 -0
  2. app.py +18 -8
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Wild Fire Tracker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
app.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
@@ -24,6 +28,7 @@ class FireDetectionMCP:
24
  self.status_color = "#808080" # Gray
25
  self.last_analysis_time = 0
26
  self.frame_count = 0
 
27
 
28
  def analyze_frame(self, frame):
29
  """Analyze frame for fire/smoke"""
@@ -43,8 +48,8 @@ class FireDetectionMCP:
43
  answer = vqa_processor.decode(outputs[0], skip_special_tokens=True).lower()
44
 
45
  # Check for fire/smoke
46
- fire_keywords = ['fire', 'flame', 'burning', 'blaze']
47
- smoke_keywords = ['smoke', 'smoky', 'vapor']
48
 
49
  if any(word in answer for word in fire_keywords):
50
  return "πŸ”₯ FIRE DETECTED", "#FF4500" # Orange
@@ -97,6 +102,7 @@ class FireDetectionMCP:
97
  print(f"[{datetime.now().strftime('%H:%M:%S')}] Analyzing frame {self.frame_count}...")
98
  self.status, self.status_color = self.analyze_frame(frame)
99
  self.last_analysis_time = current_time
 
100
  print(f"[{datetime.now().strftime('%H:%M:%S')}] Result: {self.status}")
101
 
102
  # Add status overlay
@@ -115,8 +121,9 @@ class FireDetectionMCP:
115
  cv2.putText(display_frame, self.status, (10, 40),
116
  cv2.FONT_HERSHEY_SIMPLEX, 1.0, color, 2)
117
 
118
- # Add frame counter
119
- cv2.putText(display_frame, f"Frame: {self.frame_count}", (10, 470),
 
120
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1)
121
 
122
  # Store frame
@@ -162,6 +169,8 @@ class FireDetectionMCP:
162
 
163
  def get_status(self):
164
  """Get current status"""
 
 
165
  return self.status
166
 
167
  # Initialize MCP server
@@ -173,8 +182,9 @@ def create_interface():
173
  with gr.Blocks(title="πŸ”₯ Fire Detection MCP Server", theme=gr.themes.Soft()) as interface:
174
  gr.Markdown("# πŸ”₯ Fire Detection MCP Server")
175
  gr.Markdown("Real-time fire and smoke detection from video streams (analyzes every 10 seconds)")
176
- gr.Markdown("⚠️ **Usage**: Upload your own video file or use live sources (webcam/RTSP). Webcam may not work on HF Spaces.")
177
-
 
178
  with gr.Row():
179
  with gr.Column(scale=1):
180
  gr.Markdown("### Video Source Options")
@@ -186,7 +196,7 @@ def create_interface():
186
  file_types=[".mp4", ".avi", ".mov"],
187
  type="filepath"
188
  )
189
- upload_btn = gr.Button("πŸš€ Start from Upload", variant="primary")
190
 
191
  with gr.Tab("πŸ“Ή Live Sources"):
192
  video_input = gr.Textbox(
@@ -194,7 +204,7 @@ def create_interface():
194
  placeholder="0 (webcam), rtsp://url, or path/to/video.mp4",
195
  value="0"
196
  )
197
- live_btn = gr.Button("πŸš€ Start Live Source", variant="primary")
198
 
199
  stop_btn = gr.Button("πŸ›‘ Stop Monitoring", variant="secondary")
200
 
 
1
+ # Wild Fire Tracker - Fire Detection MCP Server
2
+ # Copyright (c) 2024 Wild Fire Tracker
3
+ # Licensed under MIT License - see LICENSE file for details
4
+
5
  import gradio as gr
6
  import cv2
7
  import numpy as np
 
28
  self.status_color = "#808080" # Gray
29
  self.last_analysis_time = 0
30
  self.frame_count = 0
31
+ self.last_detection_time = None
32
 
33
  def analyze_frame(self, frame):
34
  """Analyze frame for fire/smoke"""
 
48
  answer = vqa_processor.decode(outputs[0], skip_special_tokens=True).lower()
49
 
50
  # Check for fire/smoke
51
+ fire_keywords = ['fire', 'flame', 'burning', 'blaze', 'flames']
52
+ smoke_keywords = ['smoke', 'smoky', 'vapor', 'fog', 'mist', 'haze', 'cloud', 'grey', 'gray']
53
 
54
  if any(word in answer for word in fire_keywords):
55
  return "πŸ”₯ FIRE DETECTED", "#FF4500" # Orange
 
102
  print(f"[{datetime.now().strftime('%H:%M:%S')}] Analyzing frame {self.frame_count}...")
103
  self.status, self.status_color = self.analyze_frame(frame)
104
  self.last_analysis_time = current_time
105
+ self.last_detection_time = datetime.now().strftime('%H:%M:%S')
106
  print(f"[{datetime.now().strftime('%H:%M:%S')}] Result: {self.status}")
107
 
108
  # Add status overlay
 
121
  cv2.putText(display_frame, self.status, (10, 40),
122
  cv2.FONT_HERSHEY_SIMPLEX, 1.0, color, 2)
123
 
124
+ # Add timestamp
125
+ timestamp = datetime.now().strftime('%H:%M:%S')
126
+ cv2.putText(display_frame, f"Time: {timestamp}", (10, 470),
127
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1)
128
 
129
  # Store frame
 
169
 
170
  def get_status(self):
171
  """Get current status"""
172
+ if self.last_detection_time:
173
+ return f"{self.status} (Last check: {self.last_detection_time})"
174
  return self.status
175
 
176
  # Initialize MCP server
 
182
  with gr.Blocks(title="πŸ”₯ Fire Detection MCP Server", theme=gr.themes.Soft()) as interface:
183
  gr.Markdown("# πŸ”₯ Fire Detection MCP Server")
184
  gr.Markdown("Real-time fire and smoke detection from video streams (analyzes every 10 seconds)")
185
+ gr.Markdown("⚠️ **Usage**: Upload your own video file or use live sources (webcam/RTSP). It may take few seconds to load stream and show analysis. Webcam may not work on HF Spaces.")
186
+ gr.Markdown("πŸ”— **Sample Videos**: [Fire Test Video](https://www.pexels.com/video/a-man-carrying-gear-walking-away-from-a-controlled-fire-8552246/) | [Smoke Test Video](https://www.pexels.com/video/aerial-view-of-controlled-forest-fire-in-spring-31361444/)")
187
+
188
  with gr.Row():
189
  with gr.Column(scale=1):
190
  gr.Markdown("### Video Source Options")
 
196
  file_types=[".mp4", ".avi", ".mov"],
197
  type="filepath"
198
  )
199
+ upload_btn = gr.Button("πŸš€ Start Monitoring", variant="primary")
200
 
201
  with gr.Tab("πŸ“Ή Live Sources"):
202
  video_input = gr.Textbox(
 
204
  placeholder="0 (webcam), rtsp://url, or path/to/video.mp4",
205
  value="0"
206
  )
207
+ live_btn = gr.Button("πŸš€ Start Monitoring", variant="primary")
208
 
209
  stop_btn = gr.Button("πŸ›‘ Stop Monitoring", variant="secondary")
210