import gradio as gr from whereabouts.utils import download from whereabouts.Matcher import Matcher # download the various address databases download('au_all_sm', 'saunteringcat/whereabouts-db') download('au_all_lg', 'saunteringcat/whereabouts-db') download('au_vic_lg', 'saunteringcat/whereabouts-db') download('au_nsw_lg', 'saunteringcat/whereabouts-db') # create a matcher object matcher1 = Matcher('au_all_sm') matcher2 = Matcher('au_all_lg') matcher3 = Matcher('au_vic_lg') matcher4 = Matcher('au_nsw_lg') # function to geocode results def geocode(addresses, db_name='au_all_sm', how='standard'): if db_name == 'au_all_sm': matcher = matcher1 elif db_name == 'au_all_lg': matcher = matcher2 elif db_name == 'au_vic_lg': matcher = matcher3 elif db_name == 'au_nsw_lg': matcher = matcher4 address_list = addresses.split('\n') return matcher.geocode(address_list, how=how) # the gradio interface with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# whereabouts") gr.HTML("""
""") gr.Markdown("Fast, accurate open source geocoding in Python") gr.Markdown(""" [whereabouts](https://www.github.com/ajl2718/whereabouts) is an open source package for Python for fast and accurate geocoding within your own environment. It currently supports geocoding for Australia but with more countries coming soon. It uses duckDB to geocode 100s - 1000s of addresses per second based on an algorithm from [this paper](https://arxiv.org/abs/1708.01402)""") gr.Markdown(""" ``` pip install whereabouts python -m whereabouts download au_all_sm ``` This demo shows whereabouts in action, albeit slower due to the server. Running in your own environment speeds things up. """) with gr.Row(): with gr.Column(): dropdown_choice = gr.Dropdown(choices=[("Australia - Small", "au_all_sm"), ("Australia - Large", "au_all_lg"), ("Victoria, Australia - Large", "au_vic_lg"), ("New South Wales, Australia - Large", "au_nsw_lg")], value="au_all_sm", multiselect=False, label="Database", info="Select from one of the geocoding databases based on country, region and size") radio_choice = gr.Radio(choices=["standard", "trigram"], value='standard', label="Matching algorithm", info="Trigram matching is more accurate but slower. Only available for the large databases.") text_input = gr.Textbox(lines=2, label="Addresses to geocode (one row per address)") geocode_button = gr.Button(variant='primary') json_output = gr.JSON(label="Output JSON data") geocode_button.click(fn=geocode, inputs=[text_input, dropdown_choice, radio_choice], outputs=json_output, api_name="whereabouts_geocoder") demo.launch()