img10 / app.py
chayanee's picture
Upload app.py
25571d0
import streamlit as st
from PIL import Image
import pandas as pd
from transformers import pipeline
# Create a sentiment analysis pipeline
object_detection = pipeline("sentiment-analysis", model="chayanee/Detected_img")
try:
# Create an object detection pipeline
object_detection = pipeline("object-detection")
# Set the title for your Streamlit app
st.title("Object Detection")
# Image Upload Widget
uploaded_image = st.file_uploader("Upload an image for Detection", type=["jpg", "jpeg", "png"])
# Perform object detection when the user clicks a button
if st.button("Detection"):
# Analyze the uploaded image if available
if uploaded_image:
# Display the uploaded image
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Perform object detection on the image
results = object_detection(image)
# Display detected objects and their confidence levels
st.subheader("Detected Objects:")
for result in results:
label = result["label"]
confidence = result["score"]
box = result["box"]
st.write(f"Detected {label} with confidence {confidence:.3f} at location {box}")
except Exception as e:
st.error(f"An error occurred: {e}")