File size: 2,165 Bytes
e49e46a
 
 
 
 
0b9c9a0
e49e46a
969a9f6
 
 
 
e49e46a
969a9f6
 
 
 
e49e46a
969a9f6
a594112
0b9c9a0
 
969a9f6
a594112
 
 
 
969a9f6
e49e46a
969a9f6
 
61c828c
 
 
 
 
 
969a9f6
 
61c828c
 
26d9eaf
969a9f6
e625121
 
 
 
61c828c
 
 
26d9eaf
969a9f6
61c828c
26d9eaf
969a9f6
61c828c
 
 
e49e46a
969a9f6
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
from gradio_folium import Folium
from folium import Map
import pandas as pd
import pathlib
import os # for file search of csv files

# Function to list all CSV files in the current directory
def list_csv_files():
    path = pathlib.Path(__file__).parent
    return [f for f in os.listdir(path) if f.endswith('.csv')]

# Function to load data from selected CSV and update the map
def update_map(csv_file):
    df = pd.read_csv(pathlib.Path(__file__).parent / csv_file)
    return df, Folium(value=Map(location=[df.iloc[0]['Latitude'], df.iloc[0]['Longitude']], zoom_start=10), height=400)

# Function to update location on map based on selected data row
def select_experimental(data: gr.Dataframe):
    row = data.iloc[0, :]
    return Map(location=[row['Latitude'], row['Longitude']], zoom_start=10)

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

# Gradio Blocks
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")
    map = Folium(value=Map(location=[25.7617, -80.1918]), height=400)
    data = gr.DataFrame(value=df, height=200)
    data.select(select, data, map)

demo.launch()


    # Select box for CSV files
    #csv_files = list_csv_files()
    #csv_selector = gr.Dropdown(label="Select CSV File", choices=csv_files)

    # Dataframe and map components
    # data = gr.Dataframe()
    # map_component = Folium(height=400)

    
    #map = Folium(value=Map(location=[25.7617, -80.1918]), height=400) 
    #data = gr.DataFrame(value=df, height=200)
    #data.select(select, data, map)

    # Button to reload data and map
    #reload_button = gr.Button("🔄 Reload", elem_id="reload_button")

    # Interaction logic
    #csv_selector.change(update_map, inputs=csv_selector, outputs=[data, map_component])
    #data.select(select, inputs=data, outputs=map_component)
    #reload_button.click(update_map, inputs=csv_selector, outputs=[data, map_component])

# Launch the app
demo.launch()