VIATEUR-AI's picture
# 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()
5ff2435 verified