Spaces:
Sleeping
Sleeping
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), "Remera": (-1.9350, 30.1150), "Gikondo": (-1.9780, 30.0300), "Nyarugenge": (-1.9517, 30.0587), "Kicukiro": (-1.9761, 30.0992), "Kimihurura": (-1.9485, 30.0741), "Nyamata": (-2.0633, 30.3203), "Rwamagana": (-1.9489, 30.4367), "Musanze": (-1.5014, 29.6344), "Huye": (-2.5906, 29.7399), "Rubavu": (-1.7044, 29.2597), "Gisenyi": (-1.7011, 29.2568) } 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) G.add_edge("Kacyiru", "Remera", weight=3) G.add_edge("Remera", "Kimihurura", weight=4) G.add_edge("Kimihurura", "Kacyiru", weight=6) G.add_edge("Gikondo", "Nyamirambo", weight=6) G.add_edge("Nyarugenge", "Downtown", weight=2) G.add_edge("Kicukiro", "Gikondo", weight=4) G.add_edge("Nyamata", "Rwamagana", weight=18) G.add_edge("Rwamagana", "Kacyiru", weight=22) G.add_edge("Musanze", "Rubavu", weight=60) G.add_edge("Rubavu", "Gisenyi", weight=3) G.add_edge("Huye", "Nyamata", weight=75) G.add_edge("Kicukiro", "Kimihurura", weight=12) def generate_map(start, end): m = Map(location=[-1.95, 30.08], zoom_start=11) 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()
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import folium
|
5 |
import networkx as nx
|
@@ -10,6 +8,17 @@ places = {
|
|
10 |
"Downtown": (-1.9441, 30.0619),
|
11 |
"Kacyiru": (-1.9444, 30.0912),
|
12 |
"Kimironko": (-1.9300, 30.1250),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
|
15 |
G = nx.Graph()
|
@@ -17,9 +26,21 @@ G.add_edge("Nyamirambo", "Downtown", weight=10)
|
|
17 |
G.add_edge("Downtown", "Kacyiru", weight=5)
|
18 |
G.add_edge("Kacyiru", "Kimironko", weight=7)
|
19 |
G.add_edge("Nyamirambo", "Kimironko", weight=20)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def generate_map(start, end):
|
22 |
-
m = Map(location=[-1.95, 30.08], zoom_start=
|
23 |
for name, coords in places.items():
|
24 |
Marker(location=coords, popup=name).add_to(m)
|
25 |
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import folium
|
3 |
import networkx as nx
|
|
|
8 |
"Downtown": (-1.9441, 30.0619),
|
9 |
"Kacyiru": (-1.9444, 30.0912),
|
10 |
"Kimironko": (-1.9300, 30.1250),
|
11 |
+
"Remera": (-1.9350, 30.1150),
|
12 |
+
"Gikondo": (-1.9780, 30.0300),
|
13 |
+
"Nyarugenge": (-1.9517, 30.0587),
|
14 |
+
"Kicukiro": (-1.9761, 30.0992),
|
15 |
+
"Kimihurura": (-1.9485, 30.0741),
|
16 |
+
"Nyamata": (-2.0633, 30.3203),
|
17 |
+
"Rwamagana": (-1.9489, 30.4367),
|
18 |
+
"Musanze": (-1.5014, 29.6344),
|
19 |
+
"Huye": (-2.5906, 29.7399),
|
20 |
+
"Rubavu": (-1.7044, 29.2597),
|
21 |
+
"Gisenyi": (-1.7011, 29.2568)
|
22 |
}
|
23 |
|
24 |
G = nx.Graph()
|
|
|
26 |
G.add_edge("Downtown", "Kacyiru", weight=5)
|
27 |
G.add_edge("Kacyiru", "Kimironko", weight=7)
|
28 |
G.add_edge("Nyamirambo", "Kimironko", weight=20)
|
29 |
+
G.add_edge("Kacyiru", "Remera", weight=3)
|
30 |
+
G.add_edge("Remera", "Kimihurura", weight=4)
|
31 |
+
G.add_edge("Kimihurura", "Kacyiru", weight=6)
|
32 |
+
G.add_edge("Gikondo", "Nyamirambo", weight=6)
|
33 |
+
G.add_edge("Nyarugenge", "Downtown", weight=2)
|
34 |
+
G.add_edge("Kicukiro", "Gikondo", weight=4)
|
35 |
+
G.add_edge("Nyamata", "Rwamagana", weight=18)
|
36 |
+
G.add_edge("Rwamagana", "Kacyiru", weight=22)
|
37 |
+
G.add_edge("Musanze", "Rubavu", weight=60)
|
38 |
+
G.add_edge("Rubavu", "Gisenyi", weight=3)
|
39 |
+
G.add_edge("Huye", "Nyamata", weight=75)
|
40 |
+
G.add_edge("Kicukiro", "Kimihurura", weight=12)
|
41 |
|
42 |
def generate_map(start, end):
|
43 |
+
m = Map(location=[-1.95, 30.08], zoom_start=11)
|
44 |
for name, coords in places.items():
|
45 |
Marker(location=coords, popup=name).add_to(m)
|
46 |
|