GianJSX commited on
Commit
23c57e8
1 Parent(s): 2f07243

Upload 3 files

Browse files
Files changed (3) hide show
  1. .streamlit/config.toml +0 -2
  2. ledesma_clean.py +177 -10
  3. requirements.txt +0 -0
.streamlit/config.toml CHANGED
@@ -1,6 +1,4 @@
1
  [theme]
2
  primaryColor="#00a3e0"
3
- backgroundColor="#FAFAFA"
4
  secondaryBackgroundColor="#F0F2F6"
5
- textColor="#262730"
6
  font="sans serif"
 
1
  [theme]
2
  primaryColor="#00a3e0"
 
3
  secondaryBackgroundColor="#F0F2F6"
 
4
  font="sans serif"
ledesma_clean.py CHANGED
@@ -1,19 +1,16 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import csv
4
 
5
  st.image("images/ledesma-logo.png")
6
  st.title('Demo monitoreo de precios')
7
- st.markdown("*Creado para Ledesma*.")
8
- st.write("Creamos este sistema para que puedas monitorear **activamente** los precios de tus productos y los de la competencia a lo largo del pais")
9
  st.divider()
10
- st.write("Para los propositos de esta demo, hemos seleccionado un producto de ledesma, con tres presentaciones distintas, y sus respectivos competidores dentro de la misma gama de productos")
11
 
12
- st.header("Sucursales:")
13
  st.write("Seleccionamos arbitrariamente algunas regiones del pais, e incluimos algunas cadenas de supermercados en cada una de ellas")
14
 
15
  df = pd.read_csv("products.csv")
16
-
17
 
18
  product_stores = pd.read_csv("Store-Products.csv")
19
  stores = pd.read_csv("sucursales.csv")
@@ -56,7 +53,9 @@ st.map(selected_provinces,latitude='lat', longitude='lng')
56
 
57
  st.divider()
58
 
59
- st.image("images/ledesma50u.png")
 
 
60
 
61
  store_codes = selected_provinces['sucursalId'].tolist()
62
  # Seleccion de productos por provincia
