chayanee commited on
Commit
25571d0
·
1 Parent(s): 30e7fe3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
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
- # Analyze the uploaded image if available
18
- if uploaded_image:
19
- # Display the uploaded image
20
- image = Image.open(uploaded_image)
21
- st.image(image, caption="Uploaded Image", use_column_width=True)
22
 
23
- # Perform object detection on the image
24
- results = object_detection(image)
25
 
26
- # Display detected objects and their confidence levels
27
- st.subheader("Detected Objects:")
28
- for result in results:
29
- label = result["label"]
30
- confidence = result["score"]
31
- box = result["box"]
32
- st.write(f"Detected {label} with confidence {confidence:.3f} at location {box}")
 
 
 
 
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}")