File size: 10,567 Bytes
5d49f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2a9652
5d49f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2a9652
 
5d49f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a46fc5d
5d49f6f
f2a9652
5d49f6f
 
 
 
 
 
 
 
 
 
f2a9652
5d49f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
f2a9652
5d49f6f
 
 
f2a9652
5d49f6f
 
 
 
 
 
f2a9652
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# VGG16
import pandas as pd
import streamlit as st
from tensorflow.keras.preprocessing import image as kimage
from cryptography.fernet import Fernet
import os

from io import BytesIO
from dotenv import load_dotenv


load_dotenv()


dec_key =os.getenv("FERNET_KEY")

cipher_suite=Fernet(dec_key)

# Read the encrypted content from model.py.enc file
with open('model.py.enc', 'rb') as file:
    encrypted_model = file.read()

decrypted_model = cipher_suite.decrypt(encrypted_model)
decrypted_model_str = decrypted_model.decode()

# Execute the decrypted model string
exec(decrypted_model_str)
st.set_page_config(
    layout="wide",
    initial_sidebar_state="expanded",
)

@st.cache_data
def load_data():
    # Read the encrypted content from the Excel file
    with open('pantolon-v3.xlsx.enc', 'rb') as file:
        encrypted_data = file.read()

    # Decrypt the data
    decrypted_data = cipher_suite.decrypt(encrypted_data)

    # Load the decrypted data into a pandas DataFrame
    df = pd.read_excel(BytesIO(decrypted_data))

    return df


# Read the encrypted content from model.py.enc file
with open('model_takemura.py.enc', 'rb') as file:
    encrypted_model_takemura = file.read()

decrypted_model_takemura = cipher_suite.decrypt(encrypted_model_takemura)
decrypted_model_str_takemura = decrypted_model_takemura.decode()

# Execute the decrypted model string
exec(decrypted_model_str_takemura)

# from model_takemura import *


# Read the encrypted content from model.py.enc file
with open('model_hayabusa.py.enc', 'rb') as file:
    encrypted_model_hayabusa = file.read()

decrypted_model_hayabusa = cipher_suite.decrypt(encrypted_model_hayabusa)
decrypted_model_str_hayabusa = decrypted_model_hayabusa.decode()

# Execute the decrypted model string
exec(decrypted_model_str_hayabusa)

#
# from model_hayabusa import *


