sebastrh commited on
Commit
38fb341
·
verified ·
1 Parent(s): bb01617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -139
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 DE PÁGINA ---
10
  st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
11
 
12
- # --- 2. CARGAR IMÁGENES A MEMORIA (Evita el temblor y parpadeo) ---
13
- @st.cache_data
14
- def load_base64_image(file_path):
15
- if os.path.exists(file_path):
16
- with open(file_path, "rb") as f:
17
- return base64.b64encode(f.read()).decode()
18
- return None
19
-
20
- # Cargamos tus iconos
21
- b64_menu = load_base64_image("menu.png")
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 fondo blanco y ocultar interfaz de Streamlit */
32
- .stApp {{ background-color: #ffffff !important; }}
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
- /* ESTILO DE BOTONES ICONO (Convertimos el botón en la imagen) */
38
  .nav-btn button {{
39
  background-color: transparent !important;
40
  border: none !important;
41
- padding: 0 !important;
42
- width: 30px !important;
43
- height: 30px !important;
44
- background-size: contain !important;
45
  background-repeat: no-repeat !important;
46
  background-position: center !important;
47
- color: transparent !important; /* Oculta cualquier texto del botón */
48
  box-shadow: none !important;
49
- cursor: pointer !important;
50
  margin: 0 auto !important;
51
  display: block !important;
 
52
  }}
53
- .nav-btn button:hover {{ opacity: 0.6; transition: 0.2s; }}
54
- .nav-btn button:active {{ transform: scale(0.9); }}
55
-
56
- /* Inyección de las imágenes en los botones */
57
- .btn-menu button {{ background-image: url('data:image/png;base64,{b64_menu}') !important; }}
58
- .btn-search button {{ background-image: url('data:image/png;base64,{b64_search}') !important; }}
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: 40px;
66
  text-align: center;
67
  letter-spacing: 4px;
68
  text-transform: uppercase;
69
  color: black;
70
- margin-top: -15px;
71
  }}
72
 
73
- /* BOTONES DE LA TIENDA */
74
  button[kind="primary"] {{
75
- background-color: black !important; color: white !important; border-radius: 0 !important;
76
- text-transform: uppercase; letter-spacing: 2px; border: none !important; padding: 15px !important;
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 A GOOGLE SHEETS ---
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
- scopes = ["https://www.googleapis.com/auth/spreadsheets"]
111
- creds = Credentials.from_service_account_info(secret_dict, scopes=scopes)
112
  client = gspread.authorize(creds)
113
- sh = client.open_by_url(SHEET_URL)
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 DE LA APP ---
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 (ICONOS REALES) ---
130
- # Columnas: [Menu] [Search] [Logo] [Vacio] [Wish] [Bag]
131
- c1, c2, c3, c4, c5, c6 = st.columns([0.5, 0.5, 3, 0.5, 0.5, 0.5])
132
 
133
- with c1: # ICONO MENU
134
- st.markdown('<div class="nav-btn btn-menu">', unsafe_allow_html=True)
135
- if st.button("m", key="m_btn"):
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: # ICONO SEARCH
140
- st.markdown('<div class="nav-btn btn-search">', unsafe_allow_html=True)
141
- if st.button("s", key="s_btn"):
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: # LOGO TEXTO (Centrado)
146
  st.markdown('<div class="brand-logo">ARZON STUDIOS</div>', unsafe_allow_html=True)
147
- # Botón invisible sobre el texto para regresar a Home
148
- st.markdown('<div style="position:relative; height:40px; margin-top:-40px; cursor:pointer;">', unsafe_allow_html=True)
149
- if st.button("logo", key="l_btn", use_container_width=True):
150
- st.session_state.page = 'home'; st.session_state.drawer = None; st.session_state.search_active = False; st.rerun()
151
  st.markdown('</div>', unsafe_allow_html=True)
152
 
153
- with c5: # ICONO WISH
154
- st.markdown('<div class="nav-btn btn-wish">', unsafe_allow_html=True)
155
- if st.button("w", key="w_btn"):
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: # ICONO BAG
160
- st.markdown('<div class="nav-btn btn-bag">', unsafe_allow_html=True)
161
- if st.button("b", key="b_btn"):
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. COMPONENTES DESPLEGABLES ---
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
- df_show = df if st.session_state.category == "VIEW ALL" else df[df['Categoria'] == st.session_state.category]
210
-
211
- if df_show.empty:
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 class='p-title'>{row['Producto']}</div>", unsafe_allow_html=True)
219
- st.markdown(f"<div class='p-price'>${row['Precio']} MXN</div>", unsafe_allow_html=True)
220
- if st.button("SHOP NOW", key=f"shop_{idx}", type="secondary"):
221
- st.toast("Feature coming soon!")
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']}")