ArchiMathur commited on
Commit
0aa7a04
·
verified ·
1 Parent(s): f5a6f5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -5,13 +5,12 @@ import numpy as np
5
  from PIL import Image
6
 
7
  # Load the YOLO model (replace with your model path)
8
- model = YOLO("best.pt")
9
- # Use your YOLO model file here
10
 
11
  st.title("Fire Detection in Forest")
12
 
13
  # Sidebar for input options
14
- input_option = st.sidebar.selectbox("Select Input Method", ["Upload Image", "Use Webcam","Upload Video"])
15
 
16
  if input_option == "Upload Image":
17
  # Upload Image
@@ -27,21 +26,32 @@ if input_option == "Upload Image":
27
 
28
  # Make predictions
29
  results = model.predict(source=img_np, conf=0.5)
30
-
31
- if Fire_Detected= True:
32
- print("Fire Detected")
33
- else:
34
- print("Not")
35
  # Draw bounding boxes on the image
36
  for result in results:
37
  boxes = result.boxes.xyxy
38
  for box in boxes:
39
  x1, y1, x2, y2 = box[:4].astype(int)
40
  img_np = cv2.rectangle(img_np, (x1, y1), (x2, y2), (0, 255, 0), 2)
41
-
 
 
 
 
 
42
  # Show the resulting image
43
  st.image(img_np, caption='Detected Fire', use_column_width=True)
44
 
 
 
 
 
 
 
 
45
  # elif input_option == "Use Webcam":
46
  # st.write("Starting webcam for live detection...")
47
 
 
5
  from PIL import Image
6
 
7
  # Load the YOLO model (replace with your model path)
8
+ model = YOLO("best.pt") # Use your YOLO model file here
 
9
 
10
  st.title("Fire Detection in Forest")
11
 
12
  # Sidebar for input options
13
+ input_option = st.sidebar.selectbox("Select Input Method", ["Upload Image", "Use Webcam", "Upload Video"])
14
 
15
  if input_option == "Upload Image":
16
  # Upload Image
 
26
 
27
  # Make predictions
28
  results = model.predict(source=img_np, conf=0.5)
29
+
30
+ # Variable to check if fire is detected
31
+ fire_detected = False
32
+
 
33
  # Draw bounding boxes on the image
34
  for result in results:
35
  boxes = result.boxes.xyxy
36
  for box in boxes:
37
  x1, y1, x2, y2 = box[:4].astype(int)
38
  img_np = cv2.rectangle(img_np, (x1, y1), (x2, y2), (0, 255, 0), 2)
39
+
40
+ # Check if the detected class is "fire" (adjust based on your model's class mapping)
41
+ class_id = int(box[5]) # Assuming class ID is at the 6th position
42
+ if class_id == 0: # Replace 0 with the actual class ID for fire if different
43
+ fire_detected = True
44
+
45
  # Show the resulting image
46
  st.image(img_np, caption='Detected Fire', use_column_width=True)
47
 
48
+ # Display message based on fire detection
49
+ if fire_detected:
50
+ st.success("🔥 Fire Detected!")
51
+ else:
52
+ st.warning("No Fire Detected.")
53
+
54
+
55
  # elif input_option == "Use Webcam":
56
  # st.write("Starting webcam for live detection...")
57