Spaces:
Runtime error
Runtime error
Link Chemiscope load param to dataset json
Browse files
app.py
CHANGED
|
@@ -319,16 +319,26 @@ def _build_chemiscope_embed(dataset_payload: dict, dataset_path: str | Path) ->
|
|
| 319 |
viewer_path = dataset_file.parent / viewer_name
|
| 320 |
viewer_path.write_text(combined, encoding="utf-8")
|
| 321 |
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
return (
|
| 324 |
"<div style='width:100%;'>"
|
| 325 |
"<iframe "
|
| 326 |
"title='Chemiscope explorer' "
|
| 327 |
"style='width:100%;height:620px;border:none;border-radius:8px;' "
|
| 328 |
-
f"src='
|
| 329 |
"<p style='font-size:0.9em;margin-top:0.5rem;'>"
|
| 330 |
"Open in a new tab if the viewer looks blank: "
|
| 331 |
-
f"<a href='
|
| 332 |
"</p>"
|
| 333 |
"</div>"
|
| 334 |
)
|
|
|
|
| 319 |
viewer_path = dataset_file.parent / viewer_name
|
| 320 |
viewer_path.write_text(combined, encoding="utf-8")
|
| 321 |
|
| 322 |
+
space_origin = _infer_space_origin()
|
| 323 |
+
if space_origin:
|
| 324 |
+
dataset_url = f"{space_origin}/file={dataset_file.as_posix()}"
|
| 325 |
+
load_param = urllib.parse.quote(dataset_url, safe=":/?=&%")
|
| 326 |
+
iframe_src = f"https://chemiscope.org/?load={load_param}"
|
| 327 |
+
link = iframe_src
|
| 328 |
+
else:
|
| 329 |
+
encoded = base64.b64encode(combined.encode("utf-8")).decode("ascii")
|
| 330 |
+
iframe_src = f"data:text/html;base64,{encoded}"
|
| 331 |
+
link = iframe_src
|
| 332 |
+
|
| 333 |
return (
|
| 334 |
"<div style='width:100%;'>"
|
| 335 |
"<iframe "
|
| 336 |
"title='Chemiscope explorer' "
|
| 337 |
"style='width:100%;height:620px;border:none;border-radius:8px;' "
|
| 338 |
+
f"src='{iframe_src}'></iframe>"
|
| 339 |
"<p style='font-size:0.9em;margin-top:0.5rem;'>"
|
| 340 |
"Open in a new tab if the viewer looks blank: "
|
| 341 |
+
f"<a href='{link}' target='_blank' rel='noopener'>Chemiscope standalone</a>"
|
| 342 |
"</p>"
|
| 343 |
"</div>"
|
| 344 |
)
|