Spaces:
Sleeping
Sleeping
simple
Browse files- accident_detection_model.h5 +3 -0
- app.py +55 -0
accident_detection_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ccdddd973f939e2b158f4fd0bbba3f57cb993ed50273e86767176419faf808d6
|
| 3 |
+
size 27672816
|
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
from tensorflow.keras.models import load_model
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
# Load the saved model
|
| 8 |
+
loaded_model = load_model("accident_detection_model.h5")
|
| 9 |
+
st.title("Accident Detection")
|
| 10 |
+
|
| 11 |
+
# Checkbox to enable camera input
|
| 12 |
+
camera_checkbox = st.checkbox("Use Camera")
|
| 13 |
+
|
| 14 |
+
if camera_checkbox:
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
image = st.camera_input("Take Photo")
|
| 18 |
+
|
| 19 |
+
if(st.button("Capture")):
|
| 20 |
+
|
| 21 |
+
# Preprocess the image
|
| 22 |
+
image = Image.open(image)
|
| 23 |
+
img_array = np.array(image.resize((150, 150)))
|
| 24 |
+
img_array = img_array / 255.0
|
| 25 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 26 |
+
|
| 27 |
+
# Classify the image
|
| 28 |
+
prediction = loaded_model.predict(img_array)
|
| 29 |
+
if prediction[0] > 0.5:
|
| 30 |
+
st.write("Prediction: Accident")
|
| 31 |
+
else:
|
| 32 |
+
st.write("Prediction: Non-Accident")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
else:
|
| 36 |
+
# Upload image
|
| 37 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
| 38 |
+
|
| 39 |
+
if uploaded_file is not None:
|
| 40 |
+
image = Image.open(uploaded_file)
|
| 41 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 42 |
+
st.write("")
|
| 43 |
+
st.write("Classifying...")
|
| 44 |
+
|
| 45 |
+
# Preprocess the image
|
| 46 |
+
img_array = np.array(image.resize((150, 150)))
|
| 47 |
+
img_array = img_array / 255.0
|
| 48 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 49 |
+
|
| 50 |
+
# Classify the image
|
| 51 |
+
prediction = loaded_model.predict(img_array)
|
| 52 |
+
if prediction[0] > 0.5:
|
| 53 |
+
st.write("Prediction: Accident")
|
| 54 |
+
else:
|
| 55 |
+
st.write("Prediction: Non-Accident")
|