Spaces:
Sleeping
Sleeping
sadFaceEmoji
commited on
Commit
·
a4f2af5
1
Parent(s):
e89c211
Add app
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import osmnx as ox
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
import plotly.express as px
|
5 |
+
from pub_crawl_script import pub_crawl
|
6 |
+
|
7 |
+
df = pd.read_csv('galway_pubs.csv')
|
8 |
+
G = ox.io.load_graphml('galway.graphml')
|
9 |
+
|
10 |
+
def galway_map():
|
11 |
+
fig = px.scatter_mapbox(df, lat='latitude', lon='longitude', hover_name='name',
|
12 |
+
# hover_data=f"Address: {str(df['address'])}",
|
13 |
+
color_discrete_sequence=["fuchsia"],
|
14 |
+
zoom=14, height=300, opacity=0.8, size=[1]*len(df), size_max=12)
|
15 |
+
fig.update_layout(mapbox_style='open-street-map',
|
16 |
+
margin={"r": 0, "t": 0, "l": 0, "b": 0},
|
17 |
+
mapbox_bounds={"west": -9.0644, "east": -9.0456, "south": 53.2691, "north": 53.2763})
|
18 |
+
return fig
|
19 |
+
|
20 |
+
def execute_crawl_optimiser(start_pub, pubs_considered):
|
21 |
+
crawler = pub_crawl(df, G)
|
22 |
+
crawler.optimise(start_pub, pubs_considered)
|
23 |
+
route_str = ''
|
24 |
+
for i in range(len(crawler.optimal_route)-1):
|
25 |
+
route_str += f'{crawler.optimal_route[i]} --> '
|
26 |
+
route_str += crawler.optimal_route[-1]
|
27 |
+
return crawler.optimal_distance, route_str, crawler.plot_route(crawler.optimal_route)
|
28 |
+
|
29 |
+
with gr.Blocks() as pub_crawl_ui:
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
map = gr.Plot(galway_map, label='Galway Map')
|
33 |
+
with gr.Column():
|
34 |
+
start_pub = gr.Dropdown(df['name'].to_list(), value='Caribou', label="Start Pub")
|
35 |
+
pubs_considered = gr.CheckboxGroup(df['name'].to_list(), label='Pubs to Visit',
|
36 |
+
info='Please make sure "Start Pub" is selected')
|
37 |
+
with gr.Row():
|
38 |
+
run_btn = gr.Button("Run")
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column(scale=1):
|
41 |
+
distance = gr.Number(value=None, label="Route Distance (meters)")
|
42 |
+
with gr.Column(scale=3):
|
43 |
+
route = gr.Textbox(label="Route")
|
44 |
+
with gr.Row():
|
45 |
+
route_plot = gr.Plot(label="Route Map", height=1200)
|
46 |
+
|
47 |
+
run_btn.click(fn=execute_crawl_optimiser, inputs=[start_pub, pubs_considered], outputs=[distance, route, route_plot], api_name="pub_crawl")
|
48 |
+
|
49 |
+
pub_crawl_ui.launch()
|