Jonathandav commited on
Commit
a6af21c
·
verified ·
1 Parent(s): 814a198

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -666,10 +666,16 @@ def build_catalogue() -> str:
666
  """
667
  try:
668
  s = load_index()
669
- except Exception:
670
- return "<p>Catalogue unavailable — index not loaded.</p>"
671
-
672
- styles = s["styles"]
 
 
 
 
 
 
673
  first = {}
674
  for pid, sid in zip(s["plate_ids"], s["style_of"]):
675
  first.setdefault(sid, pid)
@@ -945,6 +951,8 @@ with gr.Blocks(css=CSS, title="Facade — architectural style finder",
945
  with gr.Column(scale=7):
946
  out = gr.HTML(EMPTY_HTML)
947
 
 
 
948
  catalogue = gr.HTML()
949
 
950
  def do_geocode(q):
@@ -973,6 +981,10 @@ with gr.Blocks(css=CSS, title="Facade — architectural style finder",
973
  )
974
 
975
  go.click(identify, [img, use_loc, lat, lon, weight, live_text], out)
 
 
 
 
976
  demo.load(build_catalogue, None, catalogue)
977
 
978
  if __name__ == "__main__":
 
666
  """
667
  try:
668
  s = load_index()
669
+ styles = s["styles"]
670
+ except Exception as exc:
671
+ import traceback
672
+ # Swallowing this silently rendered an invisible panel and looked like
673
+ # the section had simply not been built.
674
+ return (f"<div style='color:#E0574B;font-family:monospace;font-size:.75rem;"
675
+ f"border:1px solid #E0574B;padding:12px;margin-top:24px'>"
676
+ f"Catalogue unavailable: {_esc(type(exc).__name__)}: {_esc(exc)}"
677
+ f"<pre style='color:#8FB6D0;white-space:pre-wrap'>"
678
+ f"{_esc(traceback.format_exc()[-800:])}</pre></div>")
679
  first = {}
680
  for pid, sid in zip(s["plate_ids"], s["style_of"]):
681
  first.setdefault(sid, pid)
 
951
  with gr.Column(scale=7):
952
  out = gr.HTML(EMPTY_HTML)
953
 
954
+ with gr.Row():
955
+ show_cat = gr.Button("Show the 20 styles this can identify", size="sm")
956
  catalogue = gr.HTML()
957
 
958
  def do_geocode(q):
 
981
  )
982
 
983
  go.click(identify, [img, use_loc, lat, lon, weight, live_text], out)
984
+
985
+ # Rendered on load, with a manual trigger as a fallback: the load event is
986
+ # the one piece of this page that fails invisibly if it does not fire.
987
+ show_cat.click(build_catalogue, None, catalogue)
988
  demo.load(build_catalogue, None, catalogue)
989
 
990
  if __name__ == "__main__":