Skip to content

Commit 9c8fa8b

Browse files
Create docs for 3.13.0 + fix requirements.txt (#2811)
* Create docs + fix bug * Changelog
1 parent 53005ab commit 9c8fa8b

4 files changed

Lines changed: 37191 additions & 66 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ These links are a more secure and scalable way to create shareable demos!
1919

2020
## Bug Fixes:
2121
* Allows `gr.Dataframe()` to take a `pandas.DataFrame` that includes numpy array and other types as its initial value, by [@abidlabs](https://github.com/abidlabs) in [PR 2804](https://github.com/gradio-app/gradio/pull/2804)
22+
* Add `altair` to requirements.txt by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2811](https://github.com/gradio-app/gradio/pull/2811)
2223

2324
## Documentation Changes:
24-
No changes to highlight.
25+
* Fixed some typos in the "Plot Component for Maps" guide by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2811](https://github.com/gradio-app/gradio/pull/2811)
2526

2627
## Testing and Infrastructure Changes:
2728
* Fixed test for IP address by [@abidlabs](https://github.com/abidlabs) in [PR 2808](https://github.com/gradio-app/gradio/pull/2808)

guides/05_tabular_data_science_and_plots/plot_component_for_maps.md

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,29 @@ This guide explains how you can use Gradio to plot geographical data on a map us
99

1010
## Overview
1111

12-
We will be using the New York City Airbnb dataset, which is hosted on kaggle [here](https://www.kaggle.com/datasets/dgomonov/new-york-city-airbnb-open-data). I've uploaded it to the Hugging Face Hub as a dataset [here](https://huggingface.co/datasets/gradio/NYC-Airbnb-Open-Data) for easier use and download. Using this data we will plot Airbnb locations on a map output and allow filtering based on price and location. Below is the demo that we will be buiding. ⚡️
13-
14-
<gradio-app space="gradio/NYC-Airbnb-Map"> </gradio-app>
12+
We will be using the New York City Airbnb dataset, which is hosted on kaggle [here](https://www.kaggle.com/datasets/dgomonov/new-york-city-airbnb-open-data). I've uploaded it to the Hugging Face Hub as a dataset [here](https://huggingface.co/datasets/gradio/NYC-Airbnb-Open-Data) for easier use and download. Using this data we will plot Airbnb locations on a map output and allow filtering based on price and location. Below is the demo that we will be building. ⚡️
1513

14+
$demo_map_airbnb
1615

1716
## Step 1 - Loading CSV data 💾
1817

1918
Let's start by loading the Airbnb NYC data from the Hugging Face Hub.
2019

2120
```python
22-
import pandas as pd
21+
from datasets import load_dataset
2322

2423
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
2524
df = dataset.to_pandas()
2625

2726
def filter_map(min_price, max_price, boroughs):
2827
new_df = df[(df['neighbourhood_group'].isin(boroughs)) &
2928
(df['price'] > min_price) & (df['price'] < max_price)]
30-
names = df["name"].tolist()
31-
prices = df["price"].tolist()
29+
names = new_df["name"].tolist()
30+
prices = new_df["price"].tolist()
3231
text_list = [(names[i], prices[i]) for i in range(0, len(names))]
3332
```
3433

35-
In the code above, we first load the csv data into a pandas dataframe. Let's begin by defining a function that we will use as the prediction fuction for the gradio app. This function will accept the minimum price and maximum price range as well as the list of boroughs to filter the resulting map. We can use the passed in values (`min_price`, `max_price`, and list of `boroughs`) to filter the dataframe and create `new_df`. Next we will create `text_list` of the names and prices of each Airbnb to use as labels on the map.
34+
In the code above, we first load the csv data into a pandas dataframe. Let's begin by defining a function that we will use as the prediction function for the gradio app. This function will accept the minimum price and maximum price range as well as the list of boroughs to filter the resulting map. We can use the passed in values (`min_price`, `max_price`, and list of `boroughs`) to filter the dataframe and create `new_df`. Next we will create `text_list` of the names and prices of each Airbnb to use as labels on the map.
3635

3736
## Step 2 - Map Figure 🌐
3837

@@ -93,63 +92,7 @@ We layout these components using the `gr.Column` and `gr.Row` and wel also add e
9392

9493
This is what the full demo code looks like:
9594

96-
```python
97-
import os
98-
import gradio as gr
99-
import pandas as pd
100-
import plotly.graph_objects as go
101-
102-
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
103-
df = dataset.to_pandas()
104-
105-
def filter_map(min_price, max_price, boroughs):
106-
107-
new_df = df[(df['neighbourhood_group'].isin(boroughs)) &
108-
(df['price'] > min_price) & (df['price'] < max_price)]
109-
names = df["name"].tolist()
110-
prices = df["price"].tolist()
111-
text_list = [(names[i], prices[i]) for i in range(0, len(names))]
112-
fig = go.Figure(go.Scattermapbox(
113-
customdata=text_list,
114-
lat=new_df['latitude'].tolist(),
115-
lon=new_df['longitude'].tolist(),
116-
mode='markers',
117-
marker=go.scattermapbox.Marker(
118-
size=6
119-
),
120-
hoverinfo="text",
121-
hovertemplate='<b>Name</b>: %{customdata[0]}<br><b>Price</b>: $%{customdata[1]}'
122-
))
123-
124-
fig.update_layout(
125-
mapbox_style="open-street-map",
126-
hovermode='closest',
127-
mapbox=dict(
128-
bearing=0,
129-
center=go.layout.mapbox.Center(
130-
lat=40.67,
131-
lon=-73.90
132-
),
133-
pitch=0,
134-
zoom=9
135-
),
136-
)
137-
138-
return fig
139-
140-
with gr.Blocks() as demo:
141-
with gr.Column():
142-
with gr.Row():
143-
min_price = gr.Number(value=250, label="Minimum Price")
144-
max_price = gr.Number(value=1000, label="Maximum Price")
145-
boroughs = gr.CheckboxGroup(choices=["Queens", "Brooklyn", "Manhattan", "Bronx", "Staten Island"], value=["Queens", "Brooklyn"], label="Select Boroughs:")
146-
btn = gr.Button(value="Update Filter")
147-
map = gr.Plot()
148-
demo.load(filter_map, [min_price, max_price, boroughs], map)
149-
btn.click(filter_map, [min_price, max_price, boroughs], map)
150-
151-
demo.launch()
152-
```
95+
$code_map_airbnb
15396

15497
## Step 4 - Deployment 🤗
15598
If you run the code above, your app will start running locally.
@@ -163,4 +106,4 @@ If you haven't used Spaces before, follow the previous guide [here](/using_huggi
163106
## Conclusion 🎉
164107
And you're all done! That's all the code you need to build a map demo.
165108

166-
Here's a link to the demo [Map demo](https://huggingface.co/spaces/gradio/NYC-Airbnb-Map) and [complete code](https://huggingface.co/spaces/gradio/NYC-Airbnb-Map/blob/main/app.py) (on Hugging Face Spaces)
109+
Here's a link to the demo [Map demo](https://huggingface.co/spaces/gradio/map_airbnb) and [complete code](https://huggingface.co/spaces/gradio/map_airbnb/blob/main/run.py) (on Hugging Face Spaces)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
aiohttp
2+
altair
23
h11<0.13,>=0.11
34
fastapi
45
ffmpy

0 commit comments

Comments
 (0)