Spaces:
Runtime error
Runtime error
File size: 1,098 Bytes
e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a 26d9eaf e49e46a |
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 |
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()
|