File size: 2,080 Bytes
1098372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from cgitb import text
import os
import gradio as gr
import pandas as pd
import plotly.graph_objects as go

MAPBOX_TOKEN = os.environ.get('MAPBOX_TOKEN')
df = pd.read_csv("AB_NYC_2019.csv")

def update_map(min_price, max_price, boroughs):

    new_df = df[(df['neighbourhood_group'].isin(boroughs)) & 
          (df['price'] > min_price) & (df['price'] < max_price)]
    names = df["name"].tolist()
    prices = df["price"].tolist()
    text_list = [(names[i], prices[i]) for i in range(0, len(names))]
    fig = go.Figure(go.Scattermapbox(
            customdata=text_list,
            lat=new_df['latitude'].tolist(),
            lon=new_df['longitude'].tolist(),
            mode='markers',
            marker=go.scattermapbox.Marker(
                size=6
            ),
            hoverinfo="text",
            hovertemplate =
            '<br><b>Name</b>: %{customdata[0]}'+
            '<br><b>Price</b>: $%{customdata[1]}<br>'
        ))

    fig.update_layout(
        autosize=True,
        hovermode='closest',
        mapbox=dict(
            accesstoken=MAPBOX_TOKEN,
            bearing=0,
            center=go.layout.mapbox.Center(
                lat=40.67,
                lon=-73.90
            ),
            pitch=0,
            zoom=9
        ),
    )

    return fig

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            min_price = gr.Number(value=0, label="Minimum Price")
            max_price = gr.Number(value=1000, label="Maximum Price")
            boroughs = gr.CheckboxGroup(["Queens", "Brooklyn", "Manhattan", "Bronx", "Staten Island"], label="Select Boroughs:")
        with gr.Column():
            with gr.Box():
                map = gr.Plot()
    min_price.submit(update_map, [min_price, max_price, boroughs], map)
    max_price.submit(update_map, [min_price, max_price, boroughs], map)
    max_price.change(update_map, [min_price, max_price, boroughs], map)
    boroughs.change(update_map, [min_price, max_price, boroughs], map)
    demo.load(update_map, [min_price, max_price, boroughs], map)

demo.launch()