histOSM / strgrid_tab /strgrid_setup.py
muk42's picture
4th tab for street grids
fcdfac1
import gradio as gr
from .strgrid_logic import run_strgrid_logic
def get_strgrid_widgets():
with gr.Row():
with gr.Column(scale=1, min_width=500):
shp_input = gr.File(
label="Upload Zipped Shapefile with existing street grid"
)
run_osm_btn = gr.Button(
"Extract Nearest OSM Roads",
interactive=False
)
osm_log = gr.Textbox(
label="Progress",
lines=6,
interactive=False
)
osm_download = gr.File(
label="Download CSV",
file_types=[".csv"],
type="filepath"
)
def enable_run_btn(shp):
return gr.update(interactive=bool(shp))
shp_input.change(
fn=enable_run_btn,
inputs=shp_input,
outputs=run_osm_btn
)
def run_osm_wrapper(shp_file):
csv_path = run_strgrid_logic(
shp_file.name
)
return "Find nearest OSM roads is complete.", csv_path
run_osm_btn.click(
fn=run_osm_wrapper,
inputs=[shp_input],
outputs=[osm_log, osm_download]
)
return shp_input, run_osm_btn, osm_log, osm_download