Molbap HF Staff commited on
Commit
4b63c32
·
verified ·
1 Parent(s): 624b0a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -77
app.py CHANGED
@@ -72,82 +72,12 @@ CUSTOM_CSS = """
72
 
73
  TAB_INDEX = {"timeline": 0, "loc": 1, "graph": 2}
74
 
75
- with gr.Blocks(css=CUSTOM_CSS) as demo:
76
- header = gr.Markdown("## 🔍 Modular-candidate explorer for 🤗 Transformers")
77
-
78
- with gr.Tabs() as tabs:
79
- with gr.Tab("Chronological Timeline", id="timeline"):
80
- with gr.Row():
81
- timeline_repo_in = gr.Text(value=HF_MAIN_REPO, label="Repo / fork URL")
82
- timeline_thresh = gr.Slider(0.50, 0.95, value=0.5, step=0.01, label="Similarity ≥")
83
- timeline_multi_cb = gr.Checkbox(label="Only multimodal models")
84
- gr.Markdown("**Embedding method:** TBD")
85
- timeline_btn = gr.Button("Build timeline")
86
-
87
- timeline_html_out = gr.HTML(elem_id="timeline_html", show_label=False)
88
- timeline_json_out = gr.File(label="Download timeline.json")
89
-
90
- timeline_btn.click(
91
- lambda repo, thresh, multi: run_timeline(repo, thresh, multi, "jaccard"),
92
- [timeline_repo_in, timeline_thresh, timeline_multi_cb],
93
- [timeline_html_out, timeline_json_out],
94
- )
95
-
96
- with gr.Tab("LOC Growth", id="loc"):
97
- sim_radio2 = gr.Radio(["jaccard","embedding"], value="jaccard", label="Similarity metric")
98
- multi_cb2 = gr.Checkbox(label="Only multimodal models")
99
- go_loc = gr.Button("Show LOC growth")
100
- loc_html = gr.HTML(show_label=False)
101
- go_loc.click(run_loc, [sim_radio2, multi_cb2], loc_html)
102
-
103
- with gr.Tab("Dependency Graph", id="graph"):
104
- with gr.Row():
105
- repo_in = gr.Text(value=HF_MAIN_REPO, label="Repo / fork URL")
106
- thresh = gr.Slider(0.50, 0.95, value=0.5, step=0.01, label="Similarity ≥")
107
- multi_cb = gr.Checkbox(label="Only multimodal models")
108
- gr.Markdown("**Embedding method:** TBD")
109
- go_btn = gr.Button("Build graph")
110
-
111
- graph_html_out = gr.HTML(elem_id="graph_html", show_label=False)
112
- graph_json_out = gr.File(label="Download graph.json")
113
-
114
- go_btn.click(
115
- lambda repo, thresh, multi: run_graph(repo, thresh, multi, "jaccard"),
116
- [repo_in, thresh, multi_cb],
117
- [graph_html_out, graph_json_out],
118
- )
119
-
120
- # make embed_html a sibling of Tabs (not a child), so we can hide Tabs but show this
121
- embed_html = gr.HTML(visible=False)
122
-
123
- def _on_load(req: gr.Request):
124
- qp = req.query_params or {}
125
- tab_key = (qp.get("tab") or "").lower()
126
- embed = (qp.get("embed") == "1")
127
- tab_sel = TAB_INDEX.get(tab_key, 0)
128
-
129
- if embed:
130
- # shorter iframe inside article view
131
- if tab_key == "graph":
132
- html, _ = run_graph(HF_MAIN_REPO, 0.7, False, "jaccard", height_vh=60)
133
- elif tab_key == "timeline":
134
- html, _ = run_timeline(HF_MAIN_REPO, 0.7, False, "jaccard", height_vh=60)
135
- else:
136
- html = run_loc("jaccard", False, height_vh=60)
137
-
138
- return (
139
- gr.update(visible=False), # header
140
- gr.update(visible=False), # tabs
141
- gr.update(value=html, visible=True), # embed_html
142
- )
143
-
144
- return (
145
- gr.update(visible=True),
146
- gr.update(visible=True, selected=tab_sel),
147
- gr.update(visible=False),
148
- )
149
-
150
- demo.load(_on_load, outputs=[header, tabs, embed_html])
151
 
152
  if __name__ == "__main__":
153
- demo.launch(allowed_paths=["static"])
 
72
 
73
  TAB_INDEX = {"timeline": 0, "loc": 1, "graph": 2}
74
 
75
+ with gr.Blocks() as demo:
76
+ html = gr.HTML()
77
+ def _load():
78
+ timeline_html, _ = run_timeline(HF_MAIN_REPO, threshold=0.7, multimodal=False, sim_method="jaccard")
79
+ return timeline_html
80
+ demo.load(_load, outputs=[html])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  if __name__ == "__main__":
83
+ demo.launch()