File size: 1,827 Bytes
731f00a
3ae5d8e
e5dd3c7
defef4e
 
 
e5dd3c7
0be7ae3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5dd3c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


from ultralytics import YOLO
import streamlit as st
import numpy as np
from PIL import Image
model=YOLO("best.pt")
# Set the title of the app
st.title("Fire Detection App")

# Sidebar for input options
input_option = st.sidebar.selectbox("Select Input Method", ["Upload Image"])

if input_option == "Upload Image":
    # Upload Image
    uploaded_file = st.file_uploader("Choose an Image", type=["jpg", "jpeg", "png"])

    if uploaded_file is not None:
        # Open and display the uploaded image
        img = Image.open(uploaded_file)
        st.image(img, caption='User Image', use_column_width=True)
        
        # Convert the image to a numpy array
        img_np = np.array(img)

        # Make predictions
        results = model.predict(source=img_np, conf=0.5)  # Adjust confidence threshold as needed

        # Variable to check if fire is detected
        fire_detected = False

        # Draw bounding boxes on the image
        for result in results:
            boxes = result.boxes.xyxy  # Bounding boxes
            for box in boxes:
                x1, y1, x2, y2 = box[:4].astype(int)
                img_np = cv2.rectangle(img_np, (x1, y1), (x2, y2), (0, 255, 0), 2)

                # Check if the detected class is "fire" (adjust based on your model's class mapping)
                class_id = int(box[5])  # Assuming class ID is at the 6th position
                if class_id == 0:  # Replace 0 with the actual class ID for fire if different
                    fire_detected = True

        # Show the resulting image with bounding boxes
        st.image(img_np, caption='Detected Fire', use_column_width=True)

        # Display message based on fire detection
        if fire_detected:
            st.success("🔥 Fire Detected!")
        else:
            st.warning("No Fire Detected.")