-
Notifications
You must be signed in to change notification settings - Fork 4
/
web_app.py
161 lines (147 loc) · 5.39 KB
/
web_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pickle as pk
import time
import base64
import Agri_chatbot as ag
import Crop_yield as cy
import Weather_app
import Rain_Forecast as rf
import Crop_Recommendation as cr
import Crop_disease_prediction as disease
import streamlit_option_menu as option_menu
import feedbacko as feed
import Crop_Insurance_Risk as ir
# from Insurance_risk import insurance_app
from Mail import send_confirmation_email
from auth_module import account_creation, login
# 📊🌦️🌾🌱🛡️🦠
# streamlit_app.py
class MultiApp:
def __init__(self):
self.apps = []
def add_app(self, title, function):
self.apps.append({
'title': title,
'function': function
})
def run(self):
with st.sidebar:
st.markdown(
"""
<style>
.sidebar-container {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.round-image-container {
width: 150px;
height: 150px;
overflow: hidden;
border-radius: 50%;
border: 5px solid white; /* Optional: Add a border */
}
.round-image {
width: 100%;
height: 100%;
object-fit: cover;
}
</style>
""",
unsafe_allow_html=True,
)
# Create a container div for the sidebar
st.sidebar.markdown(
"""
<div class="sidebar-container">
<div class="round-image-container">
<img class="round-image" src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQaOVenJRaGjCo3YJo_BokKwl76iwwW30omaw&usqp=CAU'>
</div>
<br>
</div>
""",
unsafe_allow_html=True,
)
selected_app = option_menu.option_menu(
menu_title='AgriTech Service',
options=["Weather Forecast", "Crop Recommendation", "Crop Disease", "Crop Yield", "Insurance Risk",'Agri ChatBot',"Feedback"],
default_index=0,
styles={
'container': {'padding': '5!important', 'background-color': 'black'},
'nav-link': {'color': 'white', 'font-size': '20px', 'text-align': 'left', 'margin': '0px',
'--hover-color': 'blue'},
'nav-link-selected': {'background-color': '#02ab21'}
}
)
for app in self.apps:
if selected_app == app['title']:
app['function']()
def main():
# st.title("AgriTech Dashboard")
authenticated = is_user_authenticated()
if not authenticated:
authentication_section()
else:
app_interface()
def authentication_section():
st.title("AgriTech")
choice = st.sidebar.selectbox("Login/Create Account", ['Login','Create Account'])
if choice == "Login":
login_section()
elif choice == "Create Account":
create_account_section()
def login_section():
st.header("Login")
username_or_email = st.text_input("Username or Email")
password = st.text_input("Password", type="password")
if st.button("Login"):
result = login(username_or_email, password)
if result == "Login successful":
progress = st.progress(0)
for i in range(100):
time.sleep(0.005)
progress.progress(i+1)
st.success("Login successful")
st.experimental_set_query_params(logged_in=True)
st.rerun()
else:
st.warning(result)
def create_account_section():
st.header("Create Account")
username = st.text_input("Username")
email = st.text_input("Email")
password = st.text_input("Password", type="password")
if st.button("Create Account"):
try:
send_confirmation_email(email, username)
progress = st.progress(0)
for i in range(100):
time.sleep(0.005)
progress.progress(i+1)
result = account_creation(username, email, password)
if result == "Account created successfully":
st.success(result)
else:
st.warning(result)
except:
st.error("Invalid Email")
def app_interface():
multi_app = MultiApp()
multi_app.add_app("Agri ChatBot", ag.chatbot)
multi_app.add_app("Weather Forecast", Weather_app.weather_forecast_app)
multi_app.add_app("Crop Yield", cy.Crop_yield)
multi_app.add_app("Crop Recommendation", cr.run_crop_recommendation)
multi_app.add_app("Crop Disease",disease.disease_app)
multi_app.add_app("Insurance Risk",ir.insurance_app)
multi_app.add_app("Feedback",feed.run_feedback)
multi_app.run()
# Add the following code at the end of the file to handle the redirection
def is_user_authenticated():
return "logged_in" in st.experimental_get_query_params()
if __name__ == "__main__":
main()