Spaces:
Running
Running
vishalkatheriya18
commited on
Commit
•
1408ebf
1
Parent(s):
5f0ae39
Update app.py
Browse files
app.py
CHANGED
@@ -16,15 +16,14 @@ if 'models_loaded' not in st.session_state:
|
|
16 |
st.session_state.models_loaded = True
|
17 |
|
18 |
# Define image processing and classification functions
|
19 |
-
def imageprocessing(
|
20 |
-
response = requests.get(url)
|
21 |
-
image = Image.open(BytesIO(response.content))
|
22 |
encoding = st.session_state.image_processor(image.convert("RGB"), return_tensors="pt")
|
23 |
-
return encoding
|
24 |
|
25 |
def topwear(encoding):
|
26 |
outputs = st.session_state.top_wear_model(**encoding)
|
27 |
predicted_class_idx = outputs.logits.argmax(-1).item()
|
|
|
28 |
return st.session_state.top_wear_model.config.id2label[predicted_class_idx]
|
29 |
|
30 |
def patterns(encoding):
|
@@ -43,8 +42,8 @@ def sleevelengths(encoding):
|
|
43 |
return st.session_state.sleeve_length_model.config.id2label[predicted_class_idx]
|
44 |
|
45 |
# Run all models in parallel
|
46 |
-
def pipes(
|
47 |
-
encoding
|
48 |
|
49 |
results = [None] * 4
|
50 |
|
@@ -70,20 +69,26 @@ def pipes(image_url):
|
|
70 |
"sleeve_length": results[3]
|
71 |
}
|
72 |
|
73 |
-
return result_dict
|
74 |
|
75 |
# Streamlit app UI
|
76 |
st.title("Clothing Classification Pipeline")
|
77 |
|
78 |
-
|
79 |
-
if
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
st.session_state.models_loaded = True
|
17 |
|
18 |
# Define image processing and classification functions
|
19 |
+
def imageprocessing(image):
|
|
|
|
|
20 |
encoding = st.session_state.image_processor(image.convert("RGB"), return_tensors="pt")
|
21 |
+
return encoding
|
22 |
|
23 |
def topwear(encoding):
|
24 |
outputs = st.session_state.top_wear_model(**encoding)
|
25 |
predicted_class_idx = outputs.logits.argmax(-1).item()
|
26 |
+
st.write(st.session_state.top_wear_model.config.id2label[predicted_class_idx])
|
27 |
return st.session_state.top_wear_model.config.id2label[predicted_class_idx]
|
28 |
|
29 |
def patterns(encoding):
|
|
|
42 |
return st.session_state.sleeve_length_model.config.id2label[predicted_class_idx]
|
43 |
|
44 |
# Run all models in parallel
|
45 |
+
def pipes(image):
|
46 |
+
encoding = imageprocessing(image)
|
47 |
|
48 |
results = [None] * 4
|
49 |
|
|
|
69 |
"sleeve_length": results[3]
|
70 |
}
|
71 |
|
72 |
+
return result_dict
|
73 |
|
74 |
# Streamlit app UI
|
75 |
st.title("Clothing Classification Pipeline")
|
76 |
|
77 |
+
url = st.text_input("Paste image URL here...")
|
78 |
+
if url:
|
79 |
+
response = requests.get(url)
|
80 |
+
if response.status_code == 200:
|
81 |
+
image = Image.open(BytesIO(response.content))
|
82 |
+
st.image(image.resize((200, 200)), caption="Uploaded Image", use_column_width=False)
|
83 |
+
|
84 |
+
start_time = time.time()
|
85 |
+
|
86 |
+
try:
|
87 |
+
result = pipes(image)
|
88 |
+
st.write("Classification Results (JSON):")
|
89 |
+
st.json(result) # Display results in JSON format
|
90 |
+
st.write(f"Time taken: {time.time() - start_time:.2f} seconds")
|
91 |
+
except Exception as e:
|
92 |
+
st.error(f"Error processing the image: {str(e)}")
|
93 |
+
else:
|
94 |
+
st.error("Failed to load image from URL. Please check the URL.")
|