Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,29 +4,27 @@ from google.oauth2.service_account import Credentials
|
|
| 4 |
import gspread
|
| 5 |
import time
|
| 6 |
|
| 7 |
-
# --- 1. CONFIGURACIÓN ---
|
| 8 |
st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
|
| 9 |
|
| 10 |
-
# --- 2. CSS DE LUJO (
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
-
/* FUENTES */
|
| 14 |
-
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;
|
| 15 |
|
| 16 |
-
/*
|
| 17 |
#MainMenu, footer, header, .stDeployButton {display: none;}
|
| 18 |
.stApp { background-color: #ffffff; color: #000000; font-family: 'Inter', sans-serif; }
|
| 19 |
|
| 20 |
-
/*
|
| 21 |
-
.block-container {
|
| 22 |
-
|
| 23 |
-
}
|
| 24 |
-
@keyframes fadeIn {
|
| 25 |
-
0% { opacity: 0; transform: translateY(20px); }
|
| 26 |
-
100% { opacity: 1; transform: translateY(0); }
|
| 27 |
-
}
|
| 28 |
|
| 29 |
-
/* ===
|
|
|
|
|
|
|
|
|
|
| 30 |
div[data-testid="stHorizontalBlock"] .stButton button {
|
| 31 |
background: transparent !important;
|
| 32 |
border: none !important;
|
|
@@ -34,65 +32,95 @@ st.markdown("""
|
|
| 34 |
color: #000000 !important;
|
| 35 |
font-family: 'Inter', sans-serif !important;
|
| 36 |
font-size: 11px !important;
|
| 37 |
-
font-weight:
|
| 38 |
letter-spacing: 2px !important;
|
| 39 |
text-transform: uppercase !important;
|
| 40 |
padding: 0px !important;
|
| 41 |
-
transition:
|
| 42 |
}
|
| 43 |
div[data-testid="stHorizontalBlock"] .stButton button:hover {
|
| 44 |
-
|
| 45 |
-
color: #000000 !important;
|
| 46 |
}
|
| 47 |
|
| 48 |
-
/*
|
| 49 |
div[data-testid="column"]:nth-of-type(3) .stButton button {
|
| 50 |
font-family: 'Playfair Display', serif !important;
|
| 51 |
-
font-size:
|
| 52 |
letter-spacing: 5px !important;
|
| 53 |
-
text-align: center !important;
|
| 54 |
width: 100% !important;
|
| 55 |
margin-top: -12px !important;
|
| 56 |
}
|
| 57 |
|
| 58 |
-
/* ===
|
|
|
|
|
|
|
| 59 |
.stButton button[kind="primary"] {
|
| 60 |
-
background-color: #
|
| 61 |
-
color: #
|
| 62 |
-
border: 1px solid #
|
| 63 |
border-radius: 0px !important;
|
| 64 |
text-transform: uppercase !important;
|
| 65 |
-
font-size:
|
| 66 |
letter-spacing: 2px !important;
|
| 67 |
-
padding:
|
|
|
|
|
|
|
| 68 |
transition: all 0.3s ease !important;
|
| 69 |
}
|
|
|
|
| 70 |
.stButton button[kind="primary"]:hover {
|
| 71 |
-
background-color: #
|
| 72 |
-
color: #
|
| 73 |
}
|
| 74 |
|
| 75 |
-
/* ===
|
| 76 |
-
|
|
|
|
| 77 |
section[data-testid="stSidebar"] {
|
| 78 |
-
background-color:
|
| 79 |
-
border-
|
| 80 |
width: 400px !important;
|
| 81 |
-
|
| 82 |
}
|
| 83 |
|
| 84 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
div[data-testid="stTextInput"] input {
|
| 86 |
border: none !important;
|
| 87 |
-
border-bottom: 1px solid #
|
|
|
|
|
|
|
| 88 |
background: transparent !important;
|
| 89 |
-
|
|
|
|
| 90 |
color: black !important;
|
| 91 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
</style>
|
| 93 |
""", unsafe_allow_html=True)
|
| 94 |
|
| 95 |
-
# --- 3. CONEXIÓN DATOS (
|
| 96 |
secret_dict = {
|
| 97 |
"type": "service_account",
|
| 98 |
"project_id": "trhhats",
|
|
@@ -114,16 +142,17 @@ def cargar_datos():
|
|
| 114 |
creds = Credentials.from_service_account_info(secret_dict, scopes=["https://www.googleapis.com/auth/spreadsheets"])
|
| 115 |
client = gspread.authorize(creds)
|
| 116 |
|
| 117 |
-
# Intentamos abrir la hoja "Catalogo". Si falla,
|
| 118 |
try:
|
| 119 |
sheet = client.open_by_url(SHEET_URL).worksheet("Catalogo")
|
| 120 |
except:
|
| 121 |
sheet = client.open_by_url(SHEET_URL).get_worksheet(0)
|
| 122 |
|
| 123 |
data = sheet.get_all_records()
|
|
|
|
| 124 |
df = pd.DataFrame(data)
|
| 125 |
|
| 126 |
-
# Normalizamos columnas para
|
| 127 |
cols_map = {}
|
| 128 |
for col in df.columns:
|
| 129 |
c = col.lower().strip()
|
|
@@ -138,176 +167,231 @@ def cargar_datos():
|
|
| 138 |
|
| 139 |
df.rename(columns=cols_map, inplace=True)
|
| 140 |
|
| 141 |
-
|
| 142 |
-
if 'Producto' not in df.columns:
|
| 143 |
-
st.error("Error: No encuentro la columna 'Producto' en el Excel.")
|
| 144 |
-
return pd.DataFrame()
|
| 145 |
|
| 146 |
-
# Limpiamos el precio
|
| 147 |
if 'Precio' in df.columns:
|
| 148 |
df['Precio'] = df['Precio'].astype(str).str.replace(r'[$,]', '', regex=True).str.strip()
|
| 149 |
df['Precio'] = pd.to_numeric(df['Precio'], errors='coerce').fillna(0)
|
| 150 |
|
| 151 |
-
return df
|
| 152 |
|
| 153 |
except Exception as e:
|
| 154 |
-
st.error(f"Error cargando catálogo: {e}")
|
| 155 |
return pd.DataFrame()
|
| 156 |
|
| 157 |
-
# --- 4. ESTADO ---
|
| 158 |
-
if 'active_drawer' not in st.session_state: st.session_state.active_drawer = None
|
|
|
|
| 159 |
if 'cart' not in st.session_state: st.session_state.cart = []
|
| 160 |
if 'wishlist' not in st.session_state: st.session_state.wishlist = []
|
| 161 |
if 'page' not in st.session_state: st.session_state.page = 'home'
|
| 162 |
-
if '
|
| 163 |
if 'filter_cat' not in st.session_state: st.session_state.filter_cat = 'VIEW ALL'
|
|
|
|
| 164 |
|
| 165 |
df = cargar_datos()
|
| 166 |
|
| 167 |
-
# --- 5. HEADER (
|
|
|
|
| 168 |
c1, c2, c3, c4, c5 = st.columns([1, 1, 3, 1, 1])
|
| 169 |
|
| 170 |
with c1:
|
| 171 |
-
if st.button("☰ MENÚ", use_container_width=True):
|
| 172 |
st.session_state.active_drawer = 'menu' if st.session_state.active_drawer != 'menu' else None
|
|
|
|
| 173 |
st.rerun()
|
|
|
|
| 174 |
with c2:
|
| 175 |
-
if st.button("🔍 BUSCAR", use_container_width=True):
|
| 176 |
-
st.session_state.
|
|
|
|
| 177 |
st.rerun()
|
|
|
|
| 178 |
with c3:
|
| 179 |
-
|
|
|
|
| 180 |
st.session_state.page = 'home'
|
| 181 |
st.session_state.active_drawer = None
|
|
|
|
| 182 |
st.rerun()
|
|
|
|
| 183 |
with c4:
|
| 184 |
-
if st.button("♡
|
| 185 |
st.session_state.page = 'wishlist'
|
| 186 |
st.session_state.active_drawer = None
|
|
|
|
| 187 |
st.rerun()
|
|
|
|
| 188 |
with c5:
|
| 189 |
-
bag_label = f"BOLSA ({len(st.session_state.cart)})"
|
| 190 |
-
if st.button(bag_label, use_container_width=True):
|
| 191 |
st.session_state.active_drawer = 'cart' if st.session_state.active_drawer != 'cart' else None
|
|
|
|
| 192 |
st.rerun()
|
| 193 |
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
# ---
|
| 197 |
-
# Usamos el sidebar nativo para simular los menús deslizantes
|
| 198 |
if st.session_state.active_drawer:
|
| 199 |
with st.sidebar:
|
| 200 |
-
# BOTÓN CERRAR SUPERIOR
|
| 201 |
-
if st.button("✕ CERRAR", use_container_width=True):
|
| 202 |
-
st.session_state.active_drawer = None
|
| 203 |
-
st.rerun()
|
| 204 |
-
st.markdown("---")
|
| 205 |
-
|
| 206 |
-
# === CAJÓN DE MENÚ ===
|
| 207 |
-
if st.session_state.active_drawer == 'menu':
|
| 208 |
-
st.subheader("COLECCIÓN")
|
| 209 |
-
if not df.empty:
|
| 210 |
-
cats = ["VIEW ALL"] + sorted(df['Categoria'].dropna().unique().tolist())
|
| 211 |
-
for cat in cats:
|
| 212 |
-
if st.button(cat.upper(), use_container_width=True):
|
| 213 |
-
st.session_state.filter_cat = cat
|
| 214 |
-
st.session_state.active_drawer = None
|
| 215 |
-
st.session_state.page = 'home'
|
| 216 |
-
st.rerun()
|
| 217 |
|
| 218 |
-
# === CAJÓN
|
| 219 |
-
|
| 220 |
-
st.
|
| 221 |
-
|
| 222 |
-
if q != st.session_state.search_query:
|
| 223 |
-
st.session_state.search_query = q
|
| 224 |
-
st.session_state.page = 'home'
|
| 225 |
st.rerun()
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
elif st.session_state.active_drawer == 'cart':
|
| 229 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
if not st.session_state.cart:
|
| 231 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
else:
|
| 233 |
total = 0
|
| 234 |
for i, item in enumerate(st.session_state.cart):
|
| 235 |
-
|
| 236 |
-
with
|
| 237 |
img = item.get('img', '')
|
| 238 |
if not str(img).startswith('http'): img = "https://via.placeholder.com/100"
|
| 239 |
st.image(img, use_container_width=True)
|
| 240 |
-
with
|
| 241 |
st.write(f"**{item['name']}**")
|
| 242 |
st.caption(f"{item['size']} | ${item['price']}")
|
| 243 |
-
if st.button("
|
| 244 |
st.session_state.cart.pop(i)
|
| 245 |
st.rerun()
|
| 246 |
-
try: total += float(item['price'])
|
| 247 |
except: pass
|
| 248 |
st.divider()
|
| 249 |
|
| 250 |
-
st.
|
| 251 |
-
msg = f"
|
| 252 |
-
st.link_button("
|
|
|
|
| 253 |
|
| 254 |
-
# ---
|
|
|
|
|
|
|
| 255 |
if st.session_state.page == 'home':
|
|
|
|
| 256 |
if df.empty:
|
| 257 |
-
st.
|
| 258 |
else:
|
| 259 |
# Filtrado
|
| 260 |
d_show = df.copy()
|
| 261 |
-
if st.session_state.filter_cat !=
|
| 262 |
d_show = d_show[d_show['Categoria'] == st.session_state.filter_cat]
|
| 263 |
if st.session_state.search_query:
|
| 264 |
d_show = d_show[d_show.apply(lambda r: st.session_state.search_query.lower() in str(r).lower(), axis=1)]
|
| 265 |
|
| 266 |
if d_show.empty:
|
| 267 |
-
st.
|
| 268 |
else:
|
| 269 |
-
# GRID
|
| 270 |
cols = st.columns(3, gap="large")
|
| 271 |
for idx, row in d_show.iterrows():
|
| 272 |
with cols[idx % 3]:
|
|
|
|
| 273 |
img = row.get('Imagen', '')
|
| 274 |
if not str(img).startswith('http'): img = "https://via.placeholder.com/600x800?text=No+Img"
|
| 275 |
st.image(img, use_container_width=True)
|
| 276 |
|
| 277 |
-
|
| 278 |
-
st.markdown(f"<div style='text-align:center; font-size:12px;
|
|
|
|
| 279 |
|
| 280 |
-
|
|
|
|
| 281 |
st.session_state.selected_product = row.to_dict()
|
| 282 |
st.session_state.page = 'product'
|
| 283 |
st.rerun()
|
| 284 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 285 |
|
| 286 |
-
#
|
| 287 |
elif st.session_state.page == 'product' and st.session_state.selected_product:
|
| 288 |
p = st.session_state.selected_product
|
| 289 |
|
| 290 |
-
if st.button("←
|
| 291 |
st.session_state.page = 'home'
|
| 292 |
st.rerun()
|
|
|
|
| 293 |
|
| 294 |
-
st.
|
| 295 |
-
c1, c2 = st.columns([1.2, 1], gap="large")
|
| 296 |
-
|
| 297 |
with c1:
|
| 298 |
img = p.get('Imagen', '')
|
| 299 |
-
if not str(img).startswith('http'): img = "https://via.placeholder.com/600x800
|
| 300 |
st.image(img, use_container_width=True)
|
| 301 |
-
|
| 302 |
with c2:
|
| 303 |
-
st.markdown(f"## {p.get('Producto', '').upper()}")
|
| 304 |
-
st.markdown(f"### ${p.get('Precio', 0):,.2f}")
|
|
|
|
| 305 |
|
| 306 |
-
|
| 307 |
-
|
|
|
|
| 308 |
|
| 309 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 310 |
-
|
|
|
|
| 311 |
st.session_state.cart.append({
|
| 312 |
"id": p.get('ID'),
|
| 313 |
"name": p.get('Producto'),
|
|
@@ -315,20 +399,13 @@ elif st.session_state.page == 'product' and st.session_state.selected_product:
|
|
| 315 |
"size": size,
|
| 316 |
"img": p.get('Imagen')
|
| 317 |
})
|
| 318 |
-
st.session_state.active_drawer = 'cart'
|
| 319 |
st.rerun()
|
| 320 |
|
| 321 |
st.markdown("---")
|
| 322 |
-
st.
|
| 323 |
|
| 324 |
-
#
|
| 325 |
elif st.session_state.page == 'wishlist':
|
| 326 |
st.subheader("WISHLIST")
|
| 327 |
-
|
| 328 |
-
st.info("Aún no tienes favoritos.")
|
| 329 |
-
else:
|
| 330 |
-
cols = st.columns(3, gap="large")
|
| 331 |
-
for i, item in enumerate(st.session_state.wishlist):
|
| 332 |
-
with cols[i % 3]:
|
| 333 |
-
st.image(item.get('Imagen'), use_container_width=True)
|
| 334 |
-
st.write(f"**{item.get('Producto')}**")
|
|
|
|
| 4 |
import gspread
|
| 5 |
import time
|
| 6 |
|
| 7 |
+
# --- 1. CONFIGURACIÓN DE PÁGINA ---
|
| 8 |
st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
|
| 9 |
|
| 10 |
+
# --- 2. CSS DE LUJO (REPLICA AMIRI) ---
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
+
/* FUENTES: Playfair (Logo) e Inter (UI) */
|
| 14 |
+
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500&family=Inter:wght@300;400;500;600&display=swap');
|
| 15 |
|
| 16 |
+
/* GENERAL */
|
| 17 |
#MainMenu, footer, header, .stDeployButton {display: none;}
|
| 18 |
.stApp { background-color: #ffffff; color: #000000; font-family: 'Inter', sans-serif; }
|
| 19 |
|
| 20 |
+
/* ANIMACIÓN DE ENTRADA SUAVE */
|
| 21 |
+
.block-container { animation: fadeIn 0.5s ease-in-out; }
|
| 22 |
+
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
/* =========================================
|
| 25 |
+
HEADER & NAVEGACIÓN
|
| 26 |
+
========================================= */
|
| 27 |
+
/* Botones de texto limpio (MENU, BUSCAR, ETC) */
|
| 28 |
div[data-testid="stHorizontalBlock"] .stButton button {
|
| 29 |
background: transparent !important;
|
| 30 |
border: none !important;
|
|
|
|
| 32 |
color: #000000 !important;
|
| 33 |
font-family: 'Inter', sans-serif !important;
|
| 34 |
font-size: 11px !important;
|
| 35 |
+
font-weight: 500 !important;
|
| 36 |
letter-spacing: 2px !important;
|
| 37 |
text-transform: uppercase !important;
|
| 38 |
padding: 0px !important;
|
| 39 |
+
transition: color 0.3s ease;
|
| 40 |
}
|
| 41 |
div[data-testid="stHorizontalBlock"] .stButton button:hover {
|
| 42 |
+
color: #666666 !important;
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
+
/* LOGO CENTRAL (Grande y Serif) */
|
| 46 |
div[data-testid="column"]:nth-of-type(3) .stButton button {
|
| 47 |
font-family: 'Playfair Display', serif !important;
|
| 48 |
+
font-size: 34px !important;
|
| 49 |
letter-spacing: 5px !important;
|
|
|
|
| 50 |
width: 100% !important;
|
| 51 |
margin-top: -12px !important;
|
| 52 |
}
|
| 53 |
|
| 54 |
+
/* =========================================
|
| 55 |
+
BOTONES DE ACCIÓN (NEGROS SÓLIDOS)
|
| 56 |
+
========================================= */
|
| 57 |
.stButton button[kind="primary"] {
|
| 58 |
+
background-color: #000000 !important;
|
| 59 |
+
color: #ffffff !important;
|
| 60 |
+
border: 1px solid #000000 !important;
|
| 61 |
border-radius: 0px !important;
|
| 62 |
text-transform: uppercase !important;
|
| 63 |
+
font-size: 11px !important;
|
| 64 |
letter-spacing: 2px !important;
|
| 65 |
+
padding: 16px 20px !important;
|
| 66 |
+
font-weight: 600 !important;
|
| 67 |
+
width: 100% !important;
|
| 68 |
transition: all 0.3s ease !important;
|
| 69 |
}
|
| 70 |
+
/* Animación de inversión (Blanco con borde negro) */
|
| 71 |
.stButton button[kind="primary"]:hover {
|
| 72 |
+
background-color: #ffffff !important;
|
| 73 |
+
color: #000000 !important;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
/* =========================================
|
| 77 |
+
SIDEBAR (CAJONES)
|
| 78 |
+
========================================= */
|
| 79 |
section[data-testid="stSidebar"] {
|
| 80 |
+
background-color: #ffffff !important;
|
| 81 |
+
border-right: 1px solid #f0f0f0;
|
| 82 |
width: 400px !important;
|
| 83 |
+
padding-top: 20px !important;
|
| 84 |
}
|
| 85 |
|
| 86 |
+
/* Botones del Sidebar (Estilo Lista Vertical) */
|
| 87 |
+
section[data-testid="stSidebar"] .stButton button {
|
| 88 |
+
text-align: left !important;
|
| 89 |
+
justify-content: flex-start !important;
|
| 90 |
+
padding-left: 0px !important;
|
| 91 |
+
font-size: 13px !important;
|
| 92 |
+
font-weight: 500 !important;
|
| 93 |
+
border: none !important;
|
| 94 |
+
background: transparent !important;
|
| 95 |
+
margin-bottom: 5px !important;
|
| 96 |
+
}
|
| 97 |
+
section[data-testid="stSidebar"] .stButton button:hover {
|
| 98 |
+
color: #666 !important;
|
| 99 |
+
padding-left: 10px !important; /* Desplazamiento sutil */
|
| 100 |
+
transition: all 0.2s ease;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/* =========================================
|
| 104 |
+
INPUTS (BUSCADOR)
|
| 105 |
+
========================================= */
|
| 106 |
div[data-testid="stTextInput"] input {
|
| 107 |
border: none !important;
|
| 108 |
+
border-bottom: 1px solid #e0e0e0 !important;
|
| 109 |
+
border-radius: 0px !important;
|
| 110 |
+
padding: 10px 0px !important;
|
| 111 |
background: transparent !important;
|
| 112 |
+
font-family: 'Inter', sans-serif !important;
|
| 113 |
+
font-size: 14px !important;
|
| 114 |
color: black !important;
|
| 115 |
}
|
| 116 |
+
div[data-testid="stTextInput"] input:focus {
|
| 117 |
+
border-bottom: 1px solid #000000 !important;
|
| 118 |
+
box-shadow: none !important;
|
| 119 |
+
}
|
| 120 |
</style>
|
| 121 |
""", unsafe_allow_html=True)
|
| 122 |
|
| 123 |
+
# --- 3. CONEXIÓN DATOS (COMPLETA PARA EVITAR ERRORES) ---
|
| 124 |
secret_dict = {
|
| 125 |
"type": "service_account",
|
| 126 |
"project_id": "trhhats",
|
|
|
|
| 142 |
creds = Credentials.from_service_account_info(secret_dict, scopes=["https://www.googleapis.com/auth/spreadsheets"])
|
| 143 |
client = gspread.authorize(creds)
|
| 144 |
|
| 145 |
+
# Intentamos abrir la hoja ESPECÍFICA "Catalogo". Si falla, probamos la primera.
|
| 146 |
try:
|
| 147 |
sheet = client.open_by_url(SHEET_URL).worksheet("Catalogo")
|
| 148 |
except:
|
| 149 |
sheet = client.open_by_url(SHEET_URL).get_worksheet(0)
|
| 150 |
|
| 151 |
data = sheet.get_all_records()
|
| 152 |
+
if not data: return pd.DataFrame()
|
| 153 |
df = pd.DataFrame(data)
|
| 154 |
|
| 155 |
+
# Normalizamos nombres de columnas para evitar errores de mayúsculas/espacios
|
| 156 |
cols_map = {}
|
| 157 |
for col in df.columns:
|
| 158 |
c = col.lower().strip()
|
|
|
|
| 167 |
|
| 168 |
df.rename(columns=cols_map, inplace=True)
|
| 169 |
|
| 170 |
+
if 'Producto' not in df.columns: return pd.DataFrame()
|
|
|
|
|
|
|
|
|
|
| 171 |
|
|
|
|
| 172 |
if 'Precio' in df.columns:
|
| 173 |
df['Precio'] = df['Precio'].astype(str).str.replace(r'[$,]', '', regex=True).str.strip()
|
| 174 |
df['Precio'] = pd.to_numeric(df['Precio'], errors='coerce').fillna(0)
|
| 175 |
|
| 176 |
+
return df[df['Producto'].astype(str).str.strip() != '']
|
| 177 |
|
| 178 |
except Exception as e:
|
|
|
|
| 179 |
return pd.DataFrame()
|
| 180 |
|
| 181 |
+
# --- 4. GESTIÓN DE ESTADO ---
|
| 182 |
+
if 'active_drawer' not in st.session_state: st.session_state.active_drawer = None # 'menu', 'cart', None
|
| 183 |
+
if 'search_open' not in st.session_state: st.session_state.search_open = False
|
| 184 |
if 'cart' not in st.session_state: st.session_state.cart = []
|
| 185 |
if 'wishlist' not in st.session_state: st.session_state.wishlist = []
|
| 186 |
if 'page' not in st.session_state: st.session_state.page = 'home'
|
| 187 |
+
if 'selected_product' not in st.session_state: st.session_state.selected_product = None
|
| 188 |
if 'filter_cat' not in st.session_state: st.session_state.filter_cat = 'VIEW ALL'
|
| 189 |
+
if 'search_query' not in st.session_state: st.session_state.search_query = ""
|
| 190 |
|
| 191 |
df = cargar_datos()
|
| 192 |
|
| 193 |
+
# --- 5. HEADER (REPLICA EXACTA) ---
|
| 194 |
+
# [ MENÚ ] [ BUSCAR ] [ ARZON STUDIOS ] [ FAVORITOS ] [ BOLSA ]
|
| 195 |
c1, c2, c3, c4, c5 = st.columns([1, 1, 3, 1, 1])
|
| 196 |
|
| 197 |
with c1:
|
| 198 |
+
if st.button("☰ MENÚ", key="nav_menu", use_container_width=True):
|
| 199 |
st.session_state.active_drawer = 'menu' if st.session_state.active_drawer != 'menu' else None
|
| 200 |
+
st.session_state.search_open = False
|
| 201 |
st.rerun()
|
| 202 |
+
|
| 203 |
with c2:
|
| 204 |
+
if st.button("🔍 BUSCAR", key="nav_search", use_container_width=True):
|
| 205 |
+
st.session_state.search_open = not st.session_state.search_open
|
| 206 |
+
st.session_state.active_drawer = None
|
| 207 |
st.rerun()
|
| 208 |
+
|
| 209 |
with c3:
|
| 210 |
+
# Logo Central que lleva a home
|
| 211 |
+
if st.button("ARZON STUDIOS", key="nav_logo", use_container_width=True):
|
| 212 |
st.session_state.page = 'home'
|
| 213 |
st.session_state.active_drawer = None
|
| 214 |
+
st.session_state.search_open = False
|
| 215 |
st.rerun()
|
| 216 |
+
|
| 217 |
with c4:
|
| 218 |
+
if st.button("♡ FAVORITOS", key="nav_wish", use_container_width=True):
|
| 219 |
st.session_state.page = 'wishlist'
|
| 220 |
st.session_state.active_drawer = None
|
| 221 |
+
st.session_state.search_open = False
|
| 222 |
st.rerun()
|
| 223 |
+
|
| 224 |
with c5:
|
| 225 |
+
bag_label = "BOLSA" if len(st.session_state.cart) == 0 else f"BOLSA ({len(st.session_state.cart)})"
|
| 226 |
+
if st.button(bag_label, key="nav_bag", use_container_width=True):
|
| 227 |
st.session_state.active_drawer = 'cart' if st.session_state.active_drawer != 'cart' else None
|
| 228 |
+
st.session_state.search_open = False
|
| 229 |
st.rerun()
|
| 230 |
|
| 231 |
+
# --- 6. PANEL DE BÚSQUEDA (IMAGEN 2) ---
|
| 232 |
+
# Se abre debajo del header
|
| 233 |
+
if st.session_state.search_open:
|
| 234 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 235 |
+
c_s1, c_s2 = st.columns([10, 1])
|
| 236 |
+
with c_s1:
|
| 237 |
+
query = st.text_input("BUSCAR", placeholder="TYPE TO SEARCH...", value=st.session_state.search_query, label_visibility="collapsed")
|
| 238 |
+
with c_s2:
|
| 239 |
+
if st.button("✕", key="close_search"):
|
| 240 |
+
st.session_state.search_open = False
|
| 241 |
+
st.rerun()
|
| 242 |
+
|
| 243 |
+
# "POPULAR SEARCHES" como en la imagen 2
|
| 244 |
+
st.caption("POPULAR SEARCHES")
|
| 245 |
+
col_tags = st.columns(4)
|
| 246 |
+
tags = ["MEN'S DENIM", "NEW ARRIVALS", "ACCESSORIES", "SALE"]
|
| 247 |
+
for i, tag in enumerate(tags):
|
| 248 |
+
with col_tags[i]:
|
| 249 |
+
if st.button(tag, key=f"tag_{i}"):
|
| 250 |
+
st.session_state.search_query = tag
|
| 251 |
+
st.session_state.page = 'home'
|
| 252 |
+
st.rerun()
|
| 253 |
+
|
| 254 |
+
if query != st.session_state.search_query:
|
| 255 |
+
st.session_state.search_query = query
|
| 256 |
+
st.session_state.page = 'home'
|
| 257 |
+
st.rerun()
|
| 258 |
+
st.markdown("---")
|
| 259 |
|
| 260 |
+
# --- 7. DRAWERS LATERALES (USANDO SIDEBAR) ---
|
|
|
|
| 261 |
if st.session_state.active_drawer:
|
| 262 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
# === CAJÓN: MENÚ (IMAGEN 1) ===
|
| 265 |
+
if st.session_state.active_drawer == 'menu':
|
| 266 |
+
if st.button("✕ CLOSE", key="close_menu"):
|
| 267 |
+
st.session_state.active_drawer = None
|
|
|
|
|
|
|
|
|
|
| 268 |
st.rerun()
|
| 269 |
+
|
| 270 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 271 |
+
|
| 272 |
+
# Lista vertical limpia
|
| 273 |
+
cats = ["VIEW ALL"]
|
| 274 |
+
if not df.empty and 'Categoria' in df.columns:
|
| 275 |
+
cats += sorted(df['Categoria'].dropna().unique().tolist())
|
| 276 |
+
|
| 277 |
+
# Categorías demo si está vacío
|
| 278 |
+
if df.empty: cats = ["MEN", "WOMEN", "KIDS", "FOOTWEAR", "ACCESSORIES"]
|
| 279 |
+
|
| 280 |
+
for cat in cats:
|
| 281 |
+
if st.button(cat.upper(), key=f"cat_{cat}", use_container_width=True):
|
| 282 |
+
st.session_state.filter_cat = cat
|
| 283 |
+
st.session_state.page = 'home'
|
| 284 |
+
st.session_state.active_drawer = None
|
| 285 |
+
st.rerun()
|
| 286 |
+
|
| 287 |
+
# === CAJÓN: BOLSA (IMAGEN 3) ===
|
| 288 |
elif st.session_state.active_drawer == 'cart':
|
| 289 |
+
c_h1, c_h2 = st.columns([4, 1])
|
| 290 |
+
with c_h1: st.write("SHOPPING BAG")
|
| 291 |
+
with c_h2:
|
| 292 |
+
if st.button("✕"):
|
| 293 |
+
st.session_state.active_drawer = None
|
| 294 |
+
st.rerun()
|
| 295 |
+
|
| 296 |
+
st.markdown("---")
|
| 297 |
+
|
| 298 |
+
# ESTADO VACÍO (Replica exacta Imagen 3)
|
| 299 |
if not st.session_state.cart:
|
| 300 |
+
st.markdown("<br><br>", unsafe_allow_html=True)
|
| 301 |
+
st.markdown("<div style='text-align:center; font-size:14px;'>Your bag is empty</div>", unsafe_allow_html=True)
|
| 302 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 303 |
+
if st.button("CONTINUE SHOPPING", type="primary", use_container_width=True):
|
| 304 |
+
st.session_state.active_drawer = None
|
| 305 |
+
st.session_state.page = 'home'
|
| 306 |
+
st.rerun()
|
| 307 |
+
|
| 308 |
+
# ESTADO CON PRODUCTOS
|
| 309 |
else:
|
| 310 |
total = 0
|
| 311 |
for i, item in enumerate(st.session_state.cart):
|
| 312 |
+
c1, c2 = st.columns([1, 2])
|
| 313 |
+
with c1:
|
| 314 |
img = item.get('img', '')
|
| 315 |
if not str(img).startswith('http'): img = "https://via.placeholder.com/100"
|
| 316 |
st.image(img, use_container_width=True)
|
| 317 |
+
with c2:
|
| 318 |
st.write(f"**{item['name']}**")
|
| 319 |
st.caption(f"{item['size']} | ${item['price']}")
|
| 320 |
+
if st.button("REMOVE", key=f"rm_{i}"):
|
| 321 |
st.session_state.cart.pop(i)
|
| 322 |
st.rerun()
|
| 323 |
+
try: total += float(str(item['price']).replace(",",""))
|
| 324 |
except: pass
|
| 325 |
st.divider()
|
| 326 |
|
| 327 |
+
st.markdown(f"**TOTAL: ${total:,.2f}**")
|
| 328 |
+
msg = f"PEDIDO ARZON: ${total}"
|
| 329 |
+
st.link_button("CHECKOUT (WHATSAPP)", f"https://wa.me/{WHATSAPP}?text={msg}", type="primary", use_container_width=True)
|
| 330 |
+
|
| 331 |
|
| 332 |
+
# --- 8. CONTENIDO PRINCIPAL ---
|
| 333 |
+
|
| 334 |
+
# === HOME ===
|
| 335 |
if st.session_state.page == 'home':
|
| 336 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 337 |
if df.empty:
|
| 338 |
+
st.info("Cargando catálogo...")
|
| 339 |
else:
|
| 340 |
# Filtrado
|
| 341 |
d_show = df.copy()
|
| 342 |
+
if st.session_state.filter_cat != "VIEW ALL" and 'Categoria' in d_show.columns:
|
| 343 |
d_show = d_show[d_show['Categoria'] == st.session_state.filter_cat]
|
| 344 |
if st.session_state.search_query:
|
| 345 |
d_show = d_show[d_show.apply(lambda r: st.session_state.search_query.lower() in str(r).lower(), axis=1)]
|
| 346 |
|
| 347 |
if d_show.empty:
|
| 348 |
+
st.warning("No items found.")
|
| 349 |
else:
|
|
|
|
| 350 |
cols = st.columns(3, gap="large")
|
| 351 |
for idx, row in d_show.iterrows():
|
| 352 |
with cols[idx % 3]:
|
| 353 |
+
# Imagen
|
| 354 |
img = row.get('Imagen', '')
|
| 355 |
if not str(img).startswith('http'): img = "https://via.placeholder.com/600x800?text=No+Img"
|
| 356 |
st.image(img, use_container_width=True)
|
| 357 |
|
| 358 |
+
# Info Minimalista
|
| 359 |
+
st.markdown(f"<div style='text-align:center; font-weight:600; font-size:12px; margin-top:8px;'>{row.get('Producto', '').upper()}</div>", unsafe_allow_html=True)
|
| 360 |
+
st.markdown(f"<div style='text-align:center; font-size:12px; color:#555;'>${row.get('Precio', 0):,.2f}</div>", unsafe_allow_html=True)
|
| 361 |
|
| 362 |
+
# Botón Quick Shop
|
| 363 |
+
if st.button("SHOP NOW", key=f"s_{idx}", type="primary", use_container_width=True):
|
| 364 |
st.session_state.selected_product = row.to_dict()
|
| 365 |
st.session_state.page = 'product'
|
| 366 |
st.rerun()
|
| 367 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 368 |
|
| 369 |
+
# === PRODUCTO ===
|
| 370 |
elif st.session_state.page == 'product' and st.session_state.selected_product:
|
| 371 |
p = st.session_state.selected_product
|
| 372 |
|
| 373 |
+
if st.button("← BACK", key="bk"):
|
| 374 |
st.session_state.page = 'home'
|
| 375 |
st.rerun()
|
| 376 |
+
st.write("")
|
| 377 |
|
| 378 |
+
c1, c2 = st.columns([1.5, 1], gap="large")
|
|
|
|
|
|
|
| 379 |
with c1:
|
| 380 |
img = p.get('Imagen', '')
|
| 381 |
+
if not str(img).startswith('http'): img = "https://via.placeholder.com/600x800"
|
| 382 |
st.image(img, use_container_width=True)
|
|
|
|
| 383 |
with c2:
|
| 384 |
+
st.markdown(f"### {p.get('Producto', '').upper()}")
|
| 385 |
+
st.markdown(f"#### ${p.get('Precio', 0):,.2f}")
|
| 386 |
+
st.write("")
|
| 387 |
|
| 388 |
+
# Tallas
|
| 389 |
+
tallas = str(p.get('Tallas', 'ONE SIZE')).split(',')
|
| 390 |
+
size = st.selectbox("SIZE", [t.strip() for t in tallas])
|
| 391 |
|
| 392 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 393 |
+
# BOTÓN AÑADIR (Negro, invierte color)
|
| 394 |
+
if st.button("ADD TO BAG", type="primary", use_container_width=True):
|
| 395 |
st.session_state.cart.append({
|
| 396 |
"id": p.get('ID'),
|
| 397 |
"name": p.get('Producto'),
|
|
|
|
| 399 |
"size": size,
|
| 400 |
"img": p.get('Imagen')
|
| 401 |
})
|
| 402 |
+
st.session_state.active_drawer = 'cart' # Abre la bolsa automáticamente
|
| 403 |
st.rerun()
|
| 404 |
|
| 405 |
st.markdown("---")
|
| 406 |
+
st.caption(p.get('Descripcion', ''))
|
| 407 |
|
| 408 |
+
# === WISHLIST ===
|
| 409 |
elif st.session_state.page == 'wishlist':
|
| 410 |
st.subheader("WISHLIST")
|
| 411 |
+
st.info("Empty.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|