-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
88 lines (79 loc) · 2.6 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
import pickle
import pandas as pd
from nav import home, predict, result_visualization, logs, data_analysis
# Load the precomputed models, metrics, and label encoder
models_file = 'precomputation/models.pkl'
metrics_file = 'precomputation/metrics.pkl'
le_file = 'precomputation/label_encoder.pkl'
with open(models_file, 'rb') as f:
models = pickle.load(f)
with open(metrics_file, 'rb') as f:
metrics = pickle.load(f)
with open(le_file, 'rb') as f:
le = pickle.load(f)
# Load the dataset for feature names
dataset_path = 'dataset/crop_recommendation.csv'
df = pd.read_csv(dataset_path)
X = df.drop('label', axis=1)
# Custom CSS for better navigation bar with animations and icons
st.markdown("""
<style>
.navbar {
display: flex;
justify-content: space-around;
background-color: #f8f9fa;
padding: 10px;
border-bottom: 2px solid #dee2e6;
animation: fadeInDown 1s ease-out;
}
.navbar a {
text-decoration: none;
color: #333;
font-weight: bold;
display: flex;
align-items: center;
}
.navbar a:hover {
color: #007bff;
}
.navbar i {
margin-right: 5px;
}
@keyframes fadeInDown {
0% {
opacity: 0;
transform: translateY(-10px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
</style>
""", unsafe_allow_html=True)
# Create navigation bar with links targeted to _self (same window) and icons
st.markdown("""
<div class="navbar">
<a href="?page=home" id="link-home" target="_self"><i class="fa fa-home"></i> Home</a>
<a href="?page=predict" id="link-predict" target="_self"><i class="fa fa-pie-chart"></i> Predict</a>
<a href="?page=resultVisualization" id="link-result-visualization" target="_self"><i class="fa fa-bar-chart"></i> Result Visualization</a>
<a href="?page=dataAnalysis" id="link-data-analysis" target="_self"><i class="fa fa-line-chart"></i> Data Analysis</a>
<a href="?page=logs" id="link-logs" target="_self"><i class="fa fa-file-text"></i> Logs</a>
</div>
""", unsafe_allow_html=True)
# Determine the selected page based on the query parameters
query_params = st.query_params
page = query_params.get("page", "home")
if page == "home":
home.show()
elif page == "predict":
predict.show(models, metrics, le, X.columns)
elif page == "resultVisualization":
result_visualization.show(models, metrics, le, X)
elif page == "dataAnalysis":
data_analysis.main()
elif page == "logs":
logs.show_logs()
else:
home.show()