ArchiMathur commited on
Commit
0be7ae3
·
verified ·
1 Parent(s): c1bc3b1

Update app.py

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