Spaces:
Runtime error
Runtime error
import ee | |
import geemap.foliumap as geemap | |
import gradio as gr | |
ee.Authenticate | |
ee.Initialize(project='august-tract-445517-i2') | |
def generate_map(start_date, end_date, zoom, center_lat, center_lon): | |
Map = geemap.Map(center=[center_lat, center_lon], zoom=zoom) | |
# Load Landsat 8 ImageCollection filtered by date | |
landsat = ( | |
ee.ImageCollection("LANDSAT/LC08/C02/T1_L2") | |
.filterDate(start_date, end_date) | |
.median() | |
) | |
# Visualization parameters | |
vis_params = { | |
"bands": ["SR_B4", "SR_B3", "SR_B2"], # Red, Green, Blue bands | |
"min": 0, | |
"max": 3000, | |
"gamma": 1.4, | |
} | |
# Add Landsat layer to the map | |
Map.addLayer(landsat, vis_params, "Landsat 8") | |
Map.addLayerControl() # Add layer controls | |
# Save the map as an HTML file | |
map_file = "map.html" | |
Map.save(map_file) | |
# Return the HTML file | |
return map_file | |
# Gradio interface | |
def render_map(start_date, end_date, zoom, center_lat, center_lon): | |
map_file = generate_map(start_date, end_date, zoom, center_lat, center_lon) | |
with open(map_file, "r", encoding="utf-8") as f: | |
html_content = f.read() | |
return html_content | |
# Gradio app | |
iface = gr.Interface( | |
fn=render_map, | |
inputs=[ | |
gr.inputs.Textbox(label="Start Date (YYYY-MM-DD)", default="2021-01-01"), | |
gr.inputs.Textbox(label="End Date (YYYY-MM-DD)", default="2021-12-31"), | |
gr.inputs.Slider(label="Zoom Level", minimum=1, maximum=20, default=4), | |
gr.inputs.Number(label="Center Latitude", default=20.0), | |
gr.inputs.Number(label="Center Longitude", default=78.0), | |
], | |
outputs=gr.HTML(label="Interactive Map"), | |
title="Interactive Google Earth Engine Map", | |
description="Generate a responsive map using Landsat 8 data by specifying date range, zoom level, and center coordinates.", | |
) | |
iface.launch(server_name="0.0.0.0", server_port=7860) |