Spaces:
Running on CPU Upgrade

osv5m commited on
Commit
f0b4901
1 Parent(s): 7452215

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -28,7 +28,7 @@ import matplotlib.pyplot as plt
28
 
29
  from gradio_folium import Folium
30
  from geographiclib.geodesic import Geodesic
31
- from folium import Map, Element, LatLngPopup, Marker, Icon, PolyLine, FeatureGroup
32
  from folium.map import LayerControl
33
  from folium.plugins import BeautifyIcon
34
  from huggingface_hub import CommitScheduler
@@ -308,9 +308,7 @@ class Engine(object):
308
 
309
  icon_star = BeautifyIcon(
310
  icon='star',
311
- inner_icon_style='color:red;font-size:30px;',
312
- background_color='transparent',
313
- border_color='transparent',
314
  )
315
  feature_group = FeatureGroup(name='Ground Truth')
316
  Marker(
@@ -323,7 +321,6 @@ class Engine(object):
323
  icon_square = BeautifyIcon(
324
  icon_shape='rectangle-dot',
325
  border_color='green',
326
- border_width=10,
327
  )
328
  feature_group_best = FeatureGroup(name='Best Model')
329
  Marker(
@@ -337,7 +334,6 @@ class Engine(object):
337
  icon_circle = BeautifyIcon(
338
  icon_shape='circle-dot',
339
  border_color='blue',
340
- border_width=10,
341
  )
342
  feature_group_user = FeatureGroup(name='User')
343
  Marker(
@@ -397,7 +393,14 @@ class Engine(object):
397
  self.stats['country'].append(int(self.admins[self.index][3] != 'nan' and country == self.admins[self.index][3]))
398
 
399
  df = pd.DataFrame([self.get_model_average(who) for who in ['user', 'best', 'base']], columns=['who', 'GeoScore', 'Distance', 'Accuracy (country)']).round(2)
400
- result_text = (f"### GeoScore: {score:.0f}, distance: {distance:.0f} km")
 
 
 
 
 
 
 
401
 
402
  self.cache(self.index+1, score, distance, (click_lat, click_lon), time_elapsed)
403
  return self.get_figure(), result_text, df
@@ -407,8 +410,8 @@ class Engine(object):
407
  self.index += 1
408
  return self.load_image()
409
 
410
- def get_model_average(self, which, all=False):
411
- aux, i = [], self.index+1
412
  if which == 'user':
413
  avg_score = sum(self.stats['scores']) / len(self.stats['scores']) if self.stats['scores'] else 0
414
  avg_distance = sum(self.stats['distances']) / len(self.stats['distances']) if self.stats['distances'] else 0
@@ -418,18 +421,21 @@ class Engine(object):
418
  avg_area_accuracy = (0 if self.df['area_val'].iloc[:i].sum() == 0 else sum(self.stats['area'])/self.df['area_val'].iloc[:i].sum())*100
419
  avg_region_accuracy = (0 if self.df['region_val'].iloc[:i].sum() == 0 else sum(self.stats['region'])/self.df['region_val'].iloc[:i].sum())*100
420
  aux = [avg_city_accuracy, avg_area_accuracy, avg_region_accuracy]
 
421
  elif which == 'base':
422
  avg_score = np.mean(self.df[['score_base']].iloc[:i])
423
  avg_distance = np.mean(self.df[['distance_base']].iloc[:i])
424
  avg_country_accuracy = self.df['accuracy_country_base'].iloc[i]
425
  if all:
426
  aux = [self.df['accuracy_city_base'].iloc[i], self.df['accuracy_area_base'].iloc[i], self.df['accuracy_region_base'].iloc[i]]
 
427
  elif which == 'best':
428
  avg_score = np.mean(self.df[['score']].iloc[:i])
429
  avg_distance = np.mean(self.df[['distance']].iloc[:i])
430
  avg_country_accuracy = self.df['accuracy_country'].iloc[i]
431
  if all:
432
  aux = [self.df['accuracy_city_base'].iloc[i], self.df['accuracy_area_base'].iloc[i], self.df['accuracy_region_base'].iloc[i]]
 
433
  return [which, avg_score, avg_distance, avg_country_accuracy] + aux
434
 
435
  def update_average_display(self):
@@ -446,7 +452,7 @@ class Engine(object):
446
  self.stats['area'] = [(int(self.admins[self.index][1] != 'nan' and click['admin2'] == self.admins[self.index][1])) for click in clicks]
447
  self.stats['region'] = [(int(self.admins[self.index][2] != 'nan' and click['admin1'] == self.admins[self.index][2])) for click in clicks]
448
 
449
- df = pd.DataFrame([self.get_model_average(who, True) for who in ['user', 'best', 'base']], columns=['who', 'GeoScore', 'Distance', 'Accuracy (country)', 'Accuracy (city)', 'Accuracy (area)', 'Accuracy (region)'])
450
  return df
451
 
452
  # Function to save the game state
@@ -477,7 +483,8 @@ if __name__ == "__main__":
477
  kargs = {}
478
  if not MPL:
479
  kargs = {'value': empty_map()}
480
- return gr.update(visible=False, **kargs), gr.update(value=image, visible=True), gr.update(value=text, visible=True), gr.update(value=df, visible=True)
 
481
 
482
  def exit_(state):
483
  if state['engine'].index > 0:
@@ -496,7 +503,7 @@ if __name__ == "__main__":
496
  kargs = {}
497
  if not MPL:
498
  kargs = {'value': empty_map()}
499
- return gr.update(value=make_map_(), visible=True), gr.update(visible=False, **kargs), gr.update(value=image), gr.update(value=text), gr.update(visible=False), gr.update(), gr.update(visible=False), gr.update(value="-1"), gr.update(), gr.update(), gr.update()
500
  else:
501
  return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
502
 
@@ -513,7 +520,7 @@ if __name__ == "__main__":
513
  gr.update(value=image, visible=True),
514
  gr.update(value=text, visible=True),
515
  gr.update(visible=True),
516
- gr.update(visible=True),
517
  gr.update(value="<h1>OSV-5M (plonk)</h1>"),
518
  gr.update(visible=False),
519
  gr.update(visible=False),
@@ -547,7 +554,7 @@ if __name__ == "__main__":
547
 
548
  coords = gr.Textbox(value="-1", label="Latitude, Longitude", visible=False, elem_id='coords-tbox')
549
  start_button.click(start, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, rules, state, start_button, coords, select_button])
550
- select_button.click(click, inputs=[state, coords], outputs=[map_, results, text, perf], js=map_js())
551
  next_button.click(next_, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, perf, coords, rules, text_end, select_button])
552
  exit_button.click(exit_, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, perf, coords, rules, text_end, select_button])
