Spaces:
Build error
Build error
Upload streamlit_app.py with huggingface_hub
Browse files- streamlit_app.py +111 -24
streamlit_app.py
CHANGED
|
@@ -6,7 +6,9 @@ import plotly.graph_objects as go
|
|
| 6 |
from datetime import datetime
|
| 7 |
import time
|
| 8 |
import os
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Page configuration
|
| 12 |
st.set_page_config(
|
|
@@ -72,6 +74,13 @@ st.markdown("""
|
|
| 72 |
border-radius: 5px;
|
| 73 |
margin: 1rem 0;
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
</style>
|
| 76 |
""", unsafe_allow_html=True)
|
| 77 |
|
|
@@ -83,6 +92,14 @@ st.markdown("""
|
|
| 83 |
</div>
|
| 84 |
""", unsafe_allow_html=True)
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# Initialize session state
|
| 87 |
if 'installation_progress' not in st.session_state:
|
| 88 |
st.session_state.installation_progress = 0
|
|
@@ -90,6 +107,8 @@ if 'installation_steps' not in st.session_state:
|
|
| 90 |
st.session_state.installation_steps = []
|
| 91 |
if 'current_step' not in st.session_state:
|
| 92 |
st.session_state.current_step = 0
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Installation steps definition
|
| 95 |
installation_steps = [
|
|
@@ -140,54 +159,112 @@ def update_progress(step_index, status, message=None):
|
|
| 140 |
def check_system_requirements():
|
| 141 |
"""Check system requirements"""
|
| 142 |
with st.spinner("Checking system requirements..."):
|
| 143 |
-
time.sleep(
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
return True
|
| 148 |
|
| 149 |
def create_virtual_environment():
|
| 150 |
"""Create virtual environment"""
|
| 151 |
with st.spinner("Creating virtual environment..."):
|
| 152 |
-
time.sleep(
|
|
|
|
|
|
|
| 153 |
env_name = "venv"
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
def install_dependencies():
|
| 159 |
"""Install required dependencies"""
|
| 160 |
with st.spinner("Installing dependencies..."):
|
| 161 |
-
time.sleep(
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
def configure_database():
|
| 168 |
"""Configure database settings"""
|
| 169 |
with st.spinner("Configuring database..."):
|
| 170 |
-
time.sleep(
|
|
|
|
|
|
|
| 171 |
db_config = {
|
| 172 |
"host": "localhost",
|
| 173 |
"port": 5432,
|
| 174 |
"database": "app_db",
|
| 175 |
"user": "app_user"
|
| 176 |
}
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
def run_initial_setup():
|
| 182 |
"""Run initial setup and tests"""
|
| 183 |
with st.spinner("Running initial setup..."):
|
| 184 |
-
time.sleep(
|
| 185 |
update_progress(4, "completed", "Initial setup completed successfully")
|
| 186 |
return True
|
| 187 |
|
| 188 |
# Main installation interface
|
| 189 |
st.header("Step-by-Step Installation Process")
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
# Progress bar
|
| 192 |
st.markdown(f"""
|
| 193 |
<div class="progress-bar">
|
|
@@ -212,9 +289,12 @@ for i, step in enumerate(installation_steps):
|
|
| 212 |
st.write(step['description'])
|
| 213 |
|
| 214 |
if step['status'] == "pending":
|
| 215 |
-
if st.
|
| 216 |
-
st.
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
elif step['status'] == "running":
|
| 220 |
st.info("This step is currently running...")
|
|
@@ -230,7 +310,7 @@ if st.session_state.installation_progress == 0 and st.button("Start Full Install
|
|
| 230 |
st.rerun()
|
| 231 |
|
| 232 |
# Run installation automatically when ready
|
| 233 |
-
if st.session_state.current_step < len(installation_steps) and installation_steps[st.session_state.current_step]['status'] == "pending":
|
| 234 |
current_step_func = globals()[installation_steps[st.session_state.current_step]['function']]
|
| 235 |
if current_step_func():
|
| 236 |
installation_steps[st.session_state.current_step]['status'] = "completed"
|
|
@@ -275,4 +355,11 @@ with st.sidebar:
|
|
| 275 |
st.write("1. Check Python version")
|
| 276 |
st.write("2. Verify database connection")
|
| 277 |
st.write("3. Ensure all dependencies are installed")
|
| 278 |
-
st.write("4. Check logs for error messages")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
import time
|
| 8 |
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
from utils import check_dependencies, install_package, create_virtual_environment, setup_database, validate_python_version, test_database_connection
|
| 12 |
|
| 13 |
# Page configuration
|
| 14 |
st.set_page_config(
|
|
|
|
| 74 |
border-radius: 5px;
|
| 75 |
margin: 1rem 0;
|
| 76 |
}
|
| 77 |
+
.info-box {
|
| 78 |
+
background-color: #e7f3fe;
|
| 79 |
+
border-left: 4px solid #2196F3;
|
| 80 |
+
padding: 1rem;
|
| 81 |
+
border-radius: 5px;
|
| 82 |
+
margin: 1rem 0;
|
| 83 |
+
}
|
| 84 |
</style>
|
| 85 |
""", unsafe_allow_html=True)
|
| 86 |
|
|
|
|
| 92 |
</div>
|
| 93 |
""", unsafe_allow_html=True)
|
| 94 |
|
| 95 |
+
# Information box about running without Docker
|
| 96 |
+
st.markdown("""
|
| 97 |
+
<div class="info-box">
|
| 98 |
+
<strong>💡 Running without Docker:</strong> This application can be run directly on your local machine without Docker.
|
| 99 |
+
Simply follow the installation steps below or use the "Quick Install" button for automatic setup.
|
| 100 |
+
</div>
|
| 101 |
+
""", unsafe_allow_html=True)
|
| 102 |
+
|
| 103 |
# Initialize session state
|
| 104 |
if 'installation_progress' not in st.session_state:
|
| 105 |
st.session_state.installation_progress = 0
|
|
|
|
| 107 |
st.session_state.installation_steps = []
|
| 108 |
if 'current_step' not in st.session_state:
|
| 109 |
st.session_state.current_step = 0
|
| 110 |
+
if 'installation_method' not in st.session_state:
|
| 111 |
+
st.session_state.installation_method = "manual" # manual or auto
|
| 112 |
|
| 113 |
# Installation steps definition
|
| 114 |
installation_steps = [
|
|
|
|
| 159 |
def check_system_requirements():
|
| 160 |
"""Check system requirements"""
|
| 161 |
with st.spinner("Checking system requirements..."):
|
| 162 |
+
time.sleep(1)
|
| 163 |
+
|
| 164 |
+
# Check Python version
|
| 165 |
+
is_valid, version_info = validate_python_version()
|
| 166 |
+
if not is_valid:
|
| 167 |
+
st.error(f"❌ {version_info}")
|
| 168 |
+
return False
|
| 169 |
+
|
| 170 |
+
st.session_state.python_version = version_info
|
| 171 |
+
update_progress(0, "completed", f"Python version check passed: {version_info}")
|
| 172 |
return True
|
| 173 |
|
| 174 |
def create_virtual_environment():
|
| 175 |
"""Create virtual environment"""
|
| 176 |
with st.spinner("Creating virtual environment..."):
|
| 177 |
+
time.sleep(1)
|
| 178 |
+
|
| 179 |
+
# Create venv
|
| 180 |
env_name = "venv"
|
| 181 |
+
if not os.path.exists(env_name):
|
| 182 |
+
try:
|
| 183 |
+
subprocess.check_call([sys.executable, "-m", "venv", env_name])
|
| 184 |
+
st.session_state.env_name = env_name
|
| 185 |
+
update_progress(1, "completed", f"Virtual environment '{env_name}' created")
|
| 186 |
+
return True
|
| 187 |
+
except subprocess.CalledProcessError as e:
|
| 188 |
+
st.error(f"❌ Failed to create virtual environment: {str(e)}")
|
| 189 |
+
return False
|
| 190 |
+
else:
|
| 191 |
+
st.session_state.env_name = env_name
|
| 192 |
+
update_progress(1, "completed", f"Virtual environment '{env_name}' already exists")
|
| 193 |
+
return True
|
| 194 |
|
| 195 |
def install_dependencies():
|
| 196 |
"""Install required dependencies"""
|
| 197 |
with st.spinner("Installing dependencies..."):
|
| 198 |
+
time.sleep(1)
|
| 199 |
+
|
| 200 |
+
# Install packages
|
| 201 |
+
required_packages = [
|
| 202 |
+
'streamlit', 'pandas', 'numpy', 'plotly', 'python-dateutil', 'pytz',
|
| 203 |
+
'openpyxl', 'watchdog', 'python-dotenv', 'pydantic', 'sqlalchemy',
|
| 204 |
+
'psycopg2-binary', 'bcrypt', 'jinja2'
|
| 205 |
+
]
|
| 206 |
+
|
| 207 |
+
missing_packages = check_dependencies()
|
| 208 |
+
if missing_packages:
|
| 209 |
+
st.warning(f"⚠️ {len(missing_packages)} packages need to be installed")
|
| 210 |
+
|
| 211 |
+
for package in required_packages:
|
| 212 |
+
if install_package(package):
|
| 213 |
+
st.session_state.installed_packages = required_packages
|
| 214 |
+
update_progress(2, "completed", f"Installed {len(required_packages)} packages")
|
| 215 |
+
return True
|
| 216 |
+
else:
|
| 217 |
+
st.error(f"❌ Failed to install {package}")
|
| 218 |
+
return False
|
| 219 |
+
else:
|
| 220 |
+
st.session_state.installed_packages = required_packages
|
| 221 |
+
update_progress(2, "completed", "All required packages are already installed")
|
| 222 |
+
return True
|
| 223 |
|
| 224 |
def configure_database():
|
| 225 |
"""Configure database settings"""
|
| 226 |
with st.spinner("Configuring database..."):
|
| 227 |
+
time.sleep(1)
|
| 228 |
+
|
| 229 |
+
# Test database connection
|
| 230 |
db_config = {
|
| 231 |
"host": "localhost",
|
| 232 |
"port": 5432,
|
| 233 |
"database": "app_db",
|
| 234 |
"user": "app_user"
|
| 235 |
}
|
| 236 |
+
|
| 237 |
+
is_connected, connection_info = test_database_connection(db_config)
|
| 238 |
+
if is_connected:
|
| 239 |
+
st.session_state.db_config = db_config
|
| 240 |
+
update_progress(3, "completed", "Database configured successfully")
|
| 241 |
+
return True
|
| 242 |
+
else:
|
| 243 |
+
st.warning(f"⚠️ {connection_info}")
|
| 244 |
+
update_progress(3, "completed", "Database configuration attempted")
|
| 245 |
+
return True
|
| 246 |
|
| 247 |
def run_initial_setup():
|
| 248 |
"""Run initial setup and tests"""
|
| 249 |
with st.spinner("Running initial setup..."):
|
| 250 |
+
time.sleep(1)
|
| 251 |
update_progress(4, "completed", "Initial setup completed successfully")
|
| 252 |
return True
|
| 253 |
|
| 254 |
# Main installation interface
|
| 255 |
st.header("Step-by-Step Installation Process")
|
| 256 |
|
| 257 |
+
# Installation method selection
|
| 258 |
+
col1, col2, col3 = st.columns([1, 1, 2])
|
| 259 |
+
with col1:
|
| 260 |
+
if st.button("📋 Manual Installation", type="primary"):
|
| 261 |
+
st.session_state.installation_method = "manual"
|
| 262 |
+
st.rerun()
|
| 263 |
+
with col2:
|
| 264 |
+
if st.button("⚡ Quick Install", type="secondary"):
|
| 265 |
+
st.session_state.installation_method = "auto"
|
| 266 |
+
st.rerun()
|
| 267 |
+
|
| 268 |
# Progress bar
|
| 269 |
st.markdown(f"""
|
| 270 |
<div class="progress-bar">
|
|
|
|
| 289 |
st.write(step['description'])
|
| 290 |
|
| 291 |
if step['status'] == "pending":
|
| 292 |
+
if st.session_state.installation_method == "manual":
|
| 293 |
+
if st.button(f"Start Step {i+1}", key=f"step_{i}"):
|
| 294 |
+
st.session_state.current_step = i
|
| 295 |
+
st.rerun()
|
| 296 |
+
else:
|
| 297 |
+
st.info("This step will run automatically in Quick Install mode")
|
| 298 |
|
| 299 |
elif step['status'] == "running":
|
| 300 |
st.info("This step is currently running...")
|
|
|
|
| 310 |
st.rerun()
|
| 311 |
|
| 312 |
# Run installation automatically when ready
|
| 313 |
+
if st.session_state.installation_method == "auto" and st.session_state.current_step < len(installation_steps) and installation_steps[st.session_state.current_step]['status'] == "pending":
|
| 314 |
current_step_func = globals()[installation_steps[st.session_state.current_step]['function']]
|
| 315 |
if current_step_func():
|
| 316 |
installation_steps[st.session_state.current_step]['status'] = "completed"
|
|
|
|
| 355 |
st.write("1. Check Python version")
|
| 356 |
st.write("2. Verify database connection")
|
| 357 |
st.write("3. Ensure all dependencies are installed")
|
| 358 |
+
st.write("4. Check logs for error messages")
|
| 359 |
+
|
| 360 |
+
st.subheader("Running Without Docker")
|
| 361 |
+
st.write("To run this application without Docker:")
|
| 362 |
+
st.write("1. Install Python 3.11+")
|
| 363 |
+
st.write("2. Clone the repository")
|
| 364 |
+
st.write("3. Run `pip install -r requirements.txt`")
|
| 365 |
+
st.write("4. Run `streamlit run streamlit_app.py`")
|