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