Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,45 +16,30 @@ def update_map(csv_file):
|
|
16 |
return df, Folium(value=Map(location=[df.iloc[0]['Latitude'], df.iloc[0]['Longitude']], zoom_start=10), height=400)
|
17 |
|
18 |
# Function to update location on map based on selected data row
|
19 |
-
def
|
20 |
row = data.iloc[0, :]
|
21 |
return Map(location=[row['Latitude'], row['Longitude']], zoom_start=10)
|
22 |
|
23 |
-
def select(df, data: gr.SelectData):
|
24 |
-
row = df.iloc[data.index[0], :]
|
25 |
-
return Map(location=[row['Latitude'], row['Longitude']])
|
26 |
-
|
27 |
# Gradio Blocks
|
28 |
with gr.Blocks() as demo:
|
29 |
gr.Markdown("# 🗺️ Explore AI Data Maps with Gradio and Folium\n"
|
30 |
"Install this custom component with `pip install gradio_folium` - wheel files in this directory")
|
31 |
-
map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
|
32 |
-
data = gr.DataFrame(value=df, height=200)
|
33 |
-
data.select(select, data, map)
|
34 |
-
|
35 |
-
demo.launch()
|
36 |
-
|
37 |
|
38 |
# Select box for CSV files
|
39 |
-
|
40 |
-
|
41 |
|
42 |
# Dataframe and map components
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
#map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
|
48 |
-
#data = gr.DataFrame(value=df, height=200)
|
49 |
-
#data.select(select, data, map)
|
50 |
|
51 |
# Button to reload data and map
|
52 |
-
|
53 |
|
54 |
# Interaction logic
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
# Launch the app
|
60 |
demo.launch()
|
|
|
16 |
return df, Folium(value=Map(location=[df.iloc[0]['Latitude'], df.iloc[0]['Longitude']], zoom_start=10), height=400)
|
17 |
|
18 |
# Function to update location on map based on selected data row
|
19 |
+
def select(data: gr.Dataframe):
|
20 |
row = data.iloc[0, :]
|
21 |
return Map(location=[row['Latitude'], row['Longitude']], zoom_start=10)
|
22 |
|
|
|
|
|
|
|
|
|
23 |
# Gradio Blocks
|
24 |
with gr.Blocks() as demo:
|
25 |
gr.Markdown("# 🗺️ Explore AI Data Maps with Gradio and Folium\n"
|
26 |
"Install this custom component with `pip install gradio_folium` - wheel files in this directory")
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Select box for CSV files
|
29 |
+
csv_files = list_csv_files()
|
30 |
+
csv_selector = gr.Dropdown(label="Select CSV File", choices=csv_files)
|
31 |
|
32 |
# Dataframe and map components
|
33 |
+
data = gr.Dataframe()
|
34 |
+
map_component = Folium(height=400)
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Button to reload data and map
|
37 |
+
reload_button = gr.Button("🔄 Reload", elem_id="reload_button")
|
38 |
|
39 |
# Interaction logic
|
40 |
+
csv_selector.change(update_map, inputs=csv_selector, outputs=[data, map_component])
|
41 |
+
data.select(select, inputs=data, outputs=map_component)
|
42 |
+
reload_button.click(update_map, inputs=csv_selector, outputs=[data, map_component])
|
43 |
|
44 |
# Launch the app
|
45 |
demo.launch()
|