Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
ajl2718
commited on
Commit
·
c79e5a0
1
Parent(s):
5eeed5b
Include database options
Browse files
app.py
CHANGED
|
@@ -9,15 +9,23 @@ download('au_vic_lg', 'saunteringcat/whereabouts-db')
|
|
| 9 |
download('au_nsw_lg', 'saunteringcat/whereabouts-db')
|
| 10 |
|
| 11 |
# create a matcher object
|
| 12 |
-
|
| 13 |
matcher2 = Matcher('au_all_lg')
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
# function to geocode results
|
| 18 |
-
def geocode(addresses):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
address_list = addresses.split('\n')
|
| 20 |
-
return
|
| 21 |
|
| 22 |
# the gradio interface
|
| 23 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
@@ -32,18 +40,30 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 32 |
gr.Markdown("Fast, accurate open source geocoding in Python")
|
| 33 |
gr.Markdown("""
|
| 34 |
[whereabouts](https://www.github.com/ajl2718/whereabouts) is an open source package for Python for fast and accurate geocoding within
|
| 35 |
-
your own environment. It currently supports geocoding for Australia but with more countries coming soon. It uses duckDB to geocode
|
| 36 |
gr.Markdown("""
|
| 37 |
```
|
| 38 |
pip install whereabouts
|
| 39 |
python -m whereabouts download au_all_sm
|
| 40 |
```
|
| 41 |
-
This demo shows whereabouts in action,
|
| 42 |
""")
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
text_input = gr.Textbox(lines=2, label="Addresses to geocode (one row per address)")
|
| 46 |
geocode_button = gr.Button(variant='primary')
|
| 47 |
json_output = gr.JSON(label="Output JSON data")
|
| 48 |
-
geocode_button.click(fn=geocode, inputs=text_input, outputs=json_output, api_name="whereabouts_geocoder")
|
| 49 |
demo.launch()
|
|
|
|
| 9 |
download('au_nsw_lg', 'saunteringcat/whereabouts-db')
|
| 10 |
|
| 11 |
# create a matcher object
|
| 12 |
+
matcher1 = Matcher('au_all_sm')
|
| 13 |
matcher2 = Matcher('au_all_lg')
|
| 14 |
+
matcher3 = Matcher('au_vic_lg')
|
| 15 |
+
matcher4 = Matcher('au_nsw_lg')
|
| 16 |
|
| 17 |
# function to geocode results
|
| 18 |
+
def geocode(addresses, db_name='au_all_sm', how='standard'):
|
| 19 |
+
if db_name == 'au_all_sm':
|
| 20 |
+
matcher = matcher1
|
| 21 |
+
elif db_name == 'au_all_lg':
|
| 22 |
+
matcher = matcher2
|
| 23 |
+
elif db_name == 'au_vic_lg':
|
| 24 |
+
matcher = matcher3
|
| 25 |
+
elif db_name == 'au_nsw_lg':
|
| 26 |
+
matcher = matcher4
|
| 27 |
address_list = addresses.split('\n')
|
| 28 |
+
return matcher.geocode(address_list, how=how)
|
| 29 |
|
| 30 |
# the gradio interface
|
| 31 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
|
| 40 |
gr.Markdown("Fast, accurate open source geocoding in Python")
|
| 41 |
gr.Markdown("""
|
| 42 |
[whereabouts](https://www.github.com/ajl2718/whereabouts) is an open source package for Python for fast and accurate geocoding within
|
| 43 |
+
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)""")
|
| 44 |
gr.Markdown("""
|
| 45 |
```
|
| 46 |
pip install whereabouts
|
| 47 |
python -m whereabouts download au_all_sm
|
| 48 |
```
|
| 49 |
+
This demo shows whereabouts in action, albeit slower due to the server. Running in your own environment speeds things up.
|
| 50 |
""")
|
| 51 |
with gr.Row():
|
| 52 |
with gr.Column():
|
| 53 |
+
dropdown_choice = gr.Dropdown(choices=[("Australia - Small", "au_all_sm"),
|
| 54 |
+
("Australia - Large", "au_all_lg"),
|
| 55 |
+
("Victoria, Australia - Large", "au_vic_lg"),
|
| 56 |
+
("New South Wales, Australia - Large", "au_vic_lg")],
|
| 57 |
+
value="au_all_sm",
|
| 58 |
+
multiselect=False,
|
| 59 |
+
label="Database",
|
| 60 |
+
info="Select from one of the geocoding databases based on country, region and size")
|
| 61 |
+
radio_choice = gr.Radio(choices=["standard", "trigram"],
|
| 62 |
+
value='standard',
|
| 63 |
+
label="Matching algorithm",
|
| 64 |
+
info="Trigram matching is more accurate but slower. Only available for the large databases.")
|
| 65 |
text_input = gr.Textbox(lines=2, label="Addresses to geocode (one row per address)")
|
| 66 |
geocode_button = gr.Button(variant='primary')
|
| 67 |
json_output = gr.JSON(label="Output JSON data")
|
| 68 |
+
geocode_button.click(fn=geocode, inputs=[text_input, dropdown_choice, radio_choice], outputs=json_output, api_name="whereabouts_geocoder")
|
| 69 |
demo.launch()
|