vishalkatheriya18 commited on
Commit
b1e655a
1 Parent(s): bb3c537

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -207
app.py CHANGED
@@ -1,205 +1,3 @@
1
- # import streamlit as st
2
- # from transformers import AutoModelForImageClassification, AutoImageProcessor
3
- # from ultralytics import YOLO
4
- # from PIL import Image, ImageDraw
5
- # import requests
6
- # from io import BytesIO
7
- # import cv2
8
- # import numpy as np
9
- # import matplotlib.pyplot as plt
10
- # import concurrent.futures
11
-
12
- # # Categories dictionary
13
- # categories_dict = {
14
- # "UpperBody": ["top, t-shirt, sweatshirt", "shirt", "blouse", "top", "t-shirt", "sweatshirt", "sweater", "cardigan", "jacket", "vest"],
15
- # "Lowerbody": ["pants", "shorts", "skirt"],
16
- # "Wholebody": ["coat", "dress", "jumpsuit", "cape"],
17
- # "Head": ["glasses", "hat", "headband", "head covering", "hair accessory"],
18
- # "Neck": ["tie"],
19
- # "Arms and Hands": ["glove", "watch"],
20
- # "Waist": ["belt"],
21
- # "Legs and Feet": ["leg warmer", "tights", "stockings", "sock", "shoe"],
22
- # "Others": ["bag", "wallet", "scarf", "umbrella"],
23
- # "Garment parts": ["hood", "collar", "lapel", "epaulette", "sleeve", "pocket", "neckline"],
24
- # "Closures": ["buckle", "zipper"],
25
- # "Decorations": ["applique", "bead", "bow", "flower", "fringe", "ribbon", "rivet", "ruffle", "sequin", "tassel"]
26
- # }
27
-
28
- # def find_category(subcategory):
29
- # for category, subcategories in categories_dict.items():
30
- # if subcategory in subcategories:
31
- # return category
32
- # return "Subcategory not found."
33
-
34
- # # Load models and processor only once using Streamlit session state
35
- # if 'models_loaded' not in st.session_state:
36
- # st.session_state.segment_model = YOLO("best.pt")
37
- # st.write("Model loaded!")
38
- # st.session_state.models_loaded = True
39
-
40
- # # Streamlit app UI
41
- # st.title("Clothing Classification Pipeline")
42
- # url = st.sidebar.text_input("Paste image URL here...")
43
-
44
- # if url:
45
- # try:
46
- # response = requests.get(url)
47
- # if response.status_code == 200:
48
- # image = Image.open(BytesIO(response.content))
49
- # st.sidebar.image(image.resize((200, 200)), caption="Uploaded Image", use_column_width=False)
50
-
51
- # # Convert image to numpy array for YOLO model
52
- # image_np = np.array(image)
53
-
54
- # # Perform inference
55
- # results = st.session_state.segment_model(image_np)
56
-
57
- # # Create a copy of the original image to draw bounding boxes and labels
58
- # output_image = image_np.copy()
59
-
60
- # # Visualize the segmentation results
61
- # for result in results:
62
- # boxes = result.boxes # Bounding boxes
63
- # classes = result.names # Class names of the detected objects
64
-
65
- # for i, box in enumerate(boxes):
66
- # box_coords = box.xyxy[0].cpu().numpy().astype(int)
67
- # x1, y1, x2, y2 = box_coords
68
-
69
- # # Draw the bounding box on the original image
70
- # cv2.rectangle(output_image, (x1, y1), (x2, y2), color=(0, 255, 0), thickness=2)
71
-
72
- # # Get the class label and confidence score for the object
73
- # class_label = classes[box.cls[0].int().item()]
74
- # confidence = box.conf[0].item()
75
-
76
- # # Prepare the label text with class and confidence
77
- # label_text = f'{class_label}: {confidence:.2f}'
78
-
79
- # # Put text label on the original image
80
- # cv2.putText(output_image, label_text, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
81
-
82
- # # Crop the image based on the bounding box
83
- # cropped_image = image_np[y1:y2, x1:x2].copy()
84
- # category_name = find_category(class_label)
85
-
86
- # # Display the cropped image with class and probability in the title
87
- # st.image(cropped_image, caption=f'Class: {category_name}, Confidence: {confidence:.2f}')
88
-
89
- # # Display the original image with bounding boxes and labels
90
- # st.image(output_image, caption="Segmented Image", channels="RGB")
91
-
92
- # else:
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
@@ -207,19 +5,19 @@ import requests
207
  from io import BytesIO
208
  import numpy as np
209
  import cv2
210
-
211
  # Categories dictionary
212
  categories_dict = {
213
- "UpperBody": ["top", "t-shirt", "sweatshirt", "shirt", "blouse", "sweater", "cardigan", "jacket", "vest"],
214
  "Lowerbody": ["pants", "shorts", "skirt"],
215
  "Wholebody": ["coat", "dress", "jumpsuit", "cape"],
216
  "Head": ["glasses", "hat", "headband", "head covering", "hair accessory"],
217
- "Neck": ["tie"],
218
- "Arms and Hands": ["glove", "watch"],
219
  "Waist": ["belt"],
220
  "Legs and Feet": ["leg warmer", "tights", "stockings", "sock", "shoe"],
221
  "Others": ["bag", "wallet", "scarf", "umbrella"],
222
- "Garment parts": ["hood", "collar", "lapel", "epaulette", "sleeve", "pocket", "neckline"],
223
  "Closures": ["buckle", "zipper"],
224
  "Decorations": ["applique", "bead", "bow", "flower", "fringe", "ribbon", "rivet", "ruffle", "sequin", "tassel"]
225
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from ultralytics import YOLO
3
  from PIL import Image
 
5
  from io import BytesIO
6
  import numpy as np
7
  import cv2
8
+ import concurrent.futures
9
  # Categories dictionary
10
  categories_dict = {
11
+ "UpperBody": ["top", "t-shirt", "sweatshirt", "blouse", "sweater", "cardigan", "jacket", "vest"],
12
  "Lowerbody": ["pants", "shorts", "skirt"],
13
  "Wholebody": ["coat", "dress", "jumpsuit", "cape"],
14
  "Head": ["glasses", "hat", "headband", "head covering", "hair accessory"],
15
+ "Neck": ["tie", "neckline"],
16
+ "Arms and Hands": ["glove", "watch","sleeve"],
17
  "Waist": ["belt"],
18
  "Legs and Feet": ["leg warmer", "tights", "stockings", "sock", "shoe"],
19
  "Others": ["bag", "wallet", "scarf", "umbrella"],
20
+ "Garment parts": ["hood", "collar", "lapel", "epaulette","pocket"],
21
  "Closures": ["buckle", "zipper"],
22
  "Decorations": ["applique", "bead", "bow", "flower", "fringe", "ribbon", "rivet", "ruffle", "sequin", "tassel"]
23
  }