Skip to content

66 gradio

image image image

Developing interactive web apps with gradio and leafmap

Gradio: https://gradio.app

1
# !pip install -U leafmap

Folium backend

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
import leafmap.foliumap as leafmap


def split(left, right):
    m = leafmap.Map()
    m.split_map(left_layer=left, right_layer=right)
    return m.to_gradio()


left_url = (
    "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"
)
right_url = (
    "https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif"
)
left_input = gr.Textbox(value=left_url, label="Left Layer URL")
right_input = gr.Textbox(value=right_url, label="Right Layer URL")

demo = gr.Interface(split, [left_input, right_input], "html")
# demo.launch()

Plotly backend

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import gradio as gr
import leafmap.plotlymap as leafmap


def viz_cog(url):
    m = leafmap.Map()
    m.add_cog_layer(url)
    return m


url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"

demo = gr.Interface(
    fn=viz_cog,
    inputs=gr.Text(value=url, label="Enter a COG URL"),
    outputs=gr.Plot(),
)
# demo.launch()