chayanee commited on
Commit
30e7fe3
·
1 Parent(s): 888703a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -3,19 +3,30 @@ from PIL import Image
3
  import pandas as pd
4
  from transformers import pipeline
5
 
6
-
7
  # Create a sentiment analysis pipeline
8
- sentiment_analysis = pipeline("sentiment-analysis", model="chayanee/Detected_img")
 
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 sentiment analysis 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)
 
 
 
 
 
 
 
 
 
 
 
 
3
  import pandas as pd
4
  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}")