ljrmary peter2520 commited on
Commit
70d8e68
1 Parent(s): 59da0e7

Update app.py (#3)

Browse files

- Update app.py (5526681d03b01090f0a3036f555259ca6c586d5d)


Co-authored-by: Peter Hsieh <peter2520@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +54 -10
app.py CHANGED
@@ -1,39 +1,83 @@
1
  import gradio as gr
 
 
 
 
2
 
3
  def process_input(address, selected_option, additional_input):
4
- transport_analysis_needed = selected_option in ["Residential", "Office", "Community Facility"]
 
 
 
 
5
 
6
  output_address = f"You entered the address:\n{address}"
7
  output_option = f"Selected option:\n{selected_option}"
8
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  if selected_option in ["Off-Street Parking Facility", "Residential"]:
10
  output_additional = f"Number of Units/Spaces:\n{additional_input}"
11
  else:
12
  output_additional = f"Area (in 1000 GSF):\n{additional_input}"
13
 
14
- output_transport_analysis = f"Transport Analysis Needed:\n{transport_analysis_needed}"
15
-
 
 
16
  # Replace 'Your Zone Calculation Logic' with the actual zone calculation code
17
- zone = 'Your Zone Calculation Logic'
18
 
19
  output_zone = f"Zone:\n{zone}"
20
 
21
- return output_address, output_option, output_additional, output_transport_analysis, output_zone
 
 
 
 
 
 
 
22
 
23
  iface = gr.Interface(
24
  fn=process_input,
25
  inputs=[
26
  gr.inputs.Textbox(label="Enter your address"),
27
- gr.inputs.Radio(["Residential", "Office", "Regional Retail", "Local Retail", "Sit Down/High Turnover Restaurant", "Fast Food/without Drive Through",
28
- "Community Facility", "Off-Street Parking Facility"], label="Select an option"),
29
- gr.inputs.Number(label="Number of Units/Spaces or Area (in 1000 GSF)", default=1) # Default value is 1
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ],
31
  outputs=[
32
  gr.outputs.Textbox(label="Address"),
33
  gr.outputs.Textbox(label="Selected Option"),
34
  gr.outputs.Textbox(label="Number of Units/Spaces or Area"),
35
  gr.outputs.Textbox(label="Transport Analysis Needed"),
36
- gr.outputs.Textbox(label="Zone")
37
  ],
38
  )
39
 
 
1
  import gradio as gr
2
+ import requests
3
+ import geopandas as gpd
4
+ from shapely.geometry import Point
5
+
6
 
7
  def process_input(address, selected_option, additional_input):
8
+ transport_analysis_needed = selected_option in [
9
+ "Residential",
10
+ "Office",
11
+ "Community Facility",
12
+ ]
13
 
14
  output_address = f"You entered the address:\n{address}"
15
  output_option = f"Selected option:\n{selected_option}"
16
+
17
+ response = requests.get(
18
+ f"https://geosearch.planninglabs.nyc/v2/autocomplete?text={address}"
19
+ )
20
+ data = response.json()
21
+ x = data["features"][0]["geometry"]["coordinates"]
22
+
23
+ # Load the GeoJSON file into a GeoDataFrame
24
+ geodata = gpd.read_file("/content/zone_data.geojson")
25
+
26
+ # Create a Point for the given coordinates
27
+ location_point = Point(x[0], x[1])
28
+
29
+ # Find the zone that the location point is in
30
+ zone = geodata[geodata.geometry.contains(location_point)]["id"].values.item()
31
+
32
  if selected_option in ["Off-Street Parking Facility", "Residential"]:
33
  output_additional = f"Number of Units/Spaces:\n{additional_input}"
34
  else:
35
  output_additional = f"Area (in 1000 GSF):\n{additional_input}"
36
 
37
+ output_transport_analysis = (
38
+ f"Transport Analysis Needed:\n{transport_analysis_needed}"
39
+ )
40
+
41
  # Replace 'Your Zone Calculation Logic' with the actual zone calculation code
 
42
 
43
  output_zone = f"Zone:\n{zone}"
44
 
45
+ return (
46
+ output_address,
47
+ output_option,
48
+ output_additional,
49
+ output_transport_analysis,
50
+ output_zone,
51
+ )
52
+
53
 
54
  iface = gr.Interface(
55
  fn=process_input,
56
  inputs=[
57
  gr.inputs.Textbox(label="Enter your address"),
58
+ gr.inputs.Radio(
59
+ [
60
+ "Residential",
61
+ "Office",
62
+ "Regional Retail",
63
+ "Local Retail",
64
+ "Sit Down/High Turnover Restaurant",
65
+ "Fast Food/without Drive Through",
66
+ "Community Facility",
67
+ "Off-Street Parking Facility",
68
+ ],
69
+ label="Select an option",
70
+ ),
71
+ gr.inputs.Number(
72
+ label="Number of Units/Spaces or Area (in 1000 GSF)", default=1
73
+ ), # Default value is 1
74
  ],
75
  outputs=[
76
  gr.outputs.Textbox(label="Address"),
77
  gr.outputs.Textbox(label="Selected Option"),
78
  gr.outputs.Textbox(label="Number of Units/Spaces or Area"),
79
  gr.outputs.Textbox(label="Transport Analysis Needed"),
80
+ gr.outputs.Textbox(label="Zone"),
81
  ],
82
  )
83