Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import numpy as np
|
5 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
# Load
|
8 |
-
model =
|
9 |
|
10 |
def predict(image):
|
11 |
-
#
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
19 |
|
20 |
-
#
|
21 |
-
return Image.fromarray(img_with_boxes)
|
22 |
|
23 |
# Streamlit UI
|
24 |
-
st.title("
|
25 |
-
st.markdown("Upload an image for detection.")
|
26 |
|
27 |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
28 |
|
@@ -31,5 +37,5 @@ if uploaded_image is not None:
|
|
31 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
32 |
|
33 |
st.subheader("Prediction Results:")
|
34 |
-
|
35 |
-
|
|
|
1 |
import streamlit as st
|
2 |
+
import kagglehub
|
3 |
+
import tensorflow as tf
|
|
|
4 |
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Download model from Kaggle Hub
|
8 |
+
model_path = kagglehub.model_download("sohiebalwedyan/seatbelt-detection/tensorFlow2/seatbelt-detection")
|
9 |
+
print("Path to model files:", model_path)
|
10 |
|
11 |
+
# Load the TensorFlow model
|
12 |
+
model = tf.saved_model.load(model_path)
|
13 |
|
14 |
def predict(image):
|
15 |
+
# Preprocess image
|
16 |
+
img = image.resize((224, 224))
|
17 |
+
img_array = np.array(img) / 255.0
|
18 |
+
img_array = np.expand_dims(img_array, axis=0)
|
19 |
|
20 |
+
# Run inference
|
21 |
+
predictions = model(tf.convert_to_tensor(img_array, dtype=tf.float32))
|
22 |
|
23 |
+
# Process predictions (modify based on actual model output)
|
24 |
+
# This is a placeholder and may need adjustment based on model specifics
|
25 |
+
st.write("Raw predictions:", predictions)
|
26 |
|
27 |
+
return image # Placeholder return
|
|
|
28 |
|
29 |
# Streamlit UI
|
30 |
+
st.title("Seatbelt Detection")
|
31 |
+
st.markdown("Upload an image for seatbelt detection.")
|
32 |
|
33 |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
34 |
|
|
|
37 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
38 |
|
39 |
st.subheader("Prediction Results:")
|
40 |
+
result = predict(image)
|
41 |
+
# Note: You may need to modify visualization based on model output
|