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

Update app.py

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