Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ model = YOLO("best.pt")
|
|
| 11 |
st.title("Fire Detection in Forest")
|
| 12 |
|
| 13 |
# Sidebar for input options
|
| 14 |
-
input_option = st.sidebar.selectbox("Select Input Method", ["Upload Image", "Use Webcam"])
|
| 15 |
|
| 16 |
if input_option == "Upload Image":
|
| 17 |
# Upload Image
|
|
@@ -76,3 +76,46 @@ elif input_option == "Use Webcam":
|
|
| 76 |
|
| 77 |
# Release the camera
|
| 78 |
camera.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
st.title("Fire Detection in Forest")
|
| 12 |
|
| 13 |
# Sidebar for input options
|
| 14 |
+
input_option = st.sidebar.selectbox("Select Input Method", ["Upload Image", "Use Webcam","Upload Video"])
|
| 15 |
|
| 16 |
if input_option == "Upload Image":
|
| 17 |
# Upload Image
|
|
|
|
| 76 |
|
| 77 |
# Release the camera
|
| 78 |
camera.release()
|
| 79 |
+
|
| 80 |
+
elif input_option == "Upload Video":
|
| 81 |
+
uploaded_video = st.file_uploader("choose a video",type=["mp4","avi","mov","mkv"])
|
| 82 |
+
if uploaded_video is not None:
|
| 83 |
+
# Save the uploaded video temporarily
|
| 84 |
+
temp_video_path = "temp_video.mp4"
|
| 85 |
+
with open(temp_video_path, "wb") as f:
|
| 86 |
+
f.write(uploaded_video.read())
|
| 87 |
+
|
| 88 |
+
# Open the video file
|
| 89 |
+
video_capture = cv2.VideoCapture(temp_video_path)
|
| 90 |
+
|
| 91 |
+
# Create a placeholder for the video frames
|
| 92 |
+
video_frame_placeholder = st.empty()
|
| 93 |
+
|
| 94 |
+
# Loop through video frames
|
| 95 |
+
while video_capture.isOpened():
|
| 96 |
+
ret, frame = video_capture.read()
|
| 97 |
+
if not ret:
|
| 98 |
+
st.write("Finished processing video.")
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
# Make predictions
|
| 102 |
+
results = model.predict(source=frame, conf=0.5)
|
| 103 |
+
|
| 104 |
+
# Draw bounding boxes on the frame
|
| 105 |
+
for result in results:
|
| 106 |
+
boxes = result.boxes.xyxy
|
| 107 |
+
for box in boxes:
|
| 108 |
+
x1, y1, x2, y2 = box[:4].astype(int)
|
| 109 |
+
frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 110 |
+
|
| 111 |
+
# Convert frame to RGB
|
| 112 |
+
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 113 |
+
|
| 114 |
+
# Display the frame
|
| 115 |
+
video_frame_placeholder.image(rgb_frame, channels="RGB", use_column_width=True)
|
| 116 |
+
|
| 117 |
+
# Release the video capture
|
| 118 |
+
video_capture.release()
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|