File size: 5,316 Bytes
49c9801
7316a14
 
6961bab
99d5451
7316a14
99d5451
 
 
c4e3285
 
49c9801
7316a14
c79e5a0
b71a362
c79e5a0
 
c4e3285
 
7316a14
6735609
e905680
0fda97d
c79e5a0
 
 
 
 
 
 
 
 
c4e3285
 
 
 
9f3256a
c79e5a0
49c9801
55d1ec4
c1671f7
55d1ec4
 
 
 
 
 
 
 
 
 
 
c4e3285
 
 
55d1ec4
b71a362
 
c4e3285
b71a362
dd0edf7
55d1ec4
 
c79e5a0
 
 
c4e3285
 
 
e905680
c79e5a0
 
 
 
 
 
 
e905680
f4b593e
55d1ec4
c79e5a0
dd0edf7
 
 
 
 
 
 
 
 
49c9801
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
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')
download('us_ca_sm', 'saunteringcat/whereabouts-db')
download('us_ma_sm', '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')
matcher5 = Matcher('us_ca_sm')
matcher6 = Matcher('us_ma_sm')

default_address_values = "3333 Channel Way, San Diego, CA\n1500 Orange Avenuee, Colonado, CA\n3129 Arden Wy, Sacramento, 95825\n2000 Allston Way, Berkly, 94704"

# 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
    elif db_name == 'us_ca_sm':
        matcher = matcher5
    elif db_name == 'us_ma_sm':
        matcher = matcher6
    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("""
                <div style="display:flex;column-gap:4px;">
                    <a href='https://github.com/ajl2718/whereabouts'>
                        <img src='https://img.shields.io/badge/Code-github-blue'>
                    </a>
                </div>
                """)
    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 all of Australia with some US states currently being built using OpenAddresses.
                
    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 us_ca_sm
    ```
    This demo shows whereabouts with some example databases.""")
    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"),
                                                   ("California - Small", "us_ca_sm"),
                                                   ("Massachusetts - Small", "us_ma_sm")], 
                                          value="us_ca_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)", value=default_address_values)
            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")
    gr.Markdown("""
    ## License Disclaimer for Third-Party Data  
    Note that while the code from this package is licensed under the MIT license, the pre-built databases use data from data providers that may have restrictions for particular use cases:

    - The Australian databases are built from the [Geocoded National Address File](https://https://data.gov.au/data/dataset/geocoded-national-address-file-g-naf) with conditions of use based on the [End User License Agreemment](https://data.gov.au/dataset/ds-dga-e1a365fc-52f5-4798-8f0c-ed1d33d43b6d/distribution/dist-dga-0102be65-3781-42d9-9458-fdaf7170efed/details?q=previous%20gnaf)
    - The US databases are still work-in-progress but are based on data from [OpenAddresses](https://openaddresses.io/) and so any work with whereabouts based on US address data should adhere to the [OpenAddresses license](https://github.com/openaddresses/openaddresses/blob/master/LICENSE).

    Users of this software must comply with the terms and conditions of the respective data licenses, which may impose additional restrictions or requirements. By using this software, you agree to comply with the relevant licenses for any third-party data.
    """)
demo.launch()