Spaces:
No application file
No application file
Upload app (3).py
Browse files- app (3).py +27 -3
app (3).py
CHANGED
|
@@ -1,12 +1,36 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from io import StringIO
|
| 3 |
import pandas as pd
|
| 4 |
from transformers import pipeline
|
| 5 |
|
|
|
|
| 6 |
classifier = pipeline("object-detection", model="chayanee/Detected_img")
|
|
|
|
| 7 |
def main():
|
| 8 |
-
st.title("Detection
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
if __name__ == "__main__":
|
| 12 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
from io import StringIO
|
| 4 |
import pandas as pd
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
+
# Create an object detection pipeline
|
| 8 |
classifier = pipeline("object-detection", model="chayanee/Detected_img")
|
| 9 |
+
|
| 10 |
def main():
|
| 11 |
+
st.title("Object Detection on Images")
|
| 12 |
+
|
| 13 |
+
# File Upload Widget
|
| 14 |
+
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "png", "jpeg"])
|
| 15 |
+
|
| 16 |
+
if uploaded_file is not None:
|
| 17 |
+
# Display the uploaded image
|
| 18 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 19 |
+
|
| 20 |
+
# Perform object detection
|
| 21 |
+
image = Image.open(uploaded_file)
|
| 22 |
+
results = classifier(image)
|
| 23 |
+
|
| 24 |
+
# Display object detection results
|
| 25 |
+
st.subheader("Object Detection Results")
|
| 26 |
+
for result in results:
|
| 27 |
+
label = result["label"]
|
| 28 |
+
score = result["score"]
|
| 29 |
+
box = result["box"]
|
| 30 |
+
st.write(f"Label: {label}, Score: {score:.2f}")
|
| 31 |
+
st.image(image.crop(box), caption=f"Object: {label}", use_column_width=True)
|
| 32 |
+
|
| 33 |
+
st.button("Click to Detect Objects", type="primary")
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
+
main()
|