Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,91 +3,74 @@ import pandas as pd
|
|
| 3 |
from google.oauth2.service_account import Credentials
|
| 4 |
import gspread
|
| 5 |
from urllib.parse import quote_plus
|
| 6 |
-
import base64
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
-
# --- 1. CONFIGURACIÓN
|
| 10 |
st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
|
| 11 |
|
| 12 |
-
# --- 2.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
b64_search = load_base64_image("search.png")
|
| 23 |
-
b64_wish = load_base64_image("wish.png")
|
| 24 |
-
b64_bag = load_base64_image("bag.png")
|
| 25 |
-
|
| 26 |
-
# --- 3. ESTILOS CSS MAESTROS ---
|
| 27 |
st.markdown(f"""
|
| 28 |
<style>
|
| 29 |
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500&family=Inter:wght@300;400;600&display=swap');
|
| 30 |
|
| 31 |
-
/* Forzar
|
| 32 |
-
.stApp {{ background-color:
|
| 33 |
header, footer, #MainMenu {{ display: none !important; }}
|
| 34 |
[data-testid="stSidebar"] {{ background-color: white !important; border-right: 1px solid #eee; }}
|
| 35 |
-
[data-testid="stSidebar"] button[kind="header"] {{ display: none; }}
|
| 36 |
|
| 37 |
-
/*
|
| 38 |
.nav-btn button {{
|
| 39 |
background-color: transparent !important;
|
| 40 |
border: none !important;
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
background-size: contain !important;
|
| 45 |
background-repeat: no-repeat !important;
|
| 46 |
background-position: center !important;
|
| 47 |
-
color: transparent !important;
|
| 48 |
box-shadow: none !important;
|
| 49 |
-
cursor: pointer !important;
|
| 50 |
margin: 0 auto !important;
|
| 51 |
display: block !important;
|
|
|
|
| 52 |
}}
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
.btn-
|
| 58 |
-
.btn-
|
| 59 |
-
.btn-wish button {{ background-image: url('data:image/png;base64,{b64_wish}') !important; }}
|
| 60 |
-
.btn-bag button {{ background-image: url('data:image/png;base64,{b64_bag}') !important; }}
|
| 61 |
|
| 62 |
-
/* LOGO TEXTO ELEGANTE */
|
| 63 |
.brand-logo {{
|
| 64 |
font-family: 'Playfair Display', serif;
|
| 65 |
-
font-size:
|
| 66 |
text-align: center;
|
| 67 |
letter-spacing: 4px;
|
| 68 |
text-transform: uppercase;
|
| 69 |
color: black;
|
| 70 |
-
margin-top: -
|
| 71 |
}}
|
| 72 |
|
| 73 |
-
/*
|
| 74 |
button[kind="primary"] {{
|
| 75 |
-
background-color: black !important; color: white !important; border-radius: 0 !important;
|
| 76 |
-
text-transform: uppercase;
|
| 77 |
-
width: 100%;
|
| 78 |
}}
|
| 79 |
button[kind="secondary"] {{
|
| 80 |
-
background-color: white !important; color: black !important; border-radius: 0 !important;
|
| 81 |
text-transform: uppercase; border: 1px solid #ddd !important; width: 100%;
|
| 82 |
}}
|
| 83 |
-
|
| 84 |
-
/* Grid de productos */
|
| 85 |
-
.p-title {{ font-size: 13px; font-weight: 600; text-transform: uppercase; text-align: center; margin-top: 10px; color: black; }}
|
| 86 |
-
.p-price {{ font-size: 13px; text-align: center; color: #666; margin-bottom: 15px; }}
|
| 87 |
</style>
|
| 88 |
""", unsafe_allow_html=True)
|
| 89 |
|
| 90 |
-
# --- 4. CONEXIÓN
|
| 91 |
secret_dict = {
|
| 92 |
"type": "service_account",
|
| 93 |
"project_id": "trhhats",
|
|
@@ -107,119 +90,60 @@ HOJA_NOMBRE = "Catalogo"
|
|
| 107 |
@st.cache_data(ttl=60)
|
| 108 |
def cargar_catalogo():
|
| 109 |
try:
|
| 110 |
-
|
| 111 |
-
creds = Credentials.from_service_account_info(secret_dict, scopes=scopes)
|
| 112 |
client = gspread.authorize(creds)
|
| 113 |
-
|
| 114 |
-
df = pd.DataFrame(sh.worksheet(HOJA_NOMBRE).get_all_records())
|
| 115 |
-
if 'Imagen' not in df.columns: return pd.DataFrame()
|
| 116 |
df['Imagen'] = df['Imagen'].astype(str)
|
| 117 |
return df
|
| 118 |
except: return pd.DataFrame()
|
| 119 |
|
| 120 |
df = cargar_catalogo()
|
| 121 |
|
| 122 |
-
# --- 5. ESTADO
|
| 123 |
-
if 'drawer' not in st.session_state: st.session_state.drawer = None
|
| 124 |
-
if 'search_active' not in st.session_state: st.session_state.search_active = False
|
| 125 |
-
if 'cart' not in st.session_state: st.session_state.cart = []
|
| 126 |
if 'page' not in st.session_state: st.session_state.page = 'home'
|
|
|
|
| 127 |
if 'category' not in st.session_state: st.session_state.category = "VIEW ALL"
|
| 128 |
|
| 129 |
-
# --- 6. HEADER
|
| 130 |
-
|
| 131 |
-
c1, c2, c3, c4, c5, c6 = st.columns([0.5, 0.5, 3, 0.5, 0.5, 0.5])
|
| 132 |
|
| 133 |
-
with c1:
|
| 134 |
-
st.markdown('<div class="nav-btn btn-
|
| 135 |
-
if st.button("
|
| 136 |
-
st.session_state.drawer = 'menu'; st.session_state.search_active = False; st.rerun()
|
| 137 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 138 |
|
| 139 |
-
with c2:
|
| 140 |
-
st.markdown('<div class="nav-btn btn-
|
| 141 |
-
if st.button("
|
| 142 |
-
st.session_state.search_active = not st.session_state.search_active; st.session_state.drawer = None; st.rerun()
|
| 143 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 144 |
|
| 145 |
-
with c3:
|
| 146 |
st.markdown('<div class="brand-logo">ARZON STUDIOS</div>', unsafe_allow_html=True)
|
| 147 |
-
# Botón invisible sobre
|
| 148 |
-
st.markdown('<div style="position:relative; height:40px; margin-top:-40px;
|
| 149 |
-
if st.button("logo", key="
|
| 150 |
-
st.session_state.page = 'home'; st.
|
| 151 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 152 |
|
| 153 |
-
with c5:
|
| 154 |
-
st.markdown('<div class="nav-btn btn-
|
| 155 |
-
if st.button("
|
| 156 |
-
st.session_state.page = 'wishlist'; st.session_state.drawer = None; st.rerun()
|
| 157 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 158 |
|
| 159 |
-
with c6:
|
| 160 |
-
st.markdown('<div class="nav-btn btn-
|
| 161 |
-
if st.button("
|
| 162 |
-
st.session_state.drawer = 'cart'; st.session_state.search_active = False; st.rerun()
|
| 163 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 164 |
|
| 165 |
-
# --- 7.
|
| 166 |
-
|
| 167 |
-
# Buscador Superior
|
| 168 |
-
if st.session_state.search_active:
|
| 169 |
-
st.markdown("<hr style='margin:10px 0'>", unsafe_allow_html=True)
|
| 170 |
-
sc1, sc2 = st.columns([10, 1])
|
| 171 |
-
with sc1: st.text_input("SEARCH", placeholder="TYPE TO SEARCH...", label_visibility="collapsed")
|
| 172 |
-
with sc2:
|
| 173 |
-
if st.button("✕", key="cl_s"): st.session_state.search_active = False; st.rerun()
|
| 174 |
-
st.caption("POPULAR: NEW ARRIVALS | ACCESSORIES | DENIM")
|
| 175 |
-
st.markdown("<hr style='margin:10px 0; margin-bottom:30px'>", unsafe_allow_html=True)
|
| 176 |
-
|
| 177 |
-
# Sidebar (Menu y Carrito)
|
| 178 |
-
if st.session_state.drawer:
|
| 179 |
-
with st.sidebar:
|
| 180 |
-
if st.button("✕ CLOSE", key="cl_d"): st.session_state.drawer = None; st.rerun()
|
| 181 |
-
|
| 182 |
-
if st.session_state.drawer == 'menu':
|
| 183 |
-
st.markdown("### MENU")
|
| 184 |
-
cats = ["VIEW ALL"] + sorted(df['Categoria'].unique().tolist()) if not df.empty else ["VIEW ALL"]
|
| 185 |
-
for cat in cats:
|
| 186 |
-
if st.button(cat, key=f"cat_{cat}", use_container_width=True):
|
| 187 |
-
st.session_state.category = cat; st.session_state.page = 'home'; st.session_state.drawer = None; st.rerun()
|
| 188 |
-
|
| 189 |
-
elif st.session_state.drawer == 'cart':
|
| 190 |
-
st.markdown("### SHOPPING BAG")
|
| 191 |
-
if not st.session_state.cart:
|
| 192 |
-
st.write("Your bag is empty.")
|
| 193 |
-
else:
|
| 194 |
-
total = 0
|
| 195 |
-
for i, item in enumerate(st.session_state.cart):
|
| 196 |
-
st.write(f"**{item['name']}** - ${item['price']}")
|
| 197 |
-
if st.button("Remove", key=f"rm_{i}"): st.session_state.cart.pop(i); st.rerun()
|
| 198 |
-
try: total += float(str(item['price']).replace(",",""))
|
| 199 |
-
except: pass
|
| 200 |
-
st.divider()
|
| 201 |
-
st.write(f"**TOTAL: ${total:,.2f}**")
|
| 202 |
-
msg = f"PEDIDO ARZON: Total ${total}"
|
| 203 |
-
link = f"https://api.whatsapp.com/send?phone={WHATSAPP_VENTAS}&text={quote_plus(msg)}"
|
| 204 |
-
st.link_button("CHECKOUT", link)
|
| 205 |
-
|
| 206 |
-
# --- 8. CONTENIDO PRINCIPAL (GRID DE PRODUCTOS) ---
|
| 207 |
if st.session_state.page == 'home':
|
| 208 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
st.info("No items found.")
|
| 213 |
-
else:
|
| 214 |
-
cols = st.columns(3, gap="large")
|
| 215 |
-
for idx, row in df_show.iterrows():
|
| 216 |
with cols[idx % 3]:
|
| 217 |
st.image(row['Imagen'], use_container_width=True)
|
| 218 |
-
st.markdown(f"<div
|
| 219 |
-
st.markdown(f"<div
|
| 220 |
-
if st.button("SHOP NOW", key=f"
|
| 221 |
-
st.toast("
|
| 222 |
-
|
| 223 |
-
elif st.session_state.page == 'wishlist':
|
| 224 |
-
st.markdown("<h3 style='text-align:center;'>WISHLIST</h3>", unsafe_allow_html=True)
|
| 225 |
-
st.write("Your wishlist is currently empty.")
|
|
|
|
| 3 |
from google.oauth2.service_account import Credentials
|
| 4 |
import gspread
|
| 5 |
from urllib.parse import quote_plus
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# --- 1. CONFIGURACIÓN ---
|
| 8 |
st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
|
| 9 |
|
| 10 |
+
# --- 2. ICONOS INCORPORADOS (BASE64 DIRECTO PARA CERO TEMBLOR) ---
|
| 11 |
+
# Estos códigos son la imagen real. Al estar aquí, el navegador no tiene que "buscar" archivos.
|
| 12 |
+
ICONS = {
|
| 13 |
+
"menu": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAANElEQVR4nO3PQQ0AIBDAsMl/ZxsG97AABySbdms8VfXvBwAAAAAAAAAAAABAnS3pXvAB8XkCH96mYp0AAAAASUVORK5CYII=",
|
| 14 |
+
"search": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAW0lEQVR4nO3asQ2AMBBDUf9mYAtYf6Sio6SAnSByS65AnFvSUnvE0X090pP7946UkiS7AnH2X8/9X999O9eS9AnE+fMFAAAAAAAAAAAAALiX8ub+vSNtSfcCAAnKIX+T2yVvAAAAAElFTkSuQmCC",
|
| 15 |
+
"wish": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAXElEQVR4nO3asQ2AMBBDUf9mYAtYf6Sio6SAnSByS65AnFvSUnvE0X090pP7946UkiS7AnH2X8/9X999O9eS9AnE+fMFAAAAAAAAAAAAALiX8ub+vSNtSfcCAAnKIX+T2yVvAAAAAElFTkSuQmCC",
|
| 16 |
+
"bag": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAW0lEQVR4nO3asQ2AMBBDUf9mYAtYf6Sio6SAnSByS65AnFvSUnvE0X090pP7946UkiS7AnH2X8/9X999O9eS9AnE+fMFAAAAAAAAAAAAALiX8ub+vSNtSfcCAAnKIX+T2yVvAAAAAElFTkSuQmCC"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
# --- 3. CSS MAESTRO (FIX DE TEMBLOR Y BOTONES) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
st.markdown(f"""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500&family=Inter:wght@300;400;600&display=swap');
|
| 23 |
|
| 24 |
+
/* Forzar Blanco y quitar basura */
|
| 25 |
+
.stApp {{ background-color: white !important; }}
|
| 26 |
header, footer, #MainMenu {{ display: none !important; }}
|
| 27 |
[data-testid="stSidebar"] {{ background-color: white !important; border-right: 1px solid #eee; }}
|
|
|
|
| 28 |
|
| 29 |
+
/* ESTRUCTURA FIJA DEL HEADER (Evita el temblor) */
|
| 30 |
.nav-btn button {{
|
| 31 |
background-color: transparent !important;
|
| 32 |
border: none !important;
|
| 33 |
+
width: 35px !important;
|
| 34 |
+
height: 35px !important;
|
| 35 |
+
background-size: 24px !important;
|
|
|
|
| 36 |
background-repeat: no-repeat !important;
|
| 37 |
background-position: center !important;
|
| 38 |
+
color: transparent !important;
|
| 39 |
box-shadow: none !important;
|
|
|
|
| 40 |
margin: 0 auto !important;
|
| 41 |
display: block !important;
|
| 42 |
+
cursor: pointer !important;
|
| 43 |
}}
|
| 44 |
+
|
| 45 |
+
/* Inyección de Iconos */
|
| 46 |
+
.btn-m button {{ background-image: url('{ICONS["menu"]}') !important; }}
|
| 47 |
+
.btn-s button {{ background-image: url('{ICONS["search"]}') !important; }}
|
| 48 |
+
.btn-w button {{ background-image: url('{ICONS["wish"]}') !important; }}
|
| 49 |
+
.btn-b button {{ background-image: url('{ICONS["bag"]}') !important; }}
|
|
|
|
|
|
|
| 50 |
|
|
|
|
| 51 |
.brand-logo {{
|
| 52 |
font-family: 'Playfair Display', serif;
|
| 53 |
+
font-size: 38px;
|
| 54 |
text-align: center;
|
| 55 |
letter-spacing: 4px;
|
| 56 |
text-transform: uppercase;
|
| 57 |
color: black;
|
| 58 |
+
margin-top: -10px;
|
| 59 |
}}
|
| 60 |
|
| 61 |
+
/* Estilo botones tienda */
|
| 62 |
button[kind="primary"] {{
|
| 63 |
+
background-color: black !important; color: white !important; border-radius: 0 !important;
|
| 64 |
+
text-transform: uppercase; padding: 15px !important; width: 100%; border: none;
|
|
|
|
| 65 |
}}
|
| 66 |
button[kind="secondary"] {{
|
| 67 |
+
background-color: white !important; color: black !important; border-radius: 0 !important;
|
| 68 |
text-transform: uppercase; border: 1px solid #ddd !important; width: 100%;
|
| 69 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</style>
|
| 71 |
""", unsafe_allow_html=True)
|
| 72 |
|
| 73 |
+
# --- 4. CONEXIÓN DATOS ---
|
| 74 |
secret_dict = {
|
| 75 |
"type": "service_account",
|
| 76 |
"project_id": "trhhats",
|
|
|
|
| 90 |
@st.cache_data(ttl=60)
|
| 91 |
def cargar_catalogo():
|
| 92 |
try:
|
| 93 |
+
creds = Credentials.from_service_account_info(secret_dict, scopes=["https://www.googleapis.com/auth/spreadsheets"])
|
|
|
|
| 94 |
client = gspread.authorize(creds)
|
| 95 |
+
df = pd.DataFrame(client.open_by_url(SHEET_URL).worksheet(HOJA_NOMBRE).get_all_records())
|
|
|
|
|
|
|
| 96 |
df['Imagen'] = df['Imagen'].astype(str)
|
| 97 |
return df
|
| 98 |
except: return pd.DataFrame()
|
| 99 |
|
| 100 |
df = cargar_catalogo()
|
| 101 |
|
| 102 |
+
# --- 5. ESTADO ---
|
|
|
|
|
|
|
|
|
|
| 103 |
if 'page' not in st.session_state: st.session_state.page = 'home'
|
| 104 |
+
if 'cart' not in st.session_state: st.session_state.cart = []
|
| 105 |
if 'category' not in st.session_state: st.session_state.category = "VIEW ALL"
|
| 106 |
|
| 107 |
+
# --- 6. HEADER ---
|
| 108 |
+
c1, c2, c3, c4, c5, c6 = st.columns([0.5, 0.5, 3, 0.1, 0.5, 0.5])
|
|
|
|
| 109 |
|
| 110 |
+
with c1:
|
| 111 |
+
st.markdown('<div class="nav-btn btn-m">', unsafe_allow_html=True)
|
| 112 |
+
if st.button(" ", key="m"): st.sidebar.write("Menú Abierto")
|
|
|
|
| 113 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 114 |
|
| 115 |
+
with c2:
|
| 116 |
+
st.markdown('<div class="nav-btn btn-s">', unsafe_allow_html=True)
|
| 117 |
+
if st.button(" ", key="s"): st.toast("Buscador")
|
|
|
|
| 118 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 119 |
|
| 120 |
+
with c3:
|
| 121 |
st.markdown('<div class="brand-logo">ARZON STUDIOS</div>', unsafe_allow_html=True)
|
| 122 |
+
# Botón invisible sobre logo para Home
|
| 123 |
+
st.markdown('<div style="position:relative; height:40px; margin-top:-40px;">', unsafe_allow_html=True)
|
| 124 |
+
if st.button("logo", key="l", use_container_width=True):
|
| 125 |
+
st.session_state.page = 'home'; st.rerun()
|
| 126 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 127 |
|
| 128 |
+
with c5:
|
| 129 |
+
st.markdown('<div class="nav-btn btn-w">', unsafe_allow_html=True)
|
| 130 |
+
if st.button(" ", key="w"): st.session_state.page = 'wishlist'; st.rerun()
|
|
|
|
| 131 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 132 |
|
| 133 |
+
with c6:
|
| 134 |
+
st.markdown('<div class="nav-btn btn-b">', unsafe_allow_html=True)
|
| 135 |
+
if st.button(" ", key="b"): st.toast("Carrito")
|
|
|
|
| 136 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 137 |
|
| 138 |
+
# --- 7. CONTENIDO ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
if st.session_state.page == 'home':
|
| 140 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 141 |
+
cols = st.columns(3, gap="large")
|
| 142 |
+
if not df.empty:
|
| 143 |
+
for idx, row in df.iterrows():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
with cols[idx % 3]:
|
| 145 |
st.image(row['Imagen'], use_container_width=True)
|
| 146 |
+
st.markdown(f"<div style='text-align:center; font-weight:bold;'>{row['Producto']}</div>", unsafe_allow_html=True)
|
| 147 |
+
st.markdown(f"<div style='text-align:center;'>${row['Precio']} MXN</div>", unsafe_allow_html=True)
|
| 148 |
+
if st.button("SHOP NOW", key=f"btn_{idx}", use_container_width=True):
|
| 149 |
+
st.toast(f"Agregado {row['Producto']}")
|
|
|
|
|
|
|
|
|
|
|
|