Upload 4 files
Browse files- Dockerfile +34 -0
- README.md +3 -4
- app.py +146 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
# Instalar curl para el healthcheck
|
6 |
+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
7 |
+
|
8 |
+
# Crear directorio de caché y configurar permisos
|
9 |
+
RUN mkdir -p /app/.cache && \
|
10 |
+
mkdir -p /app/configs && \
|
11 |
+
chmod -R 777 /app/.cache && \
|
12 |
+
chmod -R 777 /app/configs
|
13 |
+
|
14 |
+
# Copiar e instalar dependencias
|
15 |
+
COPY requirements.txt .
|
16 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
17 |
+
|
18 |
+
# Copiar el resto de los archivos
|
19 |
+
COPY . .
|
20 |
+
|
21 |
+
# Configurar variables de entorno
|
22 |
+
ENV HF_HOME=/app/.cache
|
23 |
+
ENV TRANSFORMERS_CACHE=/app/.cache
|
24 |
+
ENV STREAMLIT_SERVER_PORT=8501
|
25 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
26 |
+
|
27 |
+
EXPOSE 8501
|
28 |
+
|
29 |
+
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
30 |
+
|
31 |
+
# Usar un usuario no root
|
32 |
+
USER nobody
|
33 |
+
|
34 |
+
CMD ["streamlit", "run", "app.py"]
|
README.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
---
|
2 |
title: Ecuador Stock Exchange Dashboard
|
3 |
-
emoji:
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: docker
|
|
|
7 |
pinned: false
|
8 |
-
license:
|
9 |
---
|
10 |
-
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Ecuador Stock Exchange Dashboard
|
3 |
+
emoji: 📊
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: docker
|
7 |
+
app_port: 8501
|
8 |
pinned: false
|
9 |
+
license: mit
|
10 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datasets import load_dataset
|
4 |
+
import pygwalker as pyg
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
from PIL import Image
|
8 |
+
import requests
|
9 |
+
from io import BytesIO
|
10 |
+
import time
|
11 |
+
|
12 |
+
# Page configuration
|
13 |
+
st.set_page_config(
|
14 |
+
page_title="Ecuador Stock Exchange Dashboard",
|
15 |
+
page_icon="📊",
|
16 |
+
layout="wide"
|
17 |
+
)
|
18 |
+
|
19 |
+
# Custom CSS for centered title and banners
|
20 |
+
st.markdown("""
|
21 |
+
<style>
|
22 |
+
.main-title {
|
23 |
+
text-align: center;
|
24 |
+
margin-bottom: 20px;
|
25 |
+
}
|
26 |
+
.banner-container {
|
27 |
+
display: flex;
|
28 |
+
justify-content: center;
|
29 |
+
align-items: center;
|
30 |
+
gap: 20px;
|
31 |
+
width: 100%;
|
32 |
+
margin: 20px 0;
|
33 |
+
}
|
34 |
+
.banner-container a {
|
35 |
+
width: 200px;
|
36 |
+
height: 60px;
|
37 |
+
display: flex;
|
38 |
+
justify-content: center;
|
39 |
+
align-items: center;
|
40 |
+
}
|
41 |
+
.banner-container img {
|
42 |
+
width: 200px;
|
43 |
+
height: 60px;
|
44 |
+
object-fit: contain;
|
45 |
+
transition: transform 0.2s;
|
46 |
+
}
|
47 |
+
.banner-container img:hover {
|
48 |
+
transform: scale(1.05);
|
49 |
+
}
|
50 |
+
.loading-container {
|
51 |
+
background-color: #1E1E1E;
|
52 |
+
color: #FFD700;
|
53 |
+
border-radius: 10px;
|
54 |
+
padding: 20px;
|
55 |
+
margin: 20px 0;
|
56 |
+
border-left: 5px solid #FFD700;
|
57 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
58 |
+
}
|
59 |
+
.loading-container strong {
|
60 |
+
color: #FFD700;
|
61 |
+
}
|
62 |
+
.element-container p {
|
63 |
+
text-align: justify;
|
64 |
+
}
|
65 |
+
</style>
|
66 |
+
""", unsafe_allow_html=True)
|
67 |
+
|
68 |
+
# Main title with custom CSS
|
69 |
+
st.markdown('<h1 class="main-title">Ecuador Stock Exchange Dashboard</h1>', unsafe_allow_html=True)
|
70 |
+
|
71 |
+
# Loading warning message
|
72 |
+
st.markdown("""
|
73 |
+
<div class="loading-container">
|
74 |
+
⚠️ Loading Notice: The data is being fetched from Hugging Face's servers. This process may take a few moments depending on your internet connection and the size of the selected dataset. Please be patient while the data loads.
|
75 |
+
</div>
|
76 |
+
""", unsafe_allow_html=True)
|
77 |
+
|
78 |
+
# Financial instruments configuration and their corresponding splits
|
79 |
+
INSTRUMENTS = {
|
80 |
+
"Stocks": {"config": "default_stocks", "split": "stocks"},
|
81 |
+
"Corporate Bonds": {"config": "default_corporate_bonds", "split": "corporate_bonds"},
|
82 |
+
"Commercial Paper": {"config": "default_comercial_paper", "split": "comercial_paper"},
|
83 |
+
"Securitizations": {"config": "default_securitizations", "split": "securitizations"},
|
84 |
+
"Credit Notes": {"config": "default_credit_notes", "split": "credit_notes"},
|
85 |
+
"Treasury Bills": {"config": "default_treasury_bills", "split": "treasury_bills"},
|
86 |
+
"Government Bonds": {"config": "default_goverment_bonds", "split": "goverment_bonds"}
|
87 |
+
}
|
88 |
+
|
89 |
+
# Function to load data
|
90 |
+
def load_data(config_name, split_name):
|
91 |
+
try:
|
92 |
+
with st.spinner('Loading data from Hugging Face...'):
|
93 |
+
dataset = load_dataset(
|
94 |
+
"beta3/Historical_Data_of_Ecuador_Stock_Exchange",
|
95 |
+
config_name,
|
96 |
+
split=split_name,
|
97 |
+
cache_dir="/app/.cache"
|
98 |
+
)
|
99 |
+
return pd.DataFrame(dataset)
|
100 |
+
except Exception as e:
|
101 |
+
st.error(f"Error loading data: {str(e)}")
|
102 |
+
return None
|
103 |
+
|
104 |
+
# Instrument selector
|
105 |
+
selected_instrument = st.selectbox(
|
106 |
+
"Select financial instrument:",
|
107 |
+
list(INSTRUMENTS.keys())
|
108 |
+
)
|
109 |
+
|
110 |
+
# Load data for selected instrument
|
111 |
+
instrument_config = INSTRUMENTS[selected_instrument]
|
112 |
+
df = load_data(instrument_config["config"], instrument_config["split"])
|
113 |
+
|
114 |
+
if df is not None:
|
115 |
+
# Load saved configuration if exists
|
116 |
+
config_path = f"configs/{instrument_config['config']}_config.json"
|
117 |
+
if os.path.exists(config_path):
|
118 |
+
with open(config_path, 'r') as f:
|
119 |
+
config = json.load(f)
|
120 |
+
else:
|
121 |
+
config = None
|
122 |
+
|
123 |
+
# Create dashboard with PyGWalker
|
124 |
+
pyg_html = pyg.to_html(df, config=config, return_html=True)
|
125 |
+
st.components.v1.html(pyg_html, height=800)
|
126 |
+
|
127 |
+
# Introduction
|
128 |
+
st.markdown("""
|
129 |
+
<div style="text-align: justify;">
|
130 |
+
This interactive dashboard provides comprehensive access to historical data from Ecuador's Stock Exchange, encompassing both the Guayaquil Stock Exchange (BVG) and Quito Stock Exchange (BVQ). The dataset represents a significant milestone in financial data accessibility, offering structured and clean information that was previously difficult to obtain in a ready-to-use format. This compilation of official BVG and national data serves as a valuable resource for researchers, analysts, and financial enthusiasts seeking to understand Ecuador's market dynamics.
|
131 |
+
The data collection process is rigorous and systematic, beginning with direct sourcing from official BVG records. Each dataset undergoes thorough pre-processing to remove non-tabular elements, followed by standardization into CSV format. The validation process ensures data consistency across multiple dimensions, including row counts, column integrity, and handling of missing values. This meticulous approach guarantees the reliability and usability of the information for various analytical purposes.
|
132 |
+
The dataset covers a wide range of financial instruments, from traditional stocks and corporate bonds to specialized securities like commercial paper and government bonds. Each instrument's data is regularly updated on a monthly basis, ensuring that users have access to the most current market information. This comprehensive coverage, combined with the interactive visualization capabilities of this dashboard, enables users to explore market trends, perform quantitative analysis, and develop predictive models for Ecuador's financial markets.
|
133 |
+
</div>
|
134 |
+
""", unsafe_allow_html=True)
|
135 |
+
|
136 |
+
# Banner container with hyperlinks
|
137 |
+
st.markdown("""
|
138 |
+
<div class="banner-container">
|
139 |
+
<a href="https://www.kaggle.com/datasets/beta3logic/historical-data-of-ecuadors-stock-exchange" target="_blank">
|
140 |
+
<img src="https://images.seeklogo.com/logo-png/33/2/kaggle-logo-png_seeklogo-335156.png" alt="Kaggle">
|
141 |
+
</a>
|
142 |
+
<a href="https://huggingface.co/datasets/beta3/Historical_Data_of_Ecuador_Stock_Exchange" target="_blank">
|
143 |
+
<img src="https://registry.npmmirror.com/@lobehub/icons-static-png/latest/files/dark/huggingface-color.png" alt="Hugging Face">
|
144 |
+
</a>
|
145 |
+
</div>
|
146 |
+
""", unsafe_allow_html=True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pygwalker==0.4.9.14
|
2 |
+
pandas==2.1.4
|
3 |
+
streamlit==1.43.2
|
4 |
+
datasets==3.4.0
|
5 |
+
numpy==1.26.2
|
6 |
+
python-dotenv==1.0.0
|