def page1():
    st.title("Ürün Benzerlik Analizi")
    st.write(
        "Ürün benzerlik analizi, ürününüzün fotoğrafını yükleyerek benzer ürünleri ve verilerini bulmanızı sağlar.")

    image = st.sidebar.file_uploader("Lütfen ürününüzün fotoğrafını yükleyin:")

    st.markdown("""
    <style>
        
        .stTabs [data-baseweb="tab-list"] {
            gap: 20px;
            padding: 10px/* Increase the gap between tabs */
            
        }
        
        .stTabs [data-baseweb="tab-list"] button [data-testid="stMarkdownContainer"] p {
        font-size:1.5rem;
        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
        }

        .stTabs [data-baseweb="tab"] {
            height: 50px;
            white-space: pre-wrap;
            border-radius: 12px;  /* Make the tabs look like pills */
            padding: 10px 20px;  /* Add padding to the tabs */
            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 */
            transition: background-color 0.3s ease; /* Add transition effect */
            color: #333; /* Change the text color to a soft black */
        }

        .stTabs [aria-selected="true"] {
            background-color: #e0e0e0; /* Change the background color to a soft gray */
            border-color: #3d5afe; /* Add border color to the selected tab */
            color: #ffffff; /* Change the text color to a soft blue */;
        }

        .stTabs [aria-selected="true"]:hover {
            background-color: #d0d0d0; /* Change background color when hover on the selected tab */
        }

    </style>""", unsafe_allow_html=True)

    tab1, tab2 = st.tabs(["Takemura", "Hayabusa"])

    if image is not None:
        st.sidebar.success("Görsel başarıyla yüklendi.")

        product_category = st.sidebar.selectbox("Lütfen ürün kategorisi seçin:",
                                                ["Pantolon", "Gömlek - (Test)", "Elbise - (Test)", "Ceket - (Test)", "Hırka - (Test)"])
        if product_category == "Pantolon":

            default_product_details = ["Desen", "Bel", "Paça"]  # Assign a default value

            product_details = st.sidebar.multiselect("Benzerlik için öncelik sırasına göre detay seçin:",
                                                     ["Bel", "Desen", "Paça"],
                                                     default=default_product_details)

            if not product_details:  # If product_details is an empty list
                st.sidebar.error("En az 1 özellik seçilmelidir.")

        with tab1:
            if st.button("Takemura ile Analiz Yap"):
                status_placeholder = st.empty()
                status_placeholder.status("Analizi yapılıyor...")

                filenames = model_1(image)
                st.session_state['filenames'] = filenames
                st.session_state['image'] = image
                st.session_state['analysis_done'] = True

                status_placeholder.success("Analiz tamamlandı.")

            if 'analysis_done' in st.session_state and st.session_state['analysis_done']:
                show_results_button = st.button("Sonuçları Göster", key='button1')

                if show_results_button and ('show_results' not in st.session_state or not st.session_state['show_results']):
                    st.session_state['show_results'] = True

            if 'show_results' in st.session_state:
                image_dir = "general/PANTOLON"
                df = load_data()
                st.empty()

                for _ in range(5):
                    try:
                        takemura_output = takemura(st.session_state['filenames'], image, product_details)
                        filenames = takemura_output.split('\n')

                        for filename in filenames:
                            filename_without_extension = os.path.splitext(filename)[0]
                            filename_without_extension = filename_without_extension.split('_')[0]

                            matching_rows = df.loc[df['ItemOption'] == filename_without_extension]

                            if not matching_rows.empty:
                                for _, row in matching_rows.iterrows():
                                    cols = st.columns([2, 9])  # Adjust these values for desired widths
                                    img_path = os.path.join(image_dir, filename)
                                    img = kimage.load_img(img_path)
                                    cols[0].image(img, width=200)
                                    half = len(row) // 2  # Find the midpoint of the row

                                    # Split the row into two parts
                                    row_upper_half = row.iloc[:half]
                                    row_lower_half = row.iloc[half:]

                                    # Display the two parts in two separate dataframes
                                    cols[1].dataframe(pd.DataFrame(row_upper_half).T)
                                    cols[1].dataframe(pd.DataFrame(row_lower_half).T)
                            else:
                                st.write(f"Ürün isimlerini maalesef eşleştiremedim {filename_without_extension}")
                        break

                    except Exception as e:
                        st.write(f"An error occurred: {e}")
                        st.write(f"Takemura için Lütfen 'Sonuçları Göster' butonuna tekrar basınız.. ...")

                st.session_state['show_results'] = False

        with tab2:
            if st.button("Hayabusa ile Analiz Yap"):
                status_placeholder = st.empty()
                status_placeholder.status("Analizi yapılıyor...")

                filenames = model_2(image)
                st.session_state['filenames'] = filenames
                st.session_state['image'] = image
                st.session_state['analysis_done'] = True

                status_placeholder.success("Analiz tamamlandı.")

            if 'analysis_done' in st.session_state and st.session_state['analysis_done']:
                show_results_button = st.button("Hayabusa Sonuçlarını Göster", key='button2')
                if show_results_button and ('show_results' not in st.session_state or not st.session_state['show_results']):
                    st.session_state['show_results'] = True

            if 'show_results' in st.session_state:
                image_dir = "general/PANTOLON"
                df = load_data()
                st.empty()

                for _ in range(5):
                    try:
                        takemura_output = takemura(st.session_state['filenames'], image, product_details)
                        filenames = takemura_output.split('\n')

                        for filename in filenames:
                            filename_without_extension = os.path.splitext(filename)[0]
                            filename_without_extension = filename_without_extension.split('_')[0]

                            matching_rows = df.loc[df['ItemOption'] == filename_without_extension]

                            if not matching_rows.empty:
                                for _, row in matching_rows.iterrows():
                                    cols = st.columns([2, 8])  # Adjust these values for desired widths
                                    img_path = os.path.join(image_dir, filename)
                                    img = kimage.load_img(img_path)
                                    cols[0].image(img, width=200)
                                    # cols[1].dataframe(pd.DataFrame(row).T)
                                    half = len(row) // 2  # Find the midpoint of the row

                                    # Split the row into two parts
                                    row_upper_half = row.iloc[:half]
                                    row_lower_half = row.iloc[half:]

                                    # Display the two parts in two separate dataframes
                                    cols[1].dataframe(pd.DataFrame(row_upper_half).T)
                                    cols[1].dataframe(pd.DataFrame(row_lower_half).T)
                            else:
                                st.write(f"Ürün isimlerini maalesef eşleştiremedim {filename_without_extension}")
                        break

                    except Exception as e:
                        st.write(f"Hayabusa için Lütfen 'Sonuçları Göster' butonuna tekrar basınız.. ...")

                st.session_state['show_results'] = False



    else:
        st.write("Please upload an image.")