@@ -68,8 +67,176 @@ product_stores_filtered = pd.merge(product_stores_filtered, stores, on='sucursal
68
 
69
  #filtrado de vuelta porque aparentemente las referencias de los storesids estan repetidas entre tiendas de distintas provincias
70
  product_stores_filtered = product_stores_filtered[product_stores_filtered['provincia'].isin(province_codes)]
71
- st.write(product_stores_filtered)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- st.header("Comparacion de precios")
 
74
 
75
- st.bar_chart(product_stores_filtered,x='provincia_nombre',y='precio_lista',color='nombre_producto', stack=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import matplotlib.pyplot as plt
4
 
5
  st.image("images/ledesma-logo.png")
6
  st.title('Demo monitoreo de precios')
 
 
7
  st.divider()
 
8
 
9
+ st.subheader("Sucursales:")
10
  st.write("Seleccionamos arbitrariamente algunas regiones del pais, e incluimos algunas cadenas de supermercados en cada una de ellas")
11
 
12
  df = pd.read_csv("products.csv")
13
+ df_historic = pd.read_csv("historico_precios.csv")
14
 
15
  product_stores = pd.read_csv("Store-Products.csv")
16
  stores = pd.read_csv("sucursales.csv")
 
53
 
54
  st.divider()
55
 
56
+ st.subheader("Producto elegido:")
57
+ st.write("Endulzante Stevia en Sobres Ledesma 50 Un")
58
+ st.image("images/ledesma50u.png", width=250)
59
 
60
  store_codes = selected_provinces['sucursalId'].tolist()
61
  # Seleccion de productos por provincia
 
67
 
68
  #filtrado de vuelta porque aparentemente las referencias de los storesids estan repetidas entre tiendas de distintas provincias
69
  product_stores_filtered = product_stores_filtered[product_stores_filtered['provincia'].isin(province_codes)]
70
+ #st.write(product_stores_filtered)
71
+ st.divider()
72
+ st.subheader("Comparacion de precios")
73
+
74
+ st.bar_chart(product_stores_filtered,x='provincia_nombre',y='precio_lista', color='nombre_producto', stack=False, y_label='Precio', x_label='Provincia', horizontal=False, height=500)
75
+ st.divider()
76
+ st.subheader("Historico de variacion de precios de ledesma y competencia")
77
+
78
+
79
+
80
+ # Convertir el string CSV en un DataFrame
81
+
82
+ df = pd.read_csv("historico_precios.csv")
83
+
84
+ # Convertir la columna 'fecha' a tipo datetime
85
+ df['fecha'] = pd.to_datetime(df['fecha'], format='%d-%m-%Y')
86
+
87
+ # Colores específicos
88
+ highlight_product = "Endulzante Stevia en Sobres Ledesma 50 Un"
89
+ highlight_color = '#1f77b4' # Azul
90
+ # Colores personalizados para los productos secundarios
91
+ secondary_colors = ['#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22']
92
 
93
+ # Establecer un estilo más moderno
94
+ plt.style.use('fast')
95
 
96
+ # Crear el gráfico de líneas
97
+ fig, ax = plt.subplots(figsize=(10, 6))
98
+
99
+
100
+ # Dibujar todas las líneas con colores distintos
101
+ for i, producto in enumerate(df['producto'].unique()):
102
+ if producto != highlight_product:
103
+ subset = df[df['producto'] == producto]
104
+ ax.plot(subset['fecha'], subset['precio'], label=producto, color=secondary_colors[i % len(secondary_colors)], alpha=0.5)
105
+
106
+ # Dibujar la línea del producto principal al final
107
+ subset = df[df['producto'] == highlight_product]
108
+ ax.plot(subset['fecha'], subset['precio'], marker='o', label=highlight_product, color=highlight_color, linewidth=3)
109
+
110
+ # Mejorar la visualización
111
+ ax.set_ylabel('Precio', fontsize=14)
112
+ #ax.set_title('Precio de Productos a lo Largo del Tiempo', fontsize=16)
113
+
114
+ # Colocar la leyenda abajo del área del gráfico
115
+ ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.20), fontsize=10, ncol=2)
116
+ # Ajustar los ticks del eje x para mostrar todas las fechas
117
+ ax.set_xticks(df['fecha'])
118
+ ax.set_xticklabels(df['fecha'].dt.strftime('%d-%m-%Y'), rotation=45, ha='right')
119
+
120
+ # Ajustar el diseño para que la leyenda no se corte
121
+ plt.tight_layout()
122
+ ax.grid(True, linestyle='--', color='gray', alpha=0.17)
123
+
124
+ # Mostrar el gráfico en Streamlit
125
+ st.pyplot(fig)
126
+
127
+ st.divider()
128
+ import streamlit.components.v1 as components
129
+ components.html("""
130
+ <head>
131
+ <meta charset="UTF-8">
132
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
133
+ <title>Monitoreo de Precios</title>
134
+ <style>
135
+ body {
136
+ font-family: Arial, sans-serif;
137
+ margin: 0;
138
+ }
139
+ .container {
140
+ background-color: white;
141
+
142
+ margin: auto;
143
+ }
144
+ .product-image {
145
+ display: flex;
146
+ align-items: center;
147
+ justify-content: space-between;
148
+ }
149
+ .product-image img {
150
+ width: 150px;
151
+ }
152
+ .price-current {
153
+ font-size: 1.5rem;
154
+ font-weight: bold;
155
+ margin-top: 10px;
156
+ }
157
+ .table-container {
158
+ margin-top: 20px;
159
+ }
160
+ table {
161
+ width: 100%;
162
+ border-collapse: collapse;
163
+ }
164
+ table th, table td {
165
+ padding: 12px;
166
+ text-align: left;
167
+ border-bottom: 1px solid #ddd;
168
+ }
169
+ table th {
170
+ background-color: #f9f9f9;
171
+ }
172
+ .price-up {
173
+ color: red;
174
+ font-weight: bold;
175
+ }
176
+ .price-down {
177
+ color: green;
178
+ font-weight: bold;
179
+ }
180
+ .available {
181
+ color: green;
182
+ }
183
+ .not-available {
184
+ color: rgb(255, 0, 0);
185
+ }
186
+ .store-logo {
187
+ width: 24px;
188
+ vertical-align: middle;
189
+ margin-right: 10px;
190
+ }
191
+ </style>
192
+ </head>
193
+ <body>
194
+ <div class="container">
195
+ <div class="product-image">
196
+ <div>
197
+ <h2>Monitoreo de Precios de Azucar ledesma 1 kg</h2>
198
+ <p class="price-current">Precio actual: $970,00</p>
199
+ </div>
200
+ <img src=" https://huggingface.co/spaces/GianJSX/precios-demo/resolve/main/images/azucar-logo.png" alt="Scooter">
201
+ </div>
202
+
203
+ <div class="table-container">
204
+ <h3>Comparativa de precios</h3>
205
+ <table>
206
+ <thead>
207
+ <tr>
208
+ <th>Tienda</th>
209
+ <th>Precio</th>
210
+ <th>Cambio (%)</th>
211
+ <th>Stock</th>
212
+ </tr>
213
+ </thead>
214
+ <tbody>
215
+ <tr>
216
+ <td><img src=" https://huggingface.co/spaces/GianJSX/precios-demo/resolve/main/images/carrefour-Logo.png" alt="Carrefour" class="store-logo"> Carrefour</td>
217
+ <td>$1100</td>
218
+ <td class="price-up">+13.4%</td>
219
+ <td class="available">Disponible</td>
220
+ </tr>
221
+ <tr>
222
+ <td><img src=" https://huggingface.co/spaces/GianJSX/precios-demo/resolve/main/images/disco.png" alt="Disco" class="store-logo">Disco</td>
223
+ <td>$950</td>
224
+ <td class="price-down">-2.7%</td>
225
+ <td class="not-available">No disponible</td>
226
+
227
+ </tr>
228
+ <tr>
229
+ <td><img src=" https://huggingface.co/spaces/GianJSX/precios-demo/resolve/main/images/vea.png" alt="Vea" class="store-logo">Vea</td>
230
+ <td>$1050</td>
231
+ <td class="price-up">+8.2%</td>
232
+ <td class="available">Disponible</td>
233
+
234
+ </tr>
235
+ </tbody>
236
+ </table>
237
+ </div>
238
+ </div>
239
+ </body>
240
+
241
+ """
242
+ , height=600)
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