Upload app.py
Browse files
app.py
CHANGED
@@ -5,28 +5,34 @@ from transformers import pipeline
|
|
5 |
|
6 |
# Create a sentiment analysis pipeline
|
7 |
object_detection = pipeline("sentiment-analysis", model="chayanee/Detected_img")
|
|
|
|
|
|
|
8 |
|
9 |
-
# Set the title for your Streamlit app
|
10 |
-
st.title("Object Detection")
|
11 |
|
12 |
-
# Image Upload Widget
|
13 |
-
uploaded_image = st.file_uploader("Upload an image for Detection", type=["jpg", "jpeg", "png"])
|
14 |
|
15 |
-
# Perform object detection when the user clicks a button
|
16 |
-
if st.button("Detection"):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
5 |
|
6 |
# Create a sentiment analysis pipeline
|
7 |
object_detection = pipeline("sentiment-analysis", model="chayanee/Detected_img")
|
8 |
+
try:
|
9 |
+
# Create an object detection pipeline
|
10 |
+
object_detection = pipeline("object-detection")
|
11 |
|
12 |
+
# Set the title for your Streamlit app
|
13 |
+
st.title("Object Detection")
|
14 |
|
15 |
+
# Image Upload Widget
|
16 |
+
uploaded_image = st.file_uploader("Upload an image for Detection", type=["jpg", "jpeg", "png"])
|
17 |
|
18 |
+
# Perform object detection when the user clicks a button
|
19 |
+
if st.button("Detection"):
|
20 |
+
# Analyze the uploaded image if available
|
21 |
+
if uploaded_image:
|
22 |
+
# Display the uploaded image
|
23 |
+
image = Image.open(uploaded_image)
|
24 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
25 |
|
26 |
+
# Perform object detection on the image
|
27 |
+
results = object_detection(image)
|
28 |
|
29 |
+
# Display detected objects and their confidence levels
|
30 |
+
st.subheader("Detected Objects:")
|
31 |
+
for result in results:
|
32 |
+
label = result["label"]
|
33 |
+
confidence = result["score"]
|
34 |
+
box = result["box"]
|
35 |
+
st.write(f"Detected {label} with confidence {confidence:.3f} at location {box}")
|
36 |
+
|
37 |
+
except Exception as e:
|
38 |
+
st.error(f"An error occurred: {e}")
|