SafeMaps / app.py
amanr24's picture
Update app.py
6cebae3 verified
Raw History Blame Contribute Delete
1.22 kB
import streamlit as st
import time
import os
from utils.astar_algo import get_route
html_file_path = "generated_map.html"
st.set_page_config(page_title="SafeMaps", layout="wide")
st.title("SafeMaps - Find the Safest Route")
source = st.text_input("Enter Source Location")
destination = st.text_input("Enter Destination Location")
safety_percentage = st.slider("Select Safety Percentage:", min_value=0, max_value=100, value=30)
if st.button("Show Route"):
if not source or not destination:
st.warning("Please enter both source and destination.")
else:
st.info("Calculating safest route...")
if os.path.exists(html_file_path):
os.remove(html_file_path)
start_time = time.time()
get_route(source, destination, safety_percentage)
while not os.path.isfile(html_file_path):
print("waiting")
time.sleep(0.5)
elapsed_time = time.time() - start_time
st.success(f"Route calculated in {elapsed_time:.2f} seconds!")
with open(html_file_path, "r", encoding="utf-8") as f:
html_content = f.read()
st.components.v1.html(html_content, height=600)
if st.button("Back"):
st.experimental_rerun()