Spaces:
Runtime error
Runtime error
Embed interactive 3D orbital viewer directly in app using iframe
Browse files- app.py +25 -15
- force_rebuild.txt +1 -1
app.py
CHANGED
|
@@ -366,23 +366,33 @@ def smiles_to_molecular_orbitals(smiles_input: str, name_input: str) -> str:
|
|
| 366 |
</html>
|
| 367 |
"""
|
| 368 |
|
| 369 |
-
# Save HTML file
|
| 370 |
-
html_filename = f"{label.lower()}
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
html_path.write_text(html_content)
|
|
|
|
| 373 |
|
| 374 |
-
# Create
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
if not html_sections:
|
| 388 |
return "<p>Could not prepare HOMO/LUMO visualizations.</p>"
|
|
|
|
| 366 |
</html>
|
| 367 |
"""
|
| 368 |
|
| 369 |
+
# Save HTML file to a location accessible by Gradio
|
| 370 |
+
html_filename = f"{label.lower()}_orbital_{hash(canonical_smiles)}.html"
|
| 371 |
+
|
| 372 |
+
# Move back to original directory to save in a persistent location
|
| 373 |
+
os.chdir(original_cwd)
|
| 374 |
+
output_dir = Path("orbital_outputs")
|
| 375 |
+
output_dir.mkdir(exist_ok=True)
|
| 376 |
+
html_path = output_dir / html_filename
|
| 377 |
html_path.write_text(html_content)
|
| 378 |
+
os.chdir(tmpdir)
|
| 379 |
|
| 380 |
+
# Create iframe to embed the HTML directly
|
| 381 |
+
iframe_html = f"""
|
| 382 |
+
<div style='margin: 20px 0; padding: 15px; background: white; border: 2px solid #2196F3; border-radius: 8px;'>
|
| 383 |
+
<h3 style='color: #1976D2; margin-top: 0;'>{label} Orbital - Interactive 3D</h3>
|
| 384 |
+
<p style='margin: 10px 0; color: #666;'><small>
|
| 385 |
+
<strong>Blue:</strong> Positive orbital lobe | <strong>Red:</strong> Negative orbital lobe<br>
|
| 386 |
+
<strong>Controls:</strong> Left-click drag to rotate, Scroll to zoom, Right-click drag to pan
|
| 387 |
+
</small></p>
|
| 388 |
+
<iframe srcdoc="{html_content.replace('"', '"')}"
|
| 389 |
+
style="width: 100%; height: 650px; border: 1px solid #ddd; border-radius: 4px;"
|
| 390 |
+
sandbox="allow-scripts allow-same-origin">
|
| 391 |
+
</iframe>
|
| 392 |
+
</div>
|
| 393 |
+
"""
|
| 394 |
+
|
| 395 |
+
html_sections.append(iframe_html)
|
| 396 |
|
| 397 |
if not html_sections:
|
| 398 |
return "<p>Could not prepare HOMO/LUMO visualizations.</p>"
|
force_rebuild.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
# Force rebuild
|
| 2 |
-
2025-11-08
|
|
|
|
| 1 |
# Force rebuild
|
| 2 |
+
2025-11-08 v15
|