awacke1 commited on
Commit
26d9eaf
·
1 Parent(s): 3512c7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -1,21 +1,32 @@
1
-
2
  import gradio as gr
 
3
  from gradio_folium import Folium
4
  from folium import Map
 
5
  import pandas as pd
6
  import pathlib
7
 
 
8
  df = pd.read_csv(pathlib.Path(__file__).parent / "cities.csv")
9
 
 
10
  def select(df, data: gr.SelectData):
11
  row = df.iloc[data.index[0], :]
12
  return Map(location=[row['Latitude'], row['Longitude']])
13
 
 
14
  with gr.Blocks() as demo:
15
- gr.Markdown(("# 🗺️ Explore World Capitals with Gradio and Folium\n"
16
- "Install this custom component with `pip install gradio_folium`"))
 
 
 
17
  map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
 
 
18
  data = gr.DataFrame(value=df, height=200)
 
 
19
  data.select(select, data, map)
20
 
21
  demo.launch()
 
 
1
  import gradio as gr
2
+
3
  from gradio_folium import Folium
4
  from folium import Map
5
+
6
  import pandas as pd
7
  import pathlib
8
 
9
+ # create a dataframe with pathlib's Path to a __file__ in parent called cities.csv with places and latitude/longitude
10
  df = pd.read_csv(pathlib.Path(__file__).parent / "cities.csv")
11
 
12
+ # select function with input dataframe and data where gradio Selects the Data then put data index 0 into df.iloc, then Map that location
13
  def select(df, data: gr.SelectData):
14
  row = df.iloc[data.index[0], :]
15
  return Map(location=[row['Latitude'], row['Longitude']])
16
 
17
+ # gradio blocks demo
18
  with gr.Blocks() as demo:
19
+
20
+ gr.Markdown(("# 🗺️ Explore AI Data Maps with Gradio and Folium\n"
21
+ "Install this custom component with `pip install gradio_folium` - wheel files in this directory"))
22
+
23
+ # define map using Folium
24
  map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
25
+
26
+ # Create a DataFrame viewer with dataframe input
27
  data = gr.DataFrame(value=df, height=200)
28
+
29
+ # Run select with data and map
30
  data.select(select, data, map)
31
 
32
  demo.launch()