Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1")
|
|
| 10 |
|
| 11 |
def generate_structure(sequence, style):
|
| 12 |
try:
|
| 13 |
-
# 🔬 Generate structure
|
| 14 |
inputs = tokenizer([sequence], return_tensors="pt", add_special_tokens=False)
|
| 15 |
|
| 16 |
with torch.no_grad():
|
|
@@ -18,12 +17,12 @@ def generate_structure(sequence, style):
|
|
| 18 |
|
| 19 |
pdb = model.output_to_pdb(outputs)[0]
|
| 20 |
|
| 21 |
-
#
|
| 22 |
file_path = "output.pdb"
|
| 23 |
with open(file_path, "w") as f:
|
| 24 |
f.write(pdb)
|
| 25 |
|
| 26 |
-
#
|
| 27 |
view = py3Dmol.view(width=800, height=500)
|
| 28 |
view.addModel(pdb, "pdb")
|
| 29 |
|
|
@@ -35,9 +34,15 @@ def generate_structure(sequence, style):
|
|
| 35 |
view.setStyle({"sphere": {}})
|
| 36 |
|
| 37 |
view.zoomTo()
|
|
|
|
|
|
|
| 38 |
html = view._make_html()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
# 📄 Preview (first 20 lines)
|
| 41 |
preview = "\n".join(pdb.split("\n")[:20])
|
| 42 |
|
| 43 |
return file_path, html, preview
|
|
|
|
| 10 |
|
| 11 |
def generate_structure(sequence, style):
|
| 12 |
try:
|
|
|
|
| 13 |
inputs = tokenizer([sequence], return_tensors="pt", add_special_tokens=False)
|
| 14 |
|
| 15 |
with torch.no_grad():
|
|
|
|
| 17 |
|
| 18 |
pdb = model.output_to_pdb(outputs)[0]
|
| 19 |
|
| 20 |
+
# Save file
|
| 21 |
file_path = "output.pdb"
|
| 22 |
with open(file_path, "w") as f:
|
| 23 |
f.write(pdb)
|
| 24 |
|
| 25 |
+
# 🔥 SAFE visualization
|
| 26 |
view = py3Dmol.view(width=800, height=500)
|
| 27 |
view.addModel(pdb, "pdb")
|
| 28 |
|
|
|
|
| 34 |
view.setStyle({"sphere": {}})
|
| 35 |
|
| 36 |
view.zoomTo()
|
| 37 |
+
|
| 38 |
+
# ✅ safer HTML export
|
| 39 |
html = view._make_html()
|
| 40 |
+
html = f"""
|
| 41 |
+
<div style="width:100%; height:500px;">
|
| 42 |
+
{html}
|
| 43 |
+
</div>
|
| 44 |
+
"""
|
| 45 |
|
|
|
|
| 46 |
preview = "\n".join(pdb.split("\n")[:20])
|
| 47 |
|
| 48 |
return file_path, html, preview
|