553
 
 
28
 
29
  from gradio_folium import Folium
30
  from geographiclib.geodesic import Geodesic
31
+ from folium import Map, Element, LatLngPopup, Marker, PolyLine, FeatureGroup
32
  from folium.map import LayerControl
33
  from folium.plugins import BeautifyIcon
34
  from huggingface_hub import CommitScheduler
 
308
 
309
  icon_star = BeautifyIcon(
310
  icon='star',
311
+ border_color='red',
 
 
312
  )
313
  feature_group = FeatureGroup(name='Ground Truth')
314
  Marker(
 
321
  icon_square = BeautifyIcon(
322
  icon_shape='rectangle-dot',
323
  border_color='green',
 
324
  )
325
  feature_group_best = FeatureGroup(name='Best Model')
326
  Marker(
 
334
  icon_circle = BeautifyIcon(
335
  icon_shape='circle-dot',
336
  border_color='blue',
 
337
  )
338
  feature_group_user = FeatureGroup(name='User')
339
  Marker(
 
393
  self.stats['country'].append(int(self.admins[self.index][3] != 'nan' and country == self.admins[self.index][3]))
394
 
395
  df = pd.DataFrame([self.get_model_average(who) for who in ['user', 'best', 'base']], columns=['who', 'GeoScore', 'Distance', 'Accuracy (country)']).round(2)
396
+ result_text = (
397
+ f"### GeoScore: <span style='color:green'>%s</span>/<span style='color:red'>%s</span>, distance: <span style='color:green'>%s</span>/<span style='color:red'>%s</span> km" % (
398
+ score,
399
+ self.df['score'].iloc[self.index+1],
400
+ distance,
401
+ self.df['distance'].iloc[self.index+1]
402
+ )
403
+ )
404
 
405
  self.cache(self.index+1, score, distance, (click_lat, click_lon), time_elapsed)
406
  return self.get_figure(), result_text, df
 
410
  self.index += 1
411
  return self.load_image()
412
 
413
+ def get_model_average(self, which, all=False, final=False):
414
+ aux, i = [], self.index+int(not final)
415
  if which == 'user':
416
  avg_score = sum(self.stats['scores']) / len(self.stats['scores']) if self.stats['scores'] else 0
417
  avg_distance = sum(self.stats['distances']) / len(self.stats['distances']) if self.stats['distances'] else 0
 
421
  avg_area_accuracy = (0 if self.df['area_val'].iloc[:i].sum() == 0 else sum(self.stats['area'])/self.df['area_val'].iloc[:i].sum())*100
422
  avg_region_accuracy = (0 if self.df['region_val'].iloc[:i].sum() == 0 else sum(self.stats['region'])/self.df['region_val'].iloc[:i].sum())*100
423
  aux = [avg_city_accuracy, avg_area_accuracy, avg_region_accuracy]
424
+ which = 'You'
425
  elif which == 'base':
426
  avg_score = np.mean(self.df[['score_base']].iloc[:i])
427
  avg_distance = np.mean(self.df[['distance_base']].iloc[:i])
428
  avg_country_accuracy = self.df['accuracy_country_base'].iloc[i]
429
  if all:
430
  aux = [self.df['accuracy_city_base'].iloc[i], self.df['accuracy_area_base'].iloc[i], self.df['accuracy_region_base'].iloc[i]]
431
+ which = 'Worst-AI'
432
  elif which == 'best':
433
  avg_score = np.mean(self.df[['score']].iloc[:i])
434
  avg_distance = np.mean(self.df[['distance']].iloc[:i])
435
  avg_country_accuracy = self.df['accuracy_country'].iloc[i]
436
  if all:
437
  aux = [self.df['accuracy_city_base'].iloc[i], self.df['accuracy_area_base'].iloc[i], self.df['accuracy_region_base'].iloc[i]]
438
+ which = 'Best-AI'
439
  return [which, avg_score, avg_distance, avg_country_accuracy] + aux
440
 
441
  def update_average_display(self):
 
452
  self.stats['area'] = [(int(self.admins[self.index][1] != 'nan' and click['admin2'] == self.admins[self.index][1])) for click in clicks]
453
  self.stats['region'] = [(int(self.admins[self.index][2] != 'nan' and click['admin1'] == self.admins[self.index][2])) for click in clicks]
454
 
455
+ df = pd.DataFrame([self.get_model_average(who, True, True) for who in ['user', 'best', 'base']], columns=['who', 'GeoScore', 'Distance', 'Accuracy (country)', 'Accuracy (city)', 'Accuracy (area)', 'Accuracy (region)'])
456
  return df
457
 
458
  # Function to save the game state
 
483
  kargs = {}
484
  if not MPL:
485
  kargs = {'value': empty_map()}
486
+ return gr.update(visible=False, **kargs), gr.update(value=image, visible=True), gr.update(value=text, visible=True), gr.update(value=df, visible=True), gr.update(visible=False), gr.update(visible=True),
487
+
488
 
489
  def exit_(state):
490
  if state['engine'].index > 0:
 
503
  kargs = {}
504
  if not MPL:
505
  kargs = {'value': empty_map()}
506
+ return gr.update(value=make_map_(), visible=True), gr.update(visible=False, **kargs), gr.update(value=image), gr.update(value=text, visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(value="-1"), gr.update(), gr.update(), gr.update(visible=True)
507
  else:
508
  return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
509
 
 
520
  gr.update(value=image, visible=True),
521
  gr.update(value=text, visible=True),
522
  gr.update(visible=True),
523
+ gr.update(visible=False),
524
  gr.update(value="<h1>OSV-5M (plonk)</h1>"),
525
  gr.update(visible=False),
526
  gr.update(visible=False),
 
554
 
555
  coords = gr.Textbox(value="-1", label="Latitude, Longitude", visible=False, elem_id='coords-tbox')
556
  start_button.click(start, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, rules, state, start_button, coords, select_button])
557
+ select_button.click(click, inputs=[state, coords], outputs=[map_, results, text, perf, select_button, next_button], js=map_js())
558
  next_button.click(next_, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, perf, coords, rules, text_end, select_button])
559
  exit_button.click(exit_, inputs=[state], outputs=[map_, results, image_, text_count, text, next_button, perf, coords, rules, text_end, select_button])
560