Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,52 +4,56 @@ import cv2
|
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
-
|
| 8 |
-
model
|
| 9 |
|
| 10 |
-
st.title("Fire Detection in Forest")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
# Upload Image
|
| 17 |
-
uploaded_file = st.file_uploader("Choose an Image", type=["jpg", "jpeg", "png"])
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
st.image(img, caption='User Image')
|
| 22 |
-
st.write("Classifying...")
|
| 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 |
|
| 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":
|