1+ import streamlit as st
2+ import os
3+ import sys
4+ from pathlib import Path
5+
6+ # Set page configuration first
7+ st .set_page_config (
8+ page_title = "Analytics Dashboard" ,
9+ page_icon = "📊" ,
10+ layout = "wide"
11+ )
12+
13+ # Add src directory and subdirectories to sys.path
14+ project_root = Path (__file__ ).parent
15+ src_path = project_root / 'src'
16+ sys .path .insert (0 , str (src_path ))
17+
18+ # Add each application's directory to sys.path
19+ app_dirs = ['DescriptiveAnalysis' , 'PredictiveAnalytics1' , 'preprocessing' , 'PrescriptiveAnalysis1' ]
20+ for app_dir in app_dirs :
21+ app_path = src_path / app_dir
22+ if app_path .exists ():
23+ sys .path .insert (0 , str (app_path ))
24+ else :
25+ print (f"Directory { app_dir } not found in src/. Please check the directory structure." )
26+
27+ # Add PredictiveAnalytics1/Frontend and PrescriptiveAnalysis1 subdirectories to sys.path
28+ predictive_frontend_path = src_path / 'PredictiveAnalytics1' / 'Frontend'
29+ if predictive_frontend_path .exists ():
30+ sys .path .insert (0 , str (predictive_frontend_path ))
31+ else :
32+ print (f"Frontend directory not found at { predictive_frontend_path } ." )
33+
34+ prescriptive_frontend_path = src_path / 'PrescriptiveAnalysis1' / 'Frontend'
35+ if prescriptive_frontend_path .exists ():
36+ sys .path .insert (0 , str (prescriptive_frontend_path ))
37+ else :
38+ print (f"Frontend directory not found at { prescriptive_frontend_path } ." )
39+
40+ prescriptive_backend_path = src_path / 'PrescriptiveAnalysis1' / 'Backend'
41+ if prescriptive_backend_path .exists ():
42+ sys .path .insert (0 , str (prescriptive_backend_path ))
43+ else :
44+ print (f"Backend directory not found at { prescriptive_backend_path } ." )
45+
46+ # Import main functions from each application
47+ try :
48+ from DescriptiveAnalysis .frontend import main as descriptive_main
49+ except ModuleNotFoundError as e :
50+ print (f"Error importing DescriptiveAnalysis: { e } " )
51+ descriptive_main = None
52+
53+ try :
54+ from PredictiveAnalytics1 .Frontend .app import main as predictive_main
55+ except ModuleNotFoundError as e :
56+ print (f"Error importing PredictiveAnalytics1: { e } " )
57+ predictive_main = None
58+
59+ try :
60+ from preprocessing .app import main as preprocessing_main
61+ except ModuleNotFoundError as e :
62+ print (f"Error importing preprocessing: { e } " )
63+ preprocessing_main = None
64+
65+ try :
66+ from PrescriptiveAnalysis1 .Frontend .main import main as prescriptive_main
67+ except ModuleNotFoundError as e :
68+ print (f"Error importing PrescriptiveAnalysis1: { e } " )
69+ prescriptive_main = None
70+
71+ # Custom CSS for styling
72+ st .markdown ("""
73+ <style>
74+ @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');
75+
76+ html, body {
77+ font-family: 'Montserrat', sans-serif;
78+ color: #333;
79+ }
80+ .sidebar .sidebar-content {
81+ background: linear-gradient(135deg, #f0f4f8, #d9e2ec);
82+ border-radius: 8px;
83+ padding: 1rem;
84+ }
85+ .stSelectbox > div > label {
86+ font-size: 1.1rem;
87+ font-weight: 600;
88+ color: #2c3e50;
89+ }
90+ .main-container {
91+ background-color: #fff;
92+ border-radius: 10px;
93+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
94+ padding: 2rem;
95+ margin: 1rem;
96+ }
97+ h1 {
98+ color: #2c3e50;
99+ text-align: center;
100+ margin-bottom: 2rem;
101+ }
102+ </style>
103+ """ , unsafe_allow_html = True )
104+
105+ def main ():
106+ """
107+ Main function to run the Streamlit dashboard application.
108+ Provides a sidebar to navigate between different analytics applications.
109+ """
110+ st .title ("Analytics Dashboard" )
111+
112+ # Display import errors, if any
113+ if descriptive_main is None :
114+ st .error ("Cannot import DescriptiveAnalysis. Please check the directory structure and files." )
115+ if predictive_main is None :
116+ st .error ("Cannot import PredictiveAnalytics1. Please check the directory structure and files." )
117+ if preprocessing_main is None :
118+ st .error ("Cannot import preprocessing. Please check the directory structure and files." )
119+ if prescriptive_main is None :
120+ st .error ("Cannot import PrescriptiveAnalysis1. Please check the directory structure and files." )
121+
122+ # Sidebar for application selection
123+ st .sidebar .title ("Navigation" )
124+ app_options = [
125+ "Descriptive Analysis" ,
126+ "Predictive Analytics" ,
127+ "Preprocessing" ,
128+ "Prescriptive Analysis"
129+ ]
130+ selected_app = st .sidebar .selectbox ("Select Application" , app_options )
131+
132+ # Map selected app to the corresponding main function
133+ app_functions = {
134+ "Descriptive Analysis" : descriptive_main ,
135+ "Predictive Analytics" : predictive_main ,
136+ "Preprocessing" : preprocessing_main ,
137+ "Prescriptive Analysis" : prescriptive_main
138+ }
139+
140+ # Run the selected application's main function
141+ with st .container ():
142+ st .markdown ('<div class="main-container">' , unsafe_allow_html = True )
143+ selected_function = app_functions [selected_app ]
144+ if selected_function is None :
145+ st .error (f"Cannot run { selected_app } . The module could not be imported. Please check the error messages above." )
146+ else :
147+ selected_function ()
148+ st .markdown ('</div>' , unsafe_allow_html = True )
149+
150+ if __name__ == "__main__" :
151+ main ()
0 commit comments