File size: 2,953 Bytes
cf73590
 
 
 
62621a3
cf73590
 
 
62621a3
cf73590
 
 
 
62621a3
cf73590
62621a3
 
 
 
 
 
cf73590
 
 
407bc71
cf73590
 
 
 
 
 
 
62621a3
 
 
81d48d9
62621a3
 
 
 
cf73590
 
 
 
 
12a4fc3
 
 
 
 
 
 
 
d037418
62621a3
cf73590
 
 
 
 
 
4eb3786
cf73590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
92
93
94
95
96
97
import gradio as gr
import requests
import geopandas as gpd
from shapely.geometry import Point
import pandas as pd


def process_input(address, selected_option, additional_input):
    transport_analysis_needed = True

    response = requests.get(
        f"https://geosearch.planninglabs.nyc/v2/autocomplete?text={address}"
    )
    
    data = response.json()
    
    address = data["features"][0]["properties"]["label"]
    output_address = f"{address}"
    output_option = f"{selected_option}"

    
    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()

    # Load Zone Table of Transportation Analysis
    df = pd.read_csv("./zone_table.csv")
    df = df.loc[df['Development Type']==selected_option] 
    threshold_value = df.loc[:, f"Zone {zone}"].values.item()

    if additional_input < threshold_value:
        transport_analysis_needed = False

    if selected_option in ["Off-Street Parking Facility", "Residential"]:
        output_additional = f"Number of Units/Spaces:\n{additional_input}"
    else:
        output_additional = f"Area (in 1000 GSF):\n{additional_input}"

    if (transport_analysis_needed):
        output_transport_analysis = (
            f"{transport_analysis_needed} (Because proposed developing units/space is larger than {threshold_value})"
        )
    else:
        output_transport_analysis = (
            f"{transport_analysis_needed} (Because proposed developing units/space is smaller than {threshold_value})"
        )
    
    output_zone = f"{zone}"

    return (
        output_address,
        output_option,
        output_additional,
        output_transport_analysis,
        output_zone,
    )


iface = gr.Interface(
    fn=process_input,
    inputs=[
        gr.inputs.Textbox(label="Enter your address"),
        gr.inputs.Radio(
            [
                "Residential",
                "Office",
                "Regional Retail",
                "Local Retail",
                "Sit Down/High Turnover Restaurant",
                "Fast Food/without Drive Through",
                "Community Facility",
                "Off-Street Parking Facility",
            ],
            label="Select an option",
        ),
        gr.inputs.Number(
            label="Number of Units/Spaces or Area (in 1000 GSF)", default=1
        ),  # Default value is 1
    ],
    outputs=[
        gr.outputs.Textbox(label="Address"),
        gr.outputs.Textbox(label="Selected Option"),
        gr.outputs.Textbox(label="Number of Units/Spaces or Area"),
        gr.outputs.Textbox(label="Transport Analysis Needed"),
        gr.outputs.Textbox(label="Zone"),
    ],
)

iface.launch()