| import gradio as gr |
| import torch |
| from transformers import EsmForProteinFolding, EsmTokenizer |
| import py3Dmol |
|
|
| |
| model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1") |
| tokenizer = EsmTokenizer.from_pretrained("facebook/esmfold_v1") |
|
|
| def predict_structure(sequence): |
| |
| inputs = tokenizer(sequence, return_tensors="pt", add_special_tokens=False) |
| |
| |
| with torch.no_grad(): |
| output = model(**inputs) |
| |
| |
| pdb_str = output["pdb"] |
|
|
| |
| viewer = py3Dmol.view(width=400, height=400) |
| viewer.addModel(pdb_str, "pdb") |
| viewer.setStyle({"cartoon": {"color": "spectrum"}}) |
| viewer.zoomTo() |
| |
| return viewer.show(), pdb_str |
|
|
| |
| iface = gr.Interface( |
| fn=predict_structure, |
| inputs=gr.Textbox(label="Enter Amino Acid Sequence", placeholder="MKTAYIAKQRQISFVK..."), |
| outputs=[ |
| gr.HTML(label="3D Structure"), |
| gr.Textbox(label="PDB Output") |
| ], |
| title="Protein Structure Prediction", |
| description="Enter a protein sequence to predict its 3D structure using ESMFold." |
| ) |
|
|
| iface.launch() |
|
|