Skip to content

Commit 1d6e589

Browse files
authored
Merge pull request #31 from TCS-2021/final-app
Final app
2 parents 488b887 + acd9771 commit 1d6e589

13 files changed

Lines changed: 222 additions & 127 deletions

File tree

main.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/DescriptiveAnalysis/frontend.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,7 @@
55
import streamlit.components.v1 as components
66
import pandas as pd
77

8-
from backend import generate_data_cubes, process_download
9-
10-
# Set page configuration and custom CSS styling
11-
st.set_page_config(layout="wide")
12-
13-
st.markdown("""
14-
<style>
15-
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');
16-
17-
html, body {
18-
background: linear-gradient(135deg, #f0f4f8, #d9e2ec);
19-
font-family: 'Montserrat', sans-serif;
20-
color: #333;
21-
}
22-
.main-container {
23-
background-color: #fff;
24-
border-radius: 10px;
25-
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
26-
padding: 2rem;
27-
margin: 1rem;
28-
}
29-
.css-1e5imcs, .css-1d391kg {
30-
background-color: #ffffff !important;
31-
border-radius: 8px;
32-
box-shadow: 0px 2px 5px rgba(0,0,0,0.1);
33-
padding: 1rem;
34-
}
35-
.css-1aumxhk {
36-
font-size: 1.2rem;
37-
font-weight: 600;
38-
}
39-
.css-1d391kg .stTabs {
40-
background-color: #fff;
41-
}
42-
</style>
43-
""", unsafe_allow_html=True)
8+
from .backend import generate_data_cubes, process_download
449

4510
def load_data():
4611
"""
@@ -347,6 +312,39 @@ def main():
347312
2. Drill-Down and Roll-Up
348313
3. Batch Processing
349314
"""
315+
# Apply custom CSS styling
316+
st.markdown("""
317+
<style>
318+
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');
319+
320+
html, body {
321+
background: linear-gradient(135deg, #f0f4f8, #d9e2ec);
322+
font-family: 'Montserrat', sans-serif;
323+
color: #333;
324+
}
325+
.main-container {
326+
background-color: #fff;
327+
border-radius: 10px;
328+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
329+
padding: 2rem;
330+
margin: 1rem;
331+
}
332+
.css-1e5imcs, .css-1d391kg {
333+
background-color: #ffffff !important;
334+
border-radius: 8px;
335+
box-shadow: 0px 2px 5px rgba(0,0,0,0.1);
336+
padding: 1rem;
337+
}
338+
.css-1aumxhk {
339+
font-size: 1.2rem;
340+
font-weight: 600;
341+
}
342+
.css-1d391kg .stTabs {
343+
background-color: #fff;
344+
}
345+
</style>
346+
""", unsafe_allow_html=True)
347+
350348
st.title("Data Warehouse & Cube Generator")
351349

352350
# Load data from CSV file
@@ -387,4 +385,4 @@ def main():
387385
batch_processing()
388386

389387
if __name__ == "__main__":
390-
main()
388+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/PredictiveAnalytics1/Frontend/app.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@
44
import pandas as pd
55
import numpy as np
66
import os
7-
import sys
87
from pathlib import Path
9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
10-
from Backend.backend import (
11-
load_data, preprocess_data, apply_pca, determine_problem_type, train_model)
8+
from ..Backend.backend import load_data, preprocess_data, apply_pca, determine_problem_type, train_model
129
from sklearn.preprocessing import LabelEncoder
1310
from sklearn.cluster import DBSCAN, SpectralClustering
1411
from sklearn.preprocessing import StandardScaler
1512
from sklearn.metrics import silhouette_score
1613

17-
18-
st.set_page_config(page_title="Model Comparison Tool", layout="wide")
19-
20-
2114
@st.cache_data
2215
def cached_load_data(file_path):
2316
return load_data(file_path)
@@ -127,7 +120,11 @@ def main():
127120
else:
128121
current_file = Path(__file__).resolve()
129122
dataset_dir = current_file.parents[3] / 'Datasets' / 'predictive-analytics-1'
130-
dataset_files = [f for f in os.listdir(dataset_dir) if f.endswith(".csv")]
123+
if not dataset_dir.exists():
124+
st.warning("Dataset directory not found. Please upload a CSV file.")
125+
dataset_files = []
126+
else:
127+
dataset_files = [f for f in os.listdir(dataset_dir) if f.endswith(".csv")]
131128

132129
if dataset_files:
133130
selected_dataset = st.selectbox("Select a dataset", dataset_files)
@@ -267,13 +264,11 @@ def main():
267264

268265
st.dataframe(comparison_df.set_index('Model').T)
269266

270-
271267
st.subheader("Performance Visualization")
272268
chart_data = comparison_df.melt(id_vars=['Model'], var_name='Metric', value_name='Score')
273269
chart_data['Score'] = pd.to_numeric(chart_data['Score'], errors='coerce')
274270
chart_data = chart_data.dropna(subset=['Score'])
275271

276-
277272
if not chart_data.empty:
278273
st.bar_chart(chart_data, x='Metric', y='Score', color='Model', stack=False)
279274
else:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/PrescriptiveAnalysis1/Frontend/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import streamlit as st
2-
import sys
3-
import os
42
import pandas as pd
3+
import os
54
import time
65
from collections import defaultdict
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
8-
from Backend.gspan import run_gspan_analysis, construct_dfs_code, load_graphs_from_json
9-
from Backend.apriori_graph import parse_graph_file, apriori_graph_mining
10-
from Backend.gsp import preprocess_sequences_ordered, gsp_algorithm
11-
from Backend.apriori import run_apriori_analysis
12-
from Backend.fp_growth import run_fp_growth_analysis
6+
7+
# Relative imports for Backend modules
8+
from ..Backend.gspan import run_gspan_analysis, construct_dfs_code, load_graphs_from_json
9+
from ..Backend.apriori_graph import parse_graph_file, apriori_graph_mining
10+
from ..Backend.gsp import preprocess_sequences_ordered, gsp_algorithm
11+
from ..Backend.apriori import run_apriori_analysis
12+
from ..Backend.fp_growth import run_fp_growth_analysis
1313

1414
def apriori_graph_mining_app():
1515
st.title("Apriori-Based Graph Mining")
16-
uploaded_file = st.file_uploader("Upload your graph dataset file ", type=['txt'], key="apriori_file")
16+
uploaded_file = st.file_uploader("Upload your graph dataset file", type=['txt'], key="apriori_file")
1717
if uploaded_file is not None:
1818
graphs = parse_graph_file(uploaded_file)
1919
st.write(f"Number of graphs loaded: {len(graphs)}")

0 commit comments

Comments
 (0)