Abs6187 commited on
Commit
cc2ee2f
·
verified ·
1 Parent(s): b8011b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -1,28 +1,34 @@
1
  import streamlit as st
2
- import torch
3
- import cv2
4
- import numpy as np
5
  from PIL import Image
 
 
 
 
 
6
 
7
- # Load YOLOv5 model
8
- model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
9
 
10
  def predict(image):
11
- # Convert PIL Image to numpy array
12
- img_array = np.array(image)
 
 
13
 
14
- # Detect objects
15
- results = model(img_array)
16
 
17
- # Plot results
18
- img_with_boxes = results.render()[0]
 
19
 
20
- # Convert back to PIL Image
21
- return Image.fromarray(img_with_boxes)
22
 
23
  # Streamlit UI
24
- st.title("Object Detection with YOLOv5")
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
- result_image = predict(image)
35
- st.image(result_image, caption="Detected Image", use_column_width=True)
 
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