File size: 1,388 Bytes
197c55a
 
 
 
 
 
30e7fe3
25571d0
 
 
30e7fe3
25571d0
 
197c55a
25571d0
 
197c55a
25571d0
 
 
 
 
 
 
30e7fe3
25571d0
 
30e7fe3
25571d0
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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}")