import gradio as gr
import random
locations = {
"Downtown": {"lat": -1.95, "lon": 30.05},
"Highway": {"lat": -1.92, "lon": 30.06},
"Industrial Area": {"lat": -1.94, "lon": 30.07},
"School Zone": {"lat": -1.93, "lon": 30.03}
}
tile_layers = {
"Light": {
"url": "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
"attribution": '© CartoDB contributors'
},
"Dark": {
"url": "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
"attribution": '© CartoDB contributors'
},
"Satellite": {
"url": "https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}",
"attribution": "Β© Google",
"subdomains": ["mt0", "mt1", "mt2", "mt3"]
}
}
def simulate_map_style(style):
markers = ""
alerts = []
for name, info in locations.items():
speed = round(random.gauss(30, 15), 1)
vehicles = int(random.gauss(40, 15))
if speed < 20 and vehicles > 50:
status = "π¦ Heavy Traffic"
color = "red"
elif speed < 40 or vehicles > 40:
status = "β οΈ Moderate Traffic"
color = "orange"
else:
status = "β
Light Traffic"
color = "green"
alerts.append(f"π {name}: {status} β {speed} km/h, {vehicles} cars")
markers += f"""
L.circleMarker([{info['lat']}, {info['lon']}], {{
color: '{color}',
radius: 10
}}).addTo(map).bindPopup("{name}
Speed: {speed} km/h
Cars: {vehicles}
Status: {status}");"""
layer = tile_layers[style]
subdomains_str = f", subdomains: {layer['subdomains']}" if "subdomains" in layer else ""
html = f"""