Spaces:
Sleeping
Sleeping
Delete product_similarity.py
Browse files- product_similarity.py +0 -256
product_similarity.py
DELETED
@@ -1,256 +0,0 @@
|
|
1 |
-
# VGG16
|
2 |
-
import pandas as pd
|
3 |
-
import streamlit as st
|
4 |
-
from tensorflow.keras.preprocessing import image as kimage
|
5 |
-
from cryptography.fernet import Fernet
|
6 |
-
import os
|
7 |
-
|
8 |
-
from io import BytesIO
|
9 |
-
from dotenv import load_dotenv
|
10 |
-
|
11 |
-
|
12 |
-
load_dotenv()
|
13 |
-
|
14 |
-
|
15 |
-
dec_key =os.getenv("FERNET_KEY")
|
16 |
-
|
17 |
-
cipher_suite=Fernet(dec_key)
|
18 |
-
|
19 |
-
# Read the encrypted content from model.py.enc file
|
20 |
-
with open('model.py.enc', 'rb') as file:
|
21 |
-
encrypted_model = file.read()
|
22 |
-
|
23 |
-
decrypted_model = cipher_suite.decrypt(encrypted_model)
|
24 |
-
decrypted_model_str = decrypted_model.decode()
|
25 |
-
|
26 |
-
# Execute the decrypted model string
|
27 |
-
exec(decrypted_model_str)
|
28 |
-
st.set_page_config(
|
29 |
-
layout="wide",
|
30 |
-
initial_sidebar_state="expanded",
|
31 |
-
)
|
32 |
-
|
33 |
-
@st.cache_data
|
34 |
-
def load_data():
|
35 |
-
# Read the encrypted content from the Excel file
|
36 |
-
with open('pantolon-v3.xlsx.enc', 'rb') as file:
|
37 |
-
encrypted_data = file.read()
|
38 |
-
|
39 |
-
# Decrypt the data
|
40 |
-
decrypted_data = cipher_suite.decrypt(encrypted_data)
|
41 |
-
|
42 |
-
# Load the decrypted data into a pandas DataFrame
|
43 |
-
df = pd.read_excel(BytesIO(decrypted_data))
|
44 |
-
|
45 |
-
return df
|
46 |
-
|
47 |
-
|
48 |
-
# Read the encrypted content from model.py.enc file
|
49 |
-
with open('model_takemura.py.enc', 'rb') as file:
|
50 |
-
encrypted_model_takemura = file.read()
|
51 |
-
|
52 |
-
decrypted_model_takemura = cipher_suite.decrypt(encrypted_model_takemura)
|
53 |
-
decrypted_model_str_takemura = decrypted_model_takemura.decode()
|
54 |
-
|
55 |
-
# Execute the decrypted model string
|
56 |
-
exec(decrypted_model_str_takemura)
|
57 |
-
|
58 |
-
# from model_takemura import *
|
59 |
-
|
60 |
-
|
61 |
-
# Read the encrypted content from model.py.enc file
|
62 |
-
with open('model_hayabusa.py.enc', 'rb') as file:
|
63 |
-
encrypted_model_hayabusa = file.read()
|
64 |
-
|
65 |
-
decrypted_model_hayabusa = cipher_suite.decrypt(encrypted_model_hayabusa)
|
66 |
-
decrypted_model_str_hayabusa = decrypted_model_hayabusa.decode()
|
67 |
-
|
68 |
-
# Execute the decrypted model string
|
69 |
-
exec(decrypted_model_str_hayabusa)
|
70 |
-
|
71 |
-
#
|
72 |
-
# from model_hayabusa import *
|
73 |
-
|
74 |
-
|
75 |
-
def page1():
|
76 |
-
st.title("Ürün Benzerlik Analizi")
|
77 |
-
st.write(
|
78 |
-
"Ürün benzerlik analizi, ürününüzün fotoğrafını yükleyerek benzer ürünleri ve verilerini bulmanızı sağlar.")
|
79 |
-
|
80 |
-
image = st.sidebar.file_uploader("Lütfen ürününüzün fotoğrafını yükleyin:")
|
81 |
-
|
82 |
-
st.markdown("""
|
83 |
-
<style>
|
84 |
-
|
85 |
-
.stTabs [data-baseweb="tab-list"] {
|
86 |
-
gap: 20px;
|
87 |
-
padding: 10px/* Increase the gap between tabs */
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
.stTabs [data-baseweb="tab-list"] button [data-testid="stMarkdownContainer"] p {
|
92 |
-
font-size:1.5rem;
|
93 |
-
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
|
94 |
-
}
|
95 |
-
|
96 |
-
.stTabs [data-baseweb="tab"] {
|
97 |
-
height: 50px;
|
98 |
-
white-space: pre-wrap;
|
99 |
-
border-radius: 12px; /* Make the tabs look like pills */
|
100 |
-
padding: 10px 20px; /* Add padding to the tabs */
|
101 |
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); /* Add shadow to the tabs */
|
102 |
-
transition: background-color 0.3s ease; /* Add transition effect */
|
103 |
-
color: #333; /* Change the text color to a soft black */
|
104 |
-
}
|
105 |
-
|
106 |
-
.stTabs [aria-selected="true"] {
|
107 |
-
background-color: #e0e0e0; /* Change the background color to a soft gray */
|
108 |
-
border-color: #3d5afe; /* Add border color to the selected tab */
|
109 |
-
color: #ffffff; /* Change the text color to a soft blue */;
|
110 |
-
}
|
111 |
-
|
112 |
-
.stTabs [aria-selected="true"]:hover {
|
113 |
-
background-color: #d0d0d0; /* Change background color when hover on the selected tab */
|
114 |
-
}
|
115 |
-
|
116 |
-
</style>""", unsafe_allow_html=True)
|
117 |
-
|
118 |
-
tab1, tab2 = st.tabs(["Takemura", "Hayabusa"])
|
119 |
-
|
120 |
-
if image is not None:
|
121 |
-
st.sidebar.success("Görsel başarıyla yüklendi.")
|
122 |
-
|
123 |
-
product_category = st.sidebar.selectbox("Lütfen ürün kategorisi seçin:",
|
124 |
-
["Pantolon", "Gömlek - (Test)", "Elbise - (Test)", "Ceket - (Test)", "Hırka - (Test)"])
|
125 |
-
if product_category == "Pantolon":
|
126 |
-
|
127 |
-
default_product_details = ["Desen", "Bel", "Paça"] # Assign a default value
|
128 |
-
|
129 |
-
product_details = st.sidebar.multiselect("Benzerlik için öncelik sırasına göre detay seçin:",
|
130 |
-
["Bel", "Desen", "Paça"],
|
131 |
-
default=default_product_details)
|
132 |
-
|
133 |
-
if not product_details: # If product_details is an empty list
|
134 |
-
st.sidebar.error("En az 1 özellik seçilmelidir.")
|
135 |
-
|
136 |
-
with tab1:
|
137 |
-
if st.button("Takemura ile Analiz Yap"):
|
138 |
-
status_placeholder = st.empty()
|
139 |
-
status_placeholder.status("Analizi yapılıyor...")
|
140 |
-
|
141 |
-
filenames = model_1(image)
|
142 |
-
st.session_state['filenames'] = filenames
|
143 |
-
st.session_state['image'] = image
|
144 |
-
st.session_state['analysis_done'] = True
|
145 |
-
|
146 |
-
status_placeholder.success("Analiz tamamlandı.")
|
147 |
-
|
148 |
-
if 'analysis_done' in st.session_state and st.session_state['analysis_done']:
|
149 |
-
show_results_button = st.button("Sonuçları Göster", key='button1')
|
150 |
-
|
151 |
-
if show_results_button and ('show_results' not in st.session_state or not st.session_state['show_results']):
|
152 |
-
st.session_state['show_results'] = True
|
153 |
-
|
154 |
-
if 'show_results' in st.session_state:
|
155 |
-
image_dir = "general/PANTOLON"
|
156 |
-
df = load_data()
|
157 |
-
st.empty()
|
158 |
-
|
159 |
-
for _ in range(5):
|
160 |
-
try:
|
161 |
-
takemura_output = takemura(st.session_state['filenames'], image, product_details)
|
162 |
-
filenames = takemura_output.split('\n')
|
163 |
-
|
164 |
-
for filename in filenames:
|
165 |
-
filename_without_extension = os.path.splitext(filename)[0]
|
166 |
-
filename_without_extension = filename_without_extension.split('_')[0]
|
167 |
-
|
168 |
-
matching_rows = df.loc[df['ItemOption'] == filename_without_extension]
|
169 |
-
|
170 |
-
if not matching_rows.empty:
|
171 |
-
for _, row in matching_rows.iterrows():
|
172 |
-
cols = st.columns([2, 9]) # Adjust these values for desired widths
|
173 |
-
img_path = os.path.join(image_dir, filename)
|
174 |
-
img = kimage.load_img(img_path)
|
175 |
-
cols[0].image(img, width=200)
|
176 |
-
half = len(row) // 2 # Find the midpoint of the row
|
177 |
-
|
178 |
-
# Split the row into two parts
|
179 |
-
row_upper_half = row.iloc[:half]
|
180 |
-
row_lower_half = row.iloc[half:]
|
181 |
-
|
182 |
-
# Display the two parts in two separate dataframes
|
183 |
-
cols[1].dataframe(pd.DataFrame(row_upper_half).T)
|
184 |
-
cols[1].dataframe(pd.DataFrame(row_lower_half).T)
|
185 |
-
else:
|
186 |
-
st.write(f"Ürün isimlerini maalesef eşleştiremedim {filename_without_extension}")
|
187 |
-
break
|
188 |
-
|
189 |
-
except Exception as e:
|
190 |
-
st.write(f"An error occurred: {e}")
|
191 |
-
st.write(f"Takemura için Lütfen 'Sonuçları Göster' butonuna tekrar basınız.. ...")
|
192 |
-
|
193 |
-
st.session_state['show_results'] = False
|
194 |
-
|
195 |
-
with tab2:
|
196 |
-
if st.button("Hayabusa ile Analiz Yap"):
|
197 |
-
status_placeholder = st.empty()
|
198 |
-
status_placeholder.status("Analizi yapılıyor...")
|
199 |
-
|
200 |
-
filenames = model_2(image)
|
201 |
-
st.session_state['filenames'] = filenames
|
202 |
-
st.session_state['image'] = image
|
203 |
-
st.session_state['analysis_done'] = True
|
204 |
-
|
205 |
-
status_placeholder.success("Analiz tamamlandı.")
|
206 |
-
|
207 |
-
if 'analysis_done' in st.session_state and st.session_state['analysis_done']:
|
208 |
-
show_results_button = st.button("Hayabusa Sonuçlarını Göster", key='button2')
|
209 |
-
if show_results_button and ('show_results' not in st.session_state or not st.session_state['show_results']):
|
210 |
-
st.session_state['show_results'] = True
|
211 |
-
|
212 |
-
if 'show_results' in st.session_state:
|
213 |
-
image_dir = "general/PANTOLON"
|
214 |
-
df = load_data()
|
215 |
-
st.empty()
|
216 |
-
|
217 |
-
for _ in range(5):
|
218 |
-
try:
|
219 |
-
takemura_output = takemura(st.session_state['filenames'], image, product_details)
|
220 |
-
filenames = takemura_output.split('\n')
|
221 |
-
|
222 |
-
for filename in filenames:
|
223 |
-
filename_without_extension = os.path.splitext(filename)[0]
|
224 |
-
filename_without_extension = filename_without_extension.split('_')[0]
|
225 |
-
|
226 |
-
matching_rows = df.loc[df['ItemOption'] == filename_without_extension]
|
227 |
-
|
228 |
-
if not matching_rows.empty:
|
229 |
-
for _, row in matching_rows.iterrows():
|
230 |
-
cols = st.columns([2, 8]) # Adjust these values for desired widths
|
231 |
-
img_path = os.path.join(image_dir, filename)
|
232 |
-
img = kimage.load_img(img_path)
|
233 |
-
cols[0].image(img, width=200)
|
234 |
-
# cols[1].dataframe(pd.DataFrame(row).T)
|
235 |
-
half = len(row) // 2 # Find the midpoint of the row
|
236 |
-
|
237 |
-
# Split the row into two parts
|
238 |
-
row_upper_half = row.iloc[:half]
|
239 |
-
row_lower_half = row.iloc[half:]
|
240 |
-
|
241 |
-
# Display the two parts in two separate dataframes
|
242 |
-
cols[1].dataframe(pd.DataFrame(row_upper_half).T)
|
243 |
-
cols[1].dataframe(pd.DataFrame(row_lower_half).T)
|
244 |
-
else:
|
245 |
-
st.write(f"Ürün isimlerini maalesef eşleştiremedim {filename_without_extension}")
|
246 |
-
break
|
247 |
-
|
248 |
-
except Exception as e:
|
249 |
-
st.write(f"Hayabusa için Lütfen 'Sonuçları Göster' butonuna tekrar basınız.. ...")
|
250 |
-
|
251 |
-
st.session_state['show_results'] = False
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
else:
|
256 |
-
st.write("Please upload an image.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|