Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,11 @@ if input_option == "Upload Image":
|
|
| 27 |
|
| 28 |
# Make predictions
|
| 29 |
results = model.predict(source=img_np, conf=0.5)
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Draw bounding boxes on the image
|
| 32 |
for result in results:
|
| 33 |
boxes = result.boxes.xyxy
|
|
@@ -38,100 +42,100 @@ if input_option == "Upload Image":
|
|
| 38 |
# Show the resulting image
|
| 39 |
st.image(img_np, caption='Detected Fire', use_column_width=True)
|
| 40 |
|
| 41 |
-
elif input_option == "Use Webcam":
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
-
elif input_option == "Upload Video":
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
|
| 136 |
|
| 137 |
|
|
|
|
| 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
|
|
|
|
| 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 |
|
| 48 |
+
# # Start video capture
|
| 49 |
+
# camera = cv2.VideoCapture(0) # 0 is the default camera
|
| 50 |
|
| 51 |
+
# # Create a placeholder for the video feed
|
| 52 |
+
# video_placeholder = st.empty()
|
| 53 |
|
| 54 |
+
# # Main loop for live detection
|
| 55 |
+
# while True:
|
| 56 |
+
# ret, frame = camera.read()
|
| 57 |
+
# if not ret:
|
| 58 |
+
# st.write("Failed to capture image")
|
| 59 |
+
# break
|
| 60 |
|
| 61 |
+
# # Make predictions
|
| 62 |
+
# results = model.predict(source=frame, conf=0.5)
|
| 63 |
|
| 64 |
+
# # Draw bounding boxes on the frame
|
| 65 |
+
# for result in results:
|
| 66 |
+
# boxes = result.boxes.xyxy
|
| 67 |
+
# for box in boxes:
|
| 68 |
+
# x1, y1, x2, y2 = box[:4].astype(int)
|
| 69 |
+
# frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 70 |
|
| 71 |
+
# # Convert frame to RGB
|
| 72 |
+
# rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 73 |
|
| 74 |
+
# # Display the frame in the Streamlit app
|
| 75 |
+
# video_placeholder.image(rgb_frame, channels="RGB", use_column_width=True)
|
| 76 |
|
| 77 |
+
# # Break loop on user command
|
| 78 |
+
# if st.button("Stop Detection"):
|
| 79 |
+
# break
|
| 80 |
|
| 81 |
+
# # Release the camera
|
| 82 |
+
# camera.release()
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
+
# elif input_option == "Upload Video":
|
| 89 |
+
# uploaded_video = st.file_uploader("Choose a video", type=["mp4", "avi", "mov", "mkv"])
|
| 90 |
+
# if uploaded_video is not None:
|
| 91 |
+
# # Save the uploaded video temporarily
|
| 92 |
+
# temp_video_path = "temp_video.mp4"
|
| 93 |
+
# with open(temp_video_path, "wb") as f:
|
| 94 |
+
# f.write(uploaded_video.read())
|
| 95 |
|
| 96 |
+
# # Display the uploaded video
|
| 97 |
+
# st.video(temp_video_path)
|
| 98 |
|
| 99 |
+
# # Open the video file
|
| 100 |
+
# video_capture = cv2.VideoCapture(temp_video_path)
|
| 101 |
|
| 102 |
+
# # Create a placeholder for video frame processing
|
| 103 |
+
# video_frame_placeholder = st.empty()
|
| 104 |
+
# fire_detected = False
|
| 105 |
|
| 106 |
+
# # Loop through video frames
|
| 107 |
+
# while video_capture.isOpened():
|
| 108 |
+
# ret, frame = video_capture.read()
|
| 109 |
+
# if not ret:
|
| 110 |
+
# break
|
| 111 |
|
| 112 |
+
# # Make predictions using your fire detection model
|
| 113 |
+
# results = model.predict(source=frame, conf=0.5)
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
+
# # Draw bounding boxes on the frame if fire is detected
|
| 118 |
+
# for result in results:
|
| 119 |
+
# boxes = result.boxes.xyxy
|
| 120 |
+
# for box in boxes:
|
| 121 |
+
# x1, y1, x2, y2 = box[:4].astype(int)
|
| 122 |
+
# frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 123 |
+
# fire_detected = True # Set fire_detected flag if a bounding box is found
|
| 124 |
|
| 125 |
+
# # Convert the frame to RGB format
|
| 126 |
+
# rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 127 |
|
| 128 |
+
# # Display the processed frame
|
| 129 |
+
# video_frame_placeholder.image(rgb_frame, channels="RGB", use_column_width=True)
|
| 130 |
|
| 131 |
+
# # Display detection result
|
| 132 |
+
# if fire_detected:
|
| 133 |
+
# st.write("Fire detected in the video.")
|
| 134 |
+
# else:
|
| 135 |
+
# st.write("No fire detected in the video.")
|
| 136 |
|
| 137 |
+
# # Release the video capture
|
| 138 |
+
# video_capture.release()
|
| 139 |
|
| 140 |
|
| 141 |
|