-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (46 loc) · 2.75 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
import streamlit as st
from src import ui_texts as ui
from src import fe_logic as fe
from src.ai_logic import fetch_city_info
def main():
ui.display_intro()
city_name = ui.get_city_name_input() # Capture user input for city name
explore_button_clicked = st.button("Explore Road Network")
# Store city name in session state only if button "Explore Road Network" is clicked
if explore_button_clicked and city_name:
st.session_state.city_name = city_name # Update the city name in session state
st.session_state.city_info = None # Reset city info to force refetching if a new city is searched
# Fetch city information of city using openai (uncomment only if you have an API key stored in .env file)
if 'city_name' in st.session_state and st.session_state.city_name:
if 'city_info' not in st.session_state or st.session_state.city_info is None:
st.session_state.city_info = fetch_city_info(st.session_state.city_name)
if st.session_state.city_info:
ui.display_city_info(st.session_state.city_name, st.session_state.city_info)
# Load and plot the network
if 'city_name' in st.session_state and st.session_state.city_name:
if 'network_with_elevation' not in st.session_state:
network_with_elevation = fe.load_network(st.session_state.city_name)
if network_with_elevation is not None:
st.session_state.network_with_elevation = network_with_elevation
st.session_state.num_nodes = len(network_with_elevation.nodes) # Initialize num_nodes
# If network is loaded, plot it
if 'network_with_elevation' in st.session_state and st.session_state.network_with_elevation:
fe.plot_network(st.session_state.network_with_elevation, st.session_state.city_name)
ui.display_network_info(st.session_state.city_name, st.session_state.num_nodes)
analyze_network_clicked = st.button("Network Analysis")
# Perform network analysis if button "Network Analysis" is clicked
if analyze_network_clicked or 'analyzer' in st.session_state:
if "analyzer" not in st.session_state:
st.session_state.analyzer = fe.analyze_network(st.session_state.network_with_elevation)
# Plot critical points on the network
fe.plot_network_critical(st.session_state.analyzer)
# Display analysis-related text
ui.display_analysis_info(
st.session_state.analyzer, st.session_state.city_name
)
# Clear everything if the user clicks the button 'Clear'
if st.button('Clear'):
st.session_state.clear()
st.rerun()
if __name__ == "__main__":
main()