pgzmnk commited on
Commit
fdda1da
0 Parent(s):

First commit.

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +54 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .venv
2
+ __pycache__/
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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().style()
51
+ demo.load(filter_map, [min_price, max_price, boroughs], map)
52
+ btn.click(filter_map, [min_price, max_price, boroughs], map)
53
+
54
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ datasets
2
+ plotly
3
+ gradio