Spaces:
Running on Zero
Running on Zero
probe API endpoint
Browse files
app.py
CHANGED
|
@@ -204,6 +204,15 @@ def analyze(ids: list[int], idx: str, names: list[str], k: int, ctrls: list[str]
|
|
| 204 |
return render_results(tok, ids, t, rows)
|
| 205 |
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
def do_refresh():
|
| 208 |
msg = refresh_registry()
|
| 209 |
return gr.update(choices=oracle_choices()), msg
|
|
@@ -250,6 +259,7 @@ with gr.Blocks(css=CSS, js=CLICK_JS, title="Future Oracle explorer") as demo:
|
|
| 250 |
click_idx.input(analyze, [ids_state, click_idx, oracles_dd, k_in, ctrl_in, layer8_in], [results])
|
| 251 |
refresh_btn.click(do_refresh, [], [oracles_dd, status])
|
| 252 |
demo.load(tokenize, [text_in], [tokens_out, ids_state, results])
|
|
|
|
| 253 |
|
| 254 |
demo.queue(default_concurrency_limit=2)
|
| 255 |
if __name__ == "__main__":
|
|
|
|
| 204 |
return render_results(tok, ids, t, rows)
|
| 205 |
|
| 206 |
|
| 207 |
+
@spaces.GPU(duration=120)
|
| 208 |
+
def probe(text: str, token_index: int, oracles: list[str] | None = None, k: int = 5,
|
| 209 |
+
controls: list[str] | None = None, layer_for_multilayer: int = 24) -> str:
|
| 210 |
+
"""API: tokenize `text`, read the future at `token_index` with the given oracles (default: all
|
| 211 |
+
single-layer oracles). Returns the results HTML."""
|
| 212 |
+
_, ids, _ = tokenize(text)
|
| 213 |
+
return analyze(ids, str(int(token_index)), oracles or default_choices(), int(k), controls or [], int(layer_for_multilayer))
|
| 214 |
+
|
| 215 |
+
|
| 216 |
def do_refresh():
|
| 217 |
msg = refresh_registry()
|
| 218 |
return gr.update(choices=oracle_choices()), msg
|
|
|
|
| 259 |
click_idx.input(analyze, [ids_state, click_idx, oracles_dd, k_in, ctrl_in, layer8_in], [results])
|
| 260 |
refresh_btn.click(do_refresh, [], [oracles_dd, status])
|
| 261 |
demo.load(tokenize, [text_in], [tokens_out, ids_state, results])
|
| 262 |
+
gr.api(probe, api_name="probe")
|
| 263 |
|
| 264 |
demo.queue(default_concurrency_limit=2)
|
| 265 |
if __name__ == "__main__":
|