Spaces:
Running
Running
vishalkatheriya18
commited on
Commit
•
ca06180
1
Parent(s):
f01686c
Update app.py
Browse files
app.py
CHANGED
@@ -93,6 +93,113 @@
|
|
93 |
# st.write("URL Invalid...!")
|
94 |
# except Exception as e:
|
95 |
# st.write(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
import streamlit as st
|
97 |
from ultralytics import YOLO
|
98 |
from PIL import Image
|
@@ -175,13 +282,14 @@ if url:
|
|
175 |
|
176 |
# Crop the image based on the bounding box
|
177 |
cropped_image = image_np[y1:y2, x1:x2].copy()
|
|
|
178 |
category_name = find_category(class_label)
|
179 |
|
180 |
# Add cropped image and its title to the list
|
181 |
cropped_images.append((cropped_image, f'Class: {category_name}, Confidence: {confidence:.2f}'))
|
182 |
|
183 |
# Display the original image with bounding boxes and labels
|
184 |
-
st.image(output_image, caption="Segmented Image", channels="RGB")
|
185 |
|
186 |
# Display cropped images row-wise
|
187 |
num_columns = 3 # Number of columns per row
|
@@ -199,4 +307,3 @@ if url:
|
|
199 |
st.write("URL Invalid...!")
|
200 |
except Exception as e:
|
201 |
st.write(f"An error occurred: {e}")
|
202 |
-
|
|
|
93 |
# st.write("URL Invalid...!")
|
94 |
# except Exception as e:
|
95 |
# st.write(f"An error occurred: {e}")
|
96 |
+
# import streamlit as st
|
97 |
+
# from ultralytics import YOLO
|
98 |
+
# from PIL import Image
|
99 |
+
# import requests
|
100 |
+
# from io import BytesIO
|
101 |
+
# import numpy as np
|
102 |
+
# import cv2
|
103 |
+
|
104 |
+
# # Categories dictionary
|
105 |
+
# categories_dict = {
|
106 |
+
# "UpperBody": ["top", "t-shirt", "sweatshirt", "shirt", "blouse", "sweater", "cardigan", "jacket", "vest"],
|
107 |
+
# "Lowerbody": ["pants", "shorts", "skirt"],
|
108 |
+
# "Wholebody": ["coat", "dress", "jumpsuit", "cape"],
|
109 |
+
# "Head": ["glasses", "hat", "headband", "head covering", "hair accessory"],
|
110 |
+
# "Neck": ["tie"],
|
111 |
+
# "Arms and Hands": ["glove", "watch"],
|
112 |
+
# "Waist": ["belt"],
|
113 |
+
# "Legs and Feet": ["leg warmer", "tights", "stockings", "sock", "shoe"],
|
114 |
+
# "Others": ["bag", "wallet", "scarf", "umbrella"],
|
115 |
+
# "Garment parts": ["hood", "collar", "lapel", "epaulette", "sleeve", "pocket", "neckline"],
|
116 |
+
# "Closures": ["buckle", "zipper"],
|
117 |
+
# "Decorations": ["applique", "bead", "bow", "flower", "fringe", "ribbon", "rivet", "ruffle", "sequin", "tassel"]
|
118 |
+
# }
|
119 |
+
|
120 |
+
# def find_category(subcategory):
|
121 |
+
# for category, subcategories in categories_dict.items():
|
122 |
+
# if subcategory in subcategories:
|
123 |
+
# return category
|
124 |
+
# return "Subcategory not found."
|
125 |
+
|
126 |
+
# # Load models and processor only once using Streamlit session state
|
127 |
+
# if 'models_loaded' not in st.session_state:
|
128 |
+
# st.session_state.segment_model = YOLO("best.pt")
|
129 |
+
# st.write("Model loaded!")
|
130 |
+
# st.session_state.models_loaded = True
|
131 |
+
|
132 |
+
# # Streamlit app UI
|
133 |
+
# st.title("Clothing Classification Pipeline")
|
134 |
+
# url = st.sidebar.text_input("Paste image URL here...")
|
135 |
+
|
136 |
+
# if url:
|
137 |
+
# try:
|
138 |
+
# response = requests.get(url)
|
139 |
+
# if response.status_code == 200:
|
140 |
+
# image = Image.open(BytesIO(response.content))
|
141 |
+
# st.sidebar.image(image.resize((200, 200)), caption="Uploaded Image", use_column_width=False)
|
142 |
+
|
143 |
+
# # Convert image to numpy array for YOLO model
|
144 |
+
# image_np = np.array(image)
|
145 |
+
|
146 |
+
# # Perform inference
|
147 |
+
# results = st.session_state.segment_model(image_np)
|
148 |
+
|
149 |
+
# # Create a copy of the original image to draw bounding boxes and labels
|
150 |
+
# output_image = image_np.copy()
|
151 |
+
|
152 |
+
# cropped_images = [] # List to hold cropped images and their titles
|
153 |
+
|
154 |
+
# # Visualize the segmentation results
|
155 |
+
# for result in results:
|
156 |
+
# boxes = result.boxes # Bounding boxes
|
157 |
+
# classes = result.names # Class names of the detected objects
|
158 |
+
|
159 |
+
# for i, box in enumerate(boxes):
|
160 |
+
# box_coords = box.xyxy[0].cpu().numpy().astype(int)
|
161 |
+
# x1, y1, x2, y2 = box_coords
|
162 |
+
|
163 |
+
# # Draw the bounding box on the original image
|
164 |
+
# cv2.rectangle(output_image, (x1, y1), (x2, y2), color=(0, 255, 0), thickness=2)
|
165 |
+
|
166 |
+
# # Get the class label and confidence score for the object
|
167 |
+
# class_label = classes[box.cls[0].int().item()]
|
168 |
+
# confidence = box.conf[0].item()
|
169 |
+
|
170 |
+
# # Prepare the label text with class and confidence
|
171 |
+
# label_text = f'{class_label}: {confidence:.2f}'
|
172 |
+
|
173 |
+
# # Put text label on the original image
|
174 |
+
# cv2.putText(output_image, label_text, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
175 |
+
|
176 |
+
# # Crop the image based on the bounding box
|
177 |
+
# cropped_image = image_np[y1:y2, x1:x2].copy()
|
178 |
+
# category_name = find_category(class_label)
|
179 |
+
|
180 |
+
# # Add cropped image and its title to the list
|
181 |
+
# cropped_images.append((cropped_image, f'Class: {category_name}, Confidence: {confidence:.2f}'))
|
182 |
+
|
183 |
+
# # Display the original image with bounding boxes and labels
|
184 |
+
# st.image(output_image, caption="Segmented Image", channels="RGB")
|
185 |
+
|
186 |
+
# # Display cropped images row-wise
|
187 |
+
# num_columns = 3 # Number of columns per row
|
188 |
+
# num_rows = (len(cropped_images) + num_columns - 1) // num_columns # Calculate the number of rows
|
189 |
+
|
190 |
+
# for i in range(num_rows):
|
191 |
+
# cols = st.columns(num_columns)
|
192 |
+
# for j in range(num_columns):
|
193 |
+
# idx = i * num_columns + j
|
194 |
+
# if idx < len(cropped_images):
|
195 |
+
# cropped_image, title = cropped_images[idx]
|
196 |
+
# with cols[j]:
|
197 |
+
# st.image(cropped_image, caption=title, use_column_width=True)
|
198 |
+
# else:
|
199 |
+
# st.write("URL Invalid...!")
|
200 |
+
# except Exception as e:
|
201 |
+
# st.write(f"An error occurred: {e}")
|
202 |
+
|
203 |
import streamlit as st
|
204 |
from ultralytics import YOLO
|
205 |
from PIL import Image
|
|
|
282 |
|
283 |
# Crop the image based on the bounding box
|
284 |
cropped_image = image_np[y1:y2, x1:x2].copy()
|
285 |
+
cropped_image = cv2.resize(cropped_image, (200, 200)) # Resize cropped image
|
286 |
category_name = find_category(class_label)
|
287 |
|
288 |
# Add cropped image and its title to the list
|
289 |
cropped_images.append((cropped_image, f'Class: {category_name}, Confidence: {confidence:.2f}'))
|
290 |
|
291 |
# Display the original image with bounding boxes and labels
|
292 |
+
st.image(output_image, caption="Segmented Image", channels="RGB", use_column_width=True)
|
293 |
|
294 |
# Display cropped images row-wise
|
295 |
num_columns = 3 # Number of columns per row
|
|
|
307 |
st.write("URL Invalid...!")
|
308 |
except Exception as e:
|
309 |
st.write(f"An error occurred: {e}")
|
|