Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import geopandas as gpd | |
| from shapely.geometry import Point | |
| def process_input(address, selected_option, additional_input, num_units, temporal_split, modal_split, directional_distribution): | |
| transport_analysis_needed = selected_option in ["Residential", "Office", "Community Facility"] | |
| output_address = f"You entered the address:\n{address}" | |
| output_option = f"Selected option:\n{selected_option}" | |
| response = requests.get(f"https://geosearch.planninglabs.nyc/v2/autocomplete?text={address}") | |
| data = response.json() | |
| x = data["features"][0]["geometry"]["coordinates"] | |
| # Load the GeoJSON file into a GeoDataFrame | |
| geodata = gpd.read_file("./zone_data.geojson") | |
| # Create a Point for the given coordinates | |
| location_point = Point(x[0], x[1]) | |
| # Find the zone that the location point is in | |
| zone = geodata[geodata.geometry.contains(location_point)]["id"].values.item() | |
| output_additional = ( | |
| f"Number of Units/Spaces:\n{additional_input}" | |
| if selected_option in ["Off-Street Parking Facility", "Residential"] | |
| else f"Area (in 1000 GSF):\n{additional_input}" | |
| ) | |
| output_num_units = f"Number of Units:\n{num_units}" | |
| output_temporal_split = f"Temporal Split:\n{temporal_split}" | |
| output_modal_split = f"Modal Split:\n{modal_split}" | |
| output_directional_distribution = f"Directional Distribution:\n{directional_distribution}" | |
| output_transport_analysis = f"Transport Analysis Needed:\n{transport_analysis_needed}" | |
| return ( | |
| output_address, | |
| output_option, | |
| output_additional, | |
| output_num_units, | |
| output_temporal_split, | |
| output_modal_split, | |
| output_directional_distribution, | |
| output_transport_analysis, | |
| f"Zone:\n{zone}", | |
| ) | |
| iface = gr.Interface( | |
| fn=process_input, | |
| inputs=[ | |
| gr.inputs.Textbox(label="Address", type="text"), | |
| gr.inputs.Radio( | |
| ["Office", "Local Retail", "Exhibit Space", "Restaurant"], label="Land Use Selection" | |
| ), | |
| gr.inputs.Number( | |
| label="Number of Units/Spaces or Area (in 1000 GSF)", default=1 | |
| ), | |
| gr.inputs.Textbox(label="Number of Units", type="text"), | |
| gr.inputs.Radio(["morning", "midday", "afternoon"], label="Temporal Split"), | |
| gr.inputs.Radio(["car", "taxi", "bus", "subway", "walking"], label="Modal Split"), | |
| gr.inputs.Dropdown(["inbound", "outbound"], label="Directional Distribution"), | |
| ], | |
| outputs=[ | |
| gr.outputs.Textbox(label="Address"), | |
| gr.outputs.Textbox(label="Land Use Selection"), | |
| gr.outputs.Textbox(label="Number of Units/Spaces or Area"), | |
| gr.outputs.Textbox(label="Number of Units"), | |
| gr.outputs.Textbox(label="Temporal Split"), | |
| gr.outputs.Textbox(label="Modal Split"), | |
| gr.outputs.Textbox(label="Directional Distribution"), | |
| gr.outputs.Textbox(label="Transport Analysis Needed"), | |
| gr.outputs.Textbox(label="Zone"), | |
| ], | |
| ) | |
| iface.launch() | |