gradio_folium / src /README.md
freddyaboulton's picture
Upload folder using huggingface_hub
d9a3dc8 verified

gradio_folium

PyPI - Version

Display Interactive Maps Created with Folium

Installation

pip install gradio_folium

Usage


import gradio as gr
from gradio_folium import Folium
from folium import Map
import pandas as pd
import pathlib

df = pd.read_csv(pathlib.Path(__file__).parent / "cities.csv")

def select(df, data: gr.SelectData):
    row = df.iloc[data.index[0], :]
    return Map(location=[row['Latitude'], row['Longitude']])

with gr.Blocks() as demo:
    gr.Markdown(("# 🗺️ Explore World Capitals with Gradio and Folium\n"
                 "Install this custom component with `pip install gradio_folium`"))
    map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
    data = gr.DataFrame(value=df, height=200)
    data.select(select, data, map)

if __name__ == "__main__":
    demo.launch()

Folium

Initialization

name type default description
value
Any
None None
height
int | None
None None
label
str | None
None None
container
bool
True None
scale
int | None
None None
min_width
int | None
None None
visible
bool
True None
elem_id
str | None
None None
elem_classes
list[str] | str | None
None None
render
bool
True None
load_fn
Callable[Ellipsis, Any] | None
None None
every
float | None
None None

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

def predict(
    value: Unknown
) -> folium.folium.Map:
    return value