williambr's picture
Update app.py
36cfca1
#import definitions
#from tkinter import W
import pandas as pd
import streamlit as st
import gradio as gr
#cleaning data
df = pd.read_csv('Map-City-State-Zip-Lat-Long.txt', dtype=str, sep=';')
df["Latitude"] = df["Latitude"].astype(float)
df["Longitude"] = df["Longitude"].astype(float)
def writeToDataFrame(dataframe, name, location, latitude, longitude):
newdf = {'Name': name, 'Location': location, 'Latitude': latitude, 'Longitude': longitude}
dataframe = dataframe.append(newdf, ignore_index = True)
return dataframe
st.title("Input a city and state I'll take you there! - Ex. Boston, MA")
city_and_state_string = st.text_input("Please search for a location:")
if city_and_state_string != "":
split_city_state = city_and_state_string.split(", ")
state_name = split_city_state[1]
city_name = split_city_state[0]
#create a dataframe consisting of the correct city input
city_df = df[df["City"] == city_name]
#use the city dateframe to confirm you are using the right map
lat = city_df[city_df["State"] == state_name]["Latitude"].values[0]
lon = city_df[city_df["State"] == state_name]["Longitude"].values[0]
city_list = []
lat_list = []
long_list = []
city_list.append(city_name)
lat_list.append(lat)
long_list.append(lon)
st.map(pd.DataFrame({'cities' : city_list, 'lat' : lat_list, 'lon' : long_list}))
checkbox = st.checkbox("Show/Hide Latitude/Longitude")
if checkbox:
st.write(city_name, "is located at: ", lat, ",", lon)