Molbap HF Staff commited on
Commit
2c2f9f8
·
verified ·
1 Parent(s): 3eea8d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -125,16 +125,33 @@ with gr.Blocks(css=CUSTOM_CSS) as demo:
125
  [repo_in, thresh, multi_cb],
126
  [graph_html_out, graph_json_out],
127
  )
 
128
 
129
- def _select_tab_on_load(req: gr.Request):
130
- qp = req.query_params or {}
131
- key = (qp.get("tab") or "").lower()
132
- idx = TAB_INDEX.get(key)
133
- if idx is not None:
134
- return gr.Tabs.update(selected=idx)
135
- return gr.Tabs.update()
136
-
137
- demo.load(_select_tab_on_load, outputs=[tabs])
138
-
139
- if __name__ == "__main__":
140
- demo.launch(allowed_paths=["static"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  [repo_in, thresh, multi_cb],
126
  [graph_html_out, graph_json_out],
127
  )
128
+ embed_html = gr.HTML(visible=False)
129
 
130
+ def _on_load(req: gr.Request):
131
+ qp = req.query_params or {}
132
+ tab_key = (qp.get("tab") or "").lower()
133
+ embed = (qp.get("embed") == "1")
134
+
135
+ tab_sel = TAB_INDEX.get(tab_key, 0)
136
+
137
+ if embed:
138
+ if tab_key == "graph":
139
+ html, _ = run_graph(HF_MAIN_REPO, 0.7, False, "jaccard")
140
+ elif tab_key == "timeline":
141
+ html, _ = run_timeline(HF_MAIN_REPO, 0.7, False, "jaccard")
142
+ else: # "loc" or anything else
143
+ html = run_loc("jaccard", False)
144
+
145
+ return (
146
+ gr.update(visible=False), # header
147
+ gr.update(visible=False), # tabs
148
+ gr.update(value=html, visible=True), # embed_html
149
+ )
150
+
151
+ return (
152
+ gr.update(visible=True), # header
153
+ gr.update(visible=True, selected=tab_sel), # tabs
154
+ gr.update(visible=False), # embed_html
155
+ )
156
+
157
+ demo.load(_on_load, outputs=[header, tabs, embed_html])