Spaces:
Sleeping
Sleeping
File size: 1,430 Bytes
5ff2435 cf2c7b4 5ff2435 cf2c7b4 5ff2435 cf2c7b4 5ff2435 |
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 |
# app.py
import gradio as gr
import folium
import networkx as nx
from folium import Map, Marker, PolyLine
places = {
"Nyamirambo": (-1.9706, 30.0423),
"Downtown": (-1.9441, 30.0619),
"Kacyiru": (-1.9444, 30.0912),
"Kimironko": (-1.9300, 30.1250),
}
G = nx.Graph()
G.add_edge("Nyamirambo", "Downtown", weight=10)
G.add_edge("Downtown", "Kacyiru", weight=5)
G.add_edge("Kacyiru", "Kimironko", weight=7)
G.add_edge("Nyamirambo", "Kimironko", weight=20)
def generate_map(start, end):
m = Map(location=[-1.95, 30.08], zoom_start=13)
for name, coords in places.items():
Marker(location=coords, popup=name).add_to(m)
if start == end:
return "Hitamo aho utangiriye n’aho ugiye bitandukanye.", m._repr_html_()
try:
path = nx.astar_path(G, start, end, heuristic=lambda u,v: 0)
coords = [places[p] for p in path]
PolyLine(coords, color="blue", weight=5).add_to(m)
return "Inzira ngufi ni: " + " ➔ ".join(path), m._repr_html_()
except:
return "Ntibishoboka kubona inzira.", m._repr_html_()
iface = gr.Interface(
fn=generate_map,
inputs=[
gr.Dropdown(list(places.keys()), label="Hitamo aho uri"),
gr.Dropdown(list(places.keys()), label="Hitamo aho ugiye")
],
outputs=[
gr.Textbox(label="Ubutumwa"),
gr.HTML(label="Map")
],
title="🗺️ Rwanda Smart Route Planner"
)
iface.launch()
|