Spaces:
Runtime error
Runtime error
import gradio as gr | |
from gradio_folium import Folium | |
from folium import Map | |
import pandas as pd | |
import pathlib | |
# create a dataframe with pathlib's Path to a __file__ in parent called cities.csv with places and latitude/longitude | |
df = pd.read_csv(pathlib.Path(__file__).parent / "cities.csv") | |
# select function with input dataframe and data where gradio Selects the Data then put data index 0 into df.iloc, then Map that location | |
def select(df, data: gr.SelectData): | |
row = df.iloc[data.index[0], :] | |
return Map(location=[row['Latitude'], row['Longitude']]) | |
# gradio blocks demo | |
with gr.Blocks() as demo: | |
gr.Markdown(("# 🗺️ Explore AI Data Maps with Gradio and Folium\n" | |
"Install this custom component with `pip install gradio_folium` - wheel files in this directory")) | |
# define map using Folium | |
map = Folium(value=Map(location=[25.7617, -80.1918]), height=400) | |
# Create a DataFrame viewer with dataframe input | |
data = gr.DataFrame(value=df, height=200) | |
# Run select with data and map | |
data.select(select, data, map) | |
demo.launch() | |