dawood HF staff commited on
Commit
1098372
1 Parent(s): b0132bc

Create new file

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from cgitb import text
2
+ import os
3
+ import gradio as gr
4
+ import pandas as pd
5
+ import plotly.graph_objects as go
6
+
7
+ MAPBOX_TOKEN = os.environ.get('MAPBOX_TOKEN')
8
+ df = pd.read_csv("AB_NYC_2019.csv")
9
+
10
+ def update_map(min_price, max_price, boroughs):
11
+
12
+ new_df = df[(df['neighbourhood_group'].isin(boroughs)) &
13
+ (df['price'] > min_price) & (df['price'] < max_price)]
14
+ names = df["name"].tolist()
15
+ prices = df["price"].tolist()
16
+ text_list = [(names[i], prices[i]) for i in range(0, len(names))]
17
+ fig = go.Figure(go.Scattermapbox(
18
+ customdata=text_list,
19
+ lat=new_df['latitude'].tolist(),
20
+ lon=new_df['longitude'].tolist(),
21
+ mode='markers',
22
+ marker=go.scattermapbox.Marker(
23
+ size=6
24
+ ),
25
+ hoverinfo="text",
26
+ hovertemplate =
27
+ '<br><b>Name</b>: %{customdata[0]}'+
28
+ '<br><b>Price</b>: $%{customdata[1]}<br>'
29
+ ))
30
+
31
+ fig.update_layout(
32
+ autosize=True,
33
+ hovermode='closest',
34
+ mapbox=dict(
35
+ accesstoken=MAPBOX_TOKEN,
36
+ bearing=0,
37
+ center=go.layout.mapbox.Center(
38
+ lat=40.67,
39
+ lon=-73.90
40
+ ),
41
+ pitch=0,
42
+ zoom=9
43
+ ),
44
+ )
45
+
46
+ return fig
47
+
48
+ with gr.Blocks() as demo:
49
+ with gr.Row():
50
+ with gr.Column():
51
+ min_price = gr.Number(value=0, label="Minimum Price")
52
+ max_price = gr.Number(value=1000, label="Maximum Price")
53
+ boroughs = gr.CheckboxGroup(["Queens", "Brooklyn", "Manhattan", "Bronx", "Staten Island"], label="Select Boroughs:")
54
+ with gr.Column():
55
+ with gr.Box():
56
+ map = gr.Plot()
57
+ min_price.submit(update_map, [min_price, max_price, boroughs], map)
58
+ max_price.submit(update_map, [min_price, max_price, boroughs], map)
59
+ max_price.change(update_map, [min_price, max_price, boroughs], map)
60
+ boroughs.change(update_map, [min_price, max_price, boroughs], map)
61
+ demo.load(update_map, [min_price, max_price, boroughs], map)
62
+
63
+ demo.launch()