Baskar2005 commited on
Commit
a732834
·
verified ·
1 Parent(s): 9e4375f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -1,40 +1,40 @@
1
- import streamlit as st
2
- from ultralytics import YOLO
3
- import cv2
4
- from PIL import Image
5
- import numpy as np
6
-
7
- # Load the pre-trained YOLOv8 model
8
- model = YOLO("YOLOv8\yolov8x.pt") # Replace with the path to your model
9
-
10
- # Title for the web app
11
- st.title("YOLOv8 Object Detection - Image Upload")
12
-
13
- # Instructions
14
- st.write("Upload an image, and YOLOv8 will predict the objects in the image with bounding boxes.")
15
-
16
- # File uploader widget
17
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
18
-
19
- if uploaded_file is not None:
20
- # Read the uploaded image file and display it
21
- image = Image.open(uploaded_file)
22
- st.image(image, caption="Uploaded Image", use_column_width=True)
23
-
24
- # Convert the image to a numpy array for YOLO processing
25
- img_array = np.array(image)
26
-
27
- # Make predictions using the model
28
- results = model.predict(img_array, conf=0.5, iou=0.4)
29
-
30
- # Display the results
31
- st.write(f"Detected {len(results)} objects.")
32
-
33
- # Annotate the image with bounding boxes
34
- annotated_img = results[0].plot()
35
-
36
- # Convert the annotated image to a format suitable for Streamlit
37
- annotated_img_pil = Image.fromarray(annotated_img)
38
-
39
- # Display the annotated image
40
- st.image(annotated_img_pil, caption="Processed Image with Bounding Boxes", use_column_width=True)
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ import cv2
4
+ from PIL import Image
5
+ import numpy as np
6
+
7
+ # Load the pre-trained YOLOv8 model
8
+ model = YOLO("yolov8x.pt") # Replace with the path to your model
9
+
10
+ # Title for the web app
11
+ st.title("YOLOv8 Object Detection - Image Upload")
12
+
13
+ # Instructions
14
+ st.write("Upload an image, and YOLOv8 will predict the objects in the image with bounding boxes.")
15
+
16
+ # File uploader widget
17
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
18
+
19
+ if uploaded_file is not None:
20
+ # Read the uploaded image file and display it
21
+ image = Image.open(uploaded_file)
22
+ st.image(image, caption="Uploaded Image", use_column_width=True)
23
+
24
+ # Convert the image to a numpy array for YOLO processing
25
+ img_array = np.array(image)
26
+
27
+ # Make predictions using the model
28
+ results = model.predict(img_array, conf=0.5, iou=0.4)
29
+
30
+ # Display the results
31
+ st.write(f"Detected {len(results)} objects.")
32
+
33
+ # Annotate the image with bounding boxes
34
+ annotated_img = results[0].plot()
35
+
36
+ # Convert the annotated image to a format suitable for Streamlit
37
+ annotated_img_pil = Image.fromarray(annotated_img)
38
+
39
+ # Display the annotated image
40
+ st.image(annotated_img_pil, caption="Processed Image with Bounding Boxes", use_column_width=True)