tclopess commited on
Commit
434e16f
1 Parent(s): 5b31e17

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import plotly.graph_objects as go
3
+ from datasets import load_dataset
4
+
5
+ dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
6
+ df = dataset.to_pandas()
7
+
8
+ def filter_map(min_price, max_price, boroughs):
9
+
10
+ filtered_df = df[(df['neighbourhood_group'].isin(boroughs)) &
11
+ (df['price'] > min_price) & (df['price'] < max_price)]
12
+ names = filtered_df["name"].tolist()
13
+ prices = filtered_df["price"].tolist()
14
+ text_list = [(names[i], prices[i]) for i in range(0, len(names))]
15
+ fig = go.Figure(go.Scattermapbox(
16
+ customdata=text_list,
17
+ lat=filtered_df['latitude'].tolist(),
18
+ lon=filtered_df['longitude'].tolist(),
19
+ mode='markers',
20
+ marker=go.scattermapbox.Marker(
21
+ size=6
22
+ ),
23
+ hoverinfo="text",
24
+ hovertemplate='<b>Name</b>: %{customdata[0]}<br><b>Price</b>: $%{customdata[1]}'
25
+ ))
26
+
27
+ fig.update_layout(
28
+ mapbox_style="open-street-map",
29
+ hovermode='closest',
30
+ mapbox=dict(
31
+ bearing=0,
32
+ center=go.layout.mapbox.Center(
33
+ lat=40.67,
34
+ lon=-73.90
35
+ ),
36
+ pitch=0,
37
+ zoom=9
38
+ ),
39
+ )
40
+
41
+ return fig
42
+
43
+ with gr.Blocks() as demo:
44
+ with gr.Column():
45
+ with gr.Row():
46
+ min_price = gr.Number(value=250, label="Minimum Price")
47
+ max_price = gr.Number(value=1000, label="Maximum Price")
48
+ boroughs = gr.CheckboxGroup(choices=["Queens", "Brooklyn", "Manhattan", "Bronx", "Staten Island"], value=["Queens", "Brooklyn"], label="Select Boroughs:")
49
+ btn = gr.Button(value="Update Filter")
50
+ map = gr.Plot()
51
+ demo.load(filter_map, [min_price, max_price, boroughs], map)
52
+ btn.click(filter_map, [min_price, max_price, boroughs], map)
53
+
54
+ if __name__ == "__main__":
55
+ demo.launch()