sebastrh commited on
Commit
cbbaf1a
·
verified ·
1 Parent(s): 0aaca37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +173 -125
app.py CHANGED
@@ -1,149 +1,197 @@
1
  import streamlit as st
2
- import pandas as pd
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 "DIBUJADOS" POR CÓDIGO (SVG) ---
11
- # Al no ser archivos externos, cargan instantáneamente y NUNCA se quitan.
12
- ICO_MENU = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='3' y1='12' x2='21' y2='12'%3E%3C/line%3E%3Cline x1='3' y1='6' x2='21' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='18' x2='21' y2='18'%3E%3C/line%3E%3C/svg%3E"
13
- ICO_SEARCH = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E"
14
- ICO_WISH = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z'%3E%3C/path%3E%3C/svg%3E"
15
- ICO_BAG = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z'%3E%3C/path%3E%3Cline x1='3' y1='6' x2='21' y2='6'%3E%3C/line%3E%3Cpath d='M16 10a4 4 0 0 1-8 0'%3E%3C/path%3E%3C/svg%3E"
16
-
17
- # --- 3. CSS MAESTRO (PNG COMO BOTÓN REAL) ---
 
 
 
 
 
 
 
 
 
 
18
  st.markdown(f"""
19
  <style>
20
- @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500&family=Inter:wght@300;400;600&display=swap');
21
-
22
- /* Forzar Blanco y ocultar basura nativa */
23
- [data-testid="stAppViewContainer"], .stApp {{ background-color: white !important; }}
24
- header, footer, #MainMenu, .stDeployButton {{ display: none !important; }}
25
-
26
- /* EL BOTÓN ES EL ICONO (SIN SOBREPONER) */
27
- .nav-btn button {{
28
- background-color: transparent !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  border: none !important;
30
- box-shadow: none !important;
31
- background-size: 22px !important;
32
- background-repeat: no-repeat !important;
33
- background-position: center !important;
34
- width: 30px !important;
35
- height: 30px !important;
36
- color: transparent !important; /* Texto invisible */
37
- padding: 0 !important;
38
- margin: 0 auto !important;
39
- display: block !important;
40
  cursor: pointer !important;
41
  }}
42
-
43
- .nav-btn button:hover {{ opacity: 0.5; transition: 0.2s; }}
44
-
45
- /* Inyección de Iconos */
46
- .btn-m button {{ background-image: url("{ICO_MENU}") !important; }}
47
- .btn-s button {{ background-image: url("{ICO_SEARCH}") !important; }}
48
- .btn-w button {{ background-image: url("{ICO_WISH}") !important; }}
49
- .btn-b button {{ background-image: url("{ICO_BAG}") !important; }}
50
-
51
- /* LOGO TEXTO (CENTRO PERFECTO) */
52
- .brand-logo {{
53
- font-family: 'Playfair Display', serif;
54
- font-size: 38px;
55
  text-align: center;
56
- letter-spacing: 5px;
57
- text-transform: uppercase;
58
- color: black;
59
- margin-top: -12px;
60
  }}
61
-
62
- .logo-reset button {{
63
- position: absolute; top: -10px; left: 0; width: 100%; height: 50px;
64
- background: transparent !important; border: none !important; color: transparent !important;
65
- opacity: 0 !important; z-index: 10;
66
  }}
67
 
68
- /* UI TIENDA */
69
- .shop-btn button {{
70
- background: white !important; border: 1px solid #ddd !important; border-radius: 0 !important;
71
- text-transform: uppercase; font-size: 11px !important; color: black !important; width: 100%;
 
 
 
 
 
 
 
 
 
 
72
  }}
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
76
- # --- 4. CONEXIÓN DATOS ---
77
- secret_dict = {
78
- "type": "service_account",
79
- "project_id": "trhhats",
80
- "private_key_id": "1555421e0c8cd47026bc9907341110db25be89d3",
81
- "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpDyDrQBSXf0Bi\nr7KTd4P4c0JszG02wl4Wq0AhMK6VV97dK14WfUXhRVvR86Gg38TC1+nT0RRy1F30\ndN9doT7gOx1khZXSmKTEN9jKGRSC381FiMFA3ziinkm5Kq6dDHS2ldLOYOtmwwbd\n0MTDVLH9/qvnW2siTwJlV0oDJbqqZIoJoh9LEGXq8OHe954G1OQka+mBwOOaMhJN\n/gcB6reu6jjO2gHlmG/R544GOSqILBiVXtfkVZUAVeDRyeD9TzVNVnpWrSTpni4E\nig55j2XO295qxI0vNfkiWzNdKOs4Iv+hh7WcJT8X1kLvOaYzZZ+RaZOgCpDoq41w\ncibhw6ntAgMBAAECggEAIXPE58f+Sxv6+YwaoeN8UaU895pb4gID7ChmwCqJ4TNJ\n/imerISNV04KJTk4OkUNAiEHO8qbaT1sefrGWBiYAHayEjn8s3dQ4yLJ2vOrg1oV\nnDS7SMLiygrYO7OeaaUVUyvCUuQKsILW0P2GccBImCHUkiscv+UybCshkg3dKen4\nHYrFCi3T+w86d82KZRj5Oq89lhBu7p8izSItdkaFUWytV7OQr86kiguLZHyRftP6\nDd6gG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84
-
85
- @st.cache_data(ttl=60)
86
- def cargar_catalogo():
87
- try:
88
- creds = Credentials.from_service_account_info(secret_dict, scopes=["https://www.googleapis.com/auth/spreadsheets"])
89
- client = gspread.authorize(creds)
90
- sh = client.open_by_url("https://docs.google.com/spreadsheets/d/1K6Jsg8dZ9ToXQJZuXyn2pLTQTAOFf7Snf7BOA_xS9Rs/edit?usp=sharing")
91
- df = pd.DataFrame(sh.worksheet("Catalogo").get_all_records())
92
- df['Imagen'] = df['Imagen'].astype(str)
93
- return df
94
- except: return pd.DataFrame()
95
-
96
- df = cargar_catalogo()
97
-
98
- # --- 5. ESTADOS ---
99
  if 'page' not in st.session_state: st.session_state.page = 'home'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
- # --- 6. HEADER (ESTILO AMIRI) ---
102
- # Columnas: [Menú] [Search] [ARZON STUDIOS] [Wish] [Bag]
103
- h_cols = st.columns([0.5, 0.5, 3.5, 0.5, 0.5])
104
-
105
- with h_cols[0]: # MENU
106
- st.markdown('<div class="nav-btn btn-m">', unsafe_allow_html=True)
107
- if st.button(" ", key="m"): st.sidebar.write("Menú")
108
- st.markdown('</div>', unsafe_allow_html=True)
109
-
110
- with h_cols[1]: # SEARCH
111
- st.markdown('<div class="nav-btn btn-s">', unsafe_allow_html=True)
112
- st.button(" ", key="s")
113
- st.markdown('</div>', unsafe_allow_html=True)
114
-
115
- with h_cols[2]: # LOGO TEXTO
116
- st.markdown('<div class="brand-logo">ARZON STUDIOS</div>', unsafe_allow_html=True)
117
- st.markdown('<div class="logo-reset">', unsafe_allow_html=True)
118
- if st.button(" ", key="logo_home"):
119
- st.session_state.page = 'home'; st.rerun()
120
- st.markdown('</div>', unsafe_allow_html=True)
121
-
122
- with h_cols[3]: # WISH
123
- st.markdown('<div class="nav-btn btn-w">', unsafe_allow_html=True)
124
- if st.button(" ", key="w"):
125
- st.session_state.page = 'wishlist'; st.rerun()
126
- st.markdown('</div>', unsafe_allow_html=True)
127
-
128
- with h_cols[4]: # BAG
129
- st.markdown('<div class="nav-btn btn-b">', unsafe_allow_html=True)
130
- st.button(" ", key="b")
131
- st.markdown('</div>', unsafe_allow_html=True)
132
 
133
  # --- 7. CONTENIDO ---
134
  if st.session_state.page == 'home':
135
- st.markdown("<br><br>", unsafe_allow_html=True)
136
- if not df.empty:
137
- cols = st.columns(3, gap="large")
138
- for i, row in df.iterrows():
139
- with cols[i % 3]:
140
- st.image(row['Imagen'], use_container_width=True)
141
- st.markdown(f"<div style='text-align:center; font-weight:600; margin-top:10px;'>{row['Producto']}</div>", unsafe_allow_html=True)
142
- st.markdown(f"<div style='text-align:center; margin-bottom:10px;'>${row['Precio']} MXN</div>", unsafe_allow_html=True)
143
- st.markdown('<div class="shop-btn">', unsafe_allow_html=True)
144
- st.button("SHOP NOW", key=f"s_{i}")
145
- st.markdown('</div>', unsafe_allow_html=True)
146
- st.write("")
147
- elif st.session_state.page == 'wishlist':
148
- st.markdown("<h3 style='text-align:center;'>WISHLIST</h3>", unsafe_allow_html=True)
149
- st.info("Empty")
 
1
  import streamlit as st
2
+ import base64
3
+ import os
 
4
  from urllib.parse import quote_plus
5
 
6
  # --- 1. CONFIGURACIÓN ---
7
  st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")
8
 
9
+ # --- 2. FUNCIÓN PARA CARGAR TUS IMÁGENES ---
10
+ def get_img_as_base64(file_path):
11
+ try:
12
+ with open(file_path, "rb") as f:
13
+ data = f.read()
14
+ return base64.b64encode(data).decode()
15
+ except:
16
+ return "" # Si no encuentra la imagen, no falla
17
+
18
+ # Cargar las imágenes en memoria (Rápido)
19
+ img_menu = get_img_as_base64("menu.png")
20
+ img_search = get_img_as_base64("search.png")
21
+ img_logo = get_img_as_base64("logo.png")
22
+ img_user = get_img_as_base64("user.png")
23
+ img_wish = get_img_as_base64("wish.png")
24
+ img_bag = get_img_as_base64("bag.png")
25
+
26
+ # --- 3. CSS "BLOQUE DE CEMENTO" (PARA QUE NO TIEMBLE) ---
27
  st.markdown(f"""
28
  <style>
29
+ /* Forzar modo claro siempre */
30
+ [data-testid="stAppViewContainer"], .stApp, header {{
31
+ background-color: #ffffff !important;
32
+ color: black !important;
33
+ }}
34
+
35
+ /* Ocultar cosas nativas que causan ruido visual */
36
+ #MainMenu, footer, header, [data-testid="stToolbar"] {{display: none !important;}}
37
+ .stDeployButton {{display: none;}}
38
+
39
+ /* === CONTENEDOR DE ICONOS === */
40
+ /* Esto asegura que la imagen y el botón ocupen EL MISMO espacio siempre */
41
+ .nav-container {{
42
+ position: relative;
43
+ width: 30px;
44
+ height: 30px;
45
+ margin: 0 auto;
46
+ }}
47
+
48
+ /* La Imagen de fondo */
49
+ .nav-img {{
50
+ width: 100%;
51
+ height: 100%;
52
+ object-fit: contain;
53
+ position: absolute;
54
+ top: 0;
55
+ left: 0;
56
+ z-index: 1;
57
+ }}
58
+
59
+ /* El Botón Invisible (Click) */
60
+ .nav-container button {{
61
+ position: absolute !important;
62
+ top: 0 !important;
63
+ left: 0 !important;
64
+ width: 100% !important;
65
+ height: 100% !important;
66
+ z-index: 5 !important;
67
+ opacity: 0 !important; /* Totalmente invisible */
68
+ background: red !important; /* Color dummy */
69
  border: none !important;
 
 
 
 
 
 
 
 
 
 
70
  cursor: pointer !important;
71
  }}
72
+ /* Prevenir que se vea negro al hacer click */
73
+ .nav-container button:active, .nav-container button:focus {{
74
+ background: transparent !important;
75
+ outline: none !important;
76
+ border: none !important;
77
+ }}
78
+
79
+ /* Logo Central */
80
+ .logo-container {{
 
 
 
 
81
  text-align: center;
82
+ width: 100%;
83
+ margin-top: -10px;
 
 
84
  }}
85
+ .logo-img {{
86
+ height: 40px; /* Ajusta el tamaño de tu logo aquí */
87
+ object-fit: contain;
 
 
88
  }}
89
 
90
+ /* Grid Fijo para evitar saltos */
91
+ [data-testid="stVerticalBlock"] {{ gap: 0 !important; }}
92
+
93
+ /* Estilos Generales */
94
+ .drawer-item button {{
95
+ text-align: left !important; border: none; background: transparent;
96
+ width: 100%; padding: 15px; border-bottom: 1px solid #eee;
97
+ text-transform: uppercase; letter-spacing: 2px; font-size: 12px;
98
+ }}
99
+ .drawer-item button:hover {{ font-weight: bold; background: #fafafa; }}
100
+
101
+ .black-btn button {{
102
+ background: black !important; color: white !important; width: 100%;
103
+ padding: 15px; text-transform: uppercase; letter-spacing: 2px; border-radius: 0;
104
  }}
105
  </style>
106
  """, unsafe_allow_html=True)
107
 
108
+ # --- 4. ESTADO ---
109
+ if 'active_drawer' not in st.session_state: st.session_state.active_drawer = None
110
+ if 'cart' not in st.session_state: st.session_state.cart = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  if 'page' not in st.session_state: st.session_state.page = 'home'
112
+ if 'search_query' not in st.session_state: st.session_state.search_query = ""
113
+
114
+ # --- 5. HEADER CON TUS IMÁGENES ---
115
+ c1, c2, c3, c4, c5, c6 = st.columns([0.5, 0.5, 3, 0.5, 0.5, 0.5])
116
+
117
+ def img_btn(col, img_b64, key, callback):
118
+ with col:
119
+ # Aquí está el truco: Dibujamos la imagen Y el botón en el mismo HTML wrapper
120
+ st.markdown(f"""
121
+ <div class="nav-container">
122
+ <img src="data:image/png;base64,{img_b64}" class="nav-img">
123
+ </div>
124
+ """, unsafe_allow_html=True)
125
+
126
+ # Botón invisible de Streamlit "flotando" encima
127
+ # Usamos CSS negativo para subirlo sobre la imagen
128
+ st.markdown('<div class="nav-container" style="margin-top: -30px;">', unsafe_allow_html=True)
129
+ if st.button(" ", key=key):
130
+ callback()
131
+ st.markdown('</div>', unsafe_allow_html=True)
132
+
133
+ # ACCIONES
134
+ def toggle_menu(): st.session_state.active_drawer = 'menu' if st.session_state.active_drawer != 'menu' else None
135
+ def toggle_cart(): st.session_state.active_drawer = 'cart' if st.session_state.active_drawer != 'cart' else None
136
+ def go_home(): st.session_state.page = 'home'; st.session_state.active_drawer = None
137
+
138
+ # RENDERIZAR HEADER
139
+ img_btn(c1, img_menu, "btn_menu", toggle_menu)
140
+ img_btn(c2, img_search, "btn_search", lambda: st.toast("Search clicked"))
141
+
142
+ with c3: # LOGO
143
+ if img_logo:
144
+ st.markdown(f'<div class="logo-container"><img src="data:image/png;base64,{img_logo}" class="logo-img"></div>', unsafe_allow_html=True)
145
+ else:
146
+ st.markdown('<h2 style="text-align:center; margin:0; padding:0;">ARZON</h2>', unsafe_allow_html=True)
147
+ # Botón invisible sobre logo
148
+ st.markdown('<div style="height:40px; margin-top:-40px; opacity:0"><button style="width:100%; height:100%">.</button></div>', unsafe_allow_html=True)
149
+
150
+ img_btn(c4, img_user, "btn_user", lambda: None)
151
+ img_btn(c5, img_wish, "btn_wish", lambda: None)
152
+ img_btn(c6, img_bag, "btn_bag", toggle_cart)
153
+
154
+ st.markdown("---") # Línea separadora header
155
+
156
+ # --- 6. CAJONES (DRAWERS) ---
157
+ if st.session_state.active_drawer:
158
+ with st.sidebar:
159
+ # Botón Cerrar
160
+ if st.button("✕ CERRAR", key="close_x"):
161
+ st.session_state.active_drawer = None
162
+ st.rerun()
163
+
164
+ if st.session_state.active_drawer == 'menu':
165
+ st.markdown("### MENU")
166
+ cats = ["VIEW ALL", "ACCESORIOS", "HOODIES", "PANTS", "T-SHIRTS"]
167
+ for cat in cats:
168
+ st.markdown('<div class="drawer-item">', unsafe_allow_html=True)
169
+ if st.button(cat, key=f"c_{cat}"):
170
+ st.session_state.page = 'home'
171
+ st.session_state.active_drawer = None
172
+ st.rerun()
173
+ st.markdown('</div>', unsafe_allow_html=True)
174
 
175
+ elif st.session_state.active_drawer == 'cart':
176
+ st.markdown("<h3 style='text-align:center;'>SHOPPING BAG</h3>", unsafe_allow_html=True)
177
+ if not st.session_state.cart:
178
+ st.info("Your bag is empty")
179
+ st.markdown('<div class="black-btn">', unsafe_allow_html=True)
180
+ if st.button("CONTINUE SHOPPING"):
181
+ st.session_state.active_drawer = None
182
+ st.rerun()
183
+ st.markdown('</div>', unsafe_allow_html=True)
184
+ else:
185
+ for item in st.session_state.cart:
186
+ st.write(f"- {item}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  # --- 7. CONTENIDO ---
189
  if st.session_state.page == 'home':
190
+ # Aquí iría tu grid de productos (usando el código anterior de cargar_catalogo)
191
+ st.markdown("<div style='text-align:center; margin-top:50px;'>GRID DE PRODUCTOS AQUÍ</div>", unsafe_allow_html=True)
192
+
193
+ # Ejemplo visual para probar estabilidad
194
+ c1, c2, c3 = st.columns(3)
195
+ with c1:
196
+ st.image("https://via.placeholder.com/300x400?text=Product+1")
197
+ st.button("SHOP NOW", key="p1")