Spaces:
Sleeping
Sleeping
kishan-1721
commited on
Commit
•
d27576c
1
Parent(s):
ac9019e
Upload 2 files
Browse files
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from main import save_image
|
3 |
+
from ultralytics import YOLO
|
4 |
+
import shutil
|
5 |
+
|
6 |
+
model = YOLO('yolov8m.pt')
|
7 |
+
|
8 |
+
st.title('Object Detection')
|
9 |
+
|
10 |
+
save_image()
|
11 |
+
|
12 |
+
if st.button("Detect Object"):
|
13 |
+
model.predict(source = 'processed_image.jpg', save = True, conf = 0.7)
|
14 |
+
st.image('runs/detect/predict/processed_image.jpg')
|
15 |
+
shutil.rmtree('runs')
|
main.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def save_image():
|
7 |
+
|
8 |
+
# st.title("Image Processing and Saving Example")
|
9 |
+
|
10 |
+
# Upload an image using Streamlit's file uploader
|
11 |
+
|
12 |
+
genre = st.radio(
|
13 |
+
"How You Want To Upload Your Image",
|
14 |
+
('Browse Photos', 'Camera'))
|
15 |
+
|
16 |
+
if genre == 'Camera':
|
17 |
+
uploaded_image = st.camera_input("Take a picture")
|
18 |
+
else:
|
19 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
20 |
+
# uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
21 |
+
|
22 |
+
if uploaded_image is not None:
|
23 |
+
# Display the uploaded image
|
24 |
+
# st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
25 |
+
|
26 |
+
# Convert the image to a format compatible with PIL and OpenCV
|
27 |
+
pil_image = Image.open(uploaded_image)
|
28 |
+
opencv_image = np.array(pil_image)
|
29 |
+
opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
|
30 |
+
|
31 |
+
# Image processing code (You can add any processing you want here)
|
32 |
+
|
33 |
+
# Save the processed image using PIL
|
34 |
+
# st.write("Processed Image")
|
35 |
+
# st.image(pil_image, caption="Processed Image", use_column_width=True)
|
36 |
+
|
37 |
+
# Save the processed image using OpenCV
|
38 |
+
# save_button = st.button("Save Processed Image")
|
39 |
+
# if save_button:
|
40 |
+
# Provide a file path to save the image
|
41 |
+
save_path = "processed_image.jpg" # You can change the file format or filename here
|
42 |
+
cv2.imwrite(save_path, opencv_image)
|
43 |
+
st.success(f"Image saved as {save_path}")
|
44 |
+
|
45 |
+
# if __name__ == "__main__":
|
46 |
+
# main()
|