Az-r-ow commited on
Commit
a4bde73
·
1 Parent(s): 65b2047

feat(interface): Beta version of the interface

Browse files
Files changed (1) hide show
  1. app/app.py +17 -9
app/app.py CHANGED
@@ -86,10 +86,10 @@ def formatPath(path):
86
  return "\n".join([f"{i + 1}. {elem}" for i, elem in enumerate(path)])
87
 
88
 
89
- def plotMap(stationsInformation: dict):
90
- stationNames = stationsInformation["stations"] if len(stationsInformation) else []
91
- stationsLat = stationsInformation["lat"] if len(stationsInformation) else []
92
- stationsLon = stationsInformation["lon"] if len(stationsInformation) else []
93
 
94
  plt = go.Figure(
95
  go.Scattermapbox(
@@ -101,10 +101,17 @@ def plotMap(stationsInformation: dict):
101
  )
102
  )
103
 
 
 
 
 
 
 
 
104
  plt.update_layout(
105
  mapbox_style="open-street-map",
106
  mapbox=dict(
107
- center=go.layout.mapbox.Center(lat=stationsLat[0], lon=stationsLon[0]),
108
  pitch=0,
109
  zoom=3,
110
  ),
@@ -134,7 +141,7 @@ def handleStationChange(departureStation, destinationStation):
134
  gr.update(value=""),
135
  gr.HTML(HTML_COMPONENTS.NO_PROMPT.value),
136
  gr.update(value=""),
137
- gr.update(value=plotMap(AStarStationsInformation)),
138
  )
139
 
140
 
@@ -210,8 +217,6 @@ def getStationsByCityName(city: str):
210
  def getStationsInformation(stations: list[str]):
211
  data = pd.read_csv("../data/sncf/gares_info.csv", sep=",")
212
  data = data[data["Nom de la gare"].isin(stations)]
213
- print(stations)
214
- print(data)
215
  return dict(
216
  stations=data["Nom de la gare"].to_list(),
217
  lat=data["Latitude"].to_list(),
@@ -292,6 +297,7 @@ def render_tabs(sentences: list[str], model: str, progress_bar: gr.Progress):
292
 
293
  dijkstraPathValues = []
294
  AStarPathValues = []
 
295
  timeDijkstraValue = HTML_COMPONENTS.NO_PROMPT.value
296
  timeAStarValue = HTML_COMPONENTS.NO_PROMPT.value
297
 
@@ -327,16 +333,18 @@ def render_tabs(sentences: list[str], model: str, progress_bar: gr.Progress):
327
  label="Gare de départ",
328
  choices=departureStations["stations"],
329
  value=departureStationValue,
 
330
  )
331
  arrivalStation = gr.Dropdown(
332
  label="Gare d'arrivée",
333
  choices=arrivalStations["stations"],
334
  value=arrivalStationValue,
 
335
  )
336
 
337
  plt = plotMap(AStarStationsInformation)
338
 
339
- map = gr.Plot(plt)
340
 
341
  with gr.Tab("Dijkstra"):
342
  timeDijkstra = gr.HTML(value=timeDijkstraValue)
 
86
  return "\n".join([f"{i + 1}. {elem}" for i, elem in enumerate(path)])
87
 
88
 
89
+ def plotMap(stationsInformation: dict = None):
90
+ stationNames = stationsInformation["stations"] if stationsInformation else []
91
+ stationsLat = stationsInformation["lat"] if stationsInformation else []
92
+ stationsLon = stationsInformation["lon"] if stationsInformation else []
93
 
94
  plt = go.Figure(
95
  go.Scattermapbox(
 
101
  )
102
  )
103
 
104
+ # France's default coordinates
105
+ defaultLat = 46.227638
106
+ defaultLon = 2.213749
107
+
108
+ centerLat = stationsLat[0] if stationsLat else defaultLat
109
+ centerLon = stationsLon[0] if stationsLon else defaultLon
110
+
111
  plt.update_layout(
112
  mapbox_style="open-street-map",
113
  mapbox=dict(
114
+ center=go.layout.mapbox.Center(lat=centerLat, lon=centerLon),
115
  pitch=0,
116
  zoom=3,
117
  ),
 
141
  gr.update(value=""),
142
  gr.HTML(HTML_COMPONENTS.NO_PROMPT.value),
143
  gr.update(value=""),
144
+ gr.update(visible=None),
145
  )
146
 
147
 
 
217
  def getStationsInformation(stations: list[str]):
218
  data = pd.read_csv("../data/sncf/gares_info.csv", sep=",")
219
  data = data[data["Nom de la gare"].isin(stations)]
 
 
220
  return dict(
221
  stations=data["Nom de la gare"].to_list(),
222
  lat=data["Latitude"].to_list(),
 
297
 
298
  dijkstraPathValues = []
299
  AStarPathValues = []
300
+ AStarStationsInformation = None
301
  timeDijkstraValue = HTML_COMPONENTS.NO_PROMPT.value
302
  timeAStarValue = HTML_COMPONENTS.NO_PROMPT.value
303
 
 
333
  label="Gare de départ",
334
  choices=departureStations["stations"],
335
  value=departureStationValue,
336
+ allow_custom_value=True,
337
  )
338
  arrivalStation = gr.Dropdown(
339
  label="Gare d'arrivée",
340
  choices=arrivalStations["stations"],
341
  value=arrivalStationValue,
342
+ allow_custom_value=True,
343
  )
344
 
345
  plt = plotMap(AStarStationsInformation)
346
 
347
+ map = gr.Plot(plt, min_width=300)
348
 
349
  with gr.Tab("Dijkstra"):
350
  timeDijkstra = gr.HTML(value=timeDijkstraValue)