Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, EsmForProteinFolding
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load model (runs once)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
|
| 8 |
+
model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1")
|
| 9 |
+
|
| 10 |
+
def predict_structure(sequence):
|
| 11 |
+
try:
|
| 12 |
+
inputs = tokenizer([sequence], return_tensors="pt", add_special_tokens=False)
|
| 13 |
+
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
|
| 17 |
+
pdb = model.output_to_pdb(outputs)[0]
|
| 18 |
+
|
| 19 |
+
# Save file
|
| 20 |
+
file_path = "output.pdb"
|
| 21 |
+
with open(file_path, "w") as f:
|
| 22 |
+
f.write(pdb)
|
| 23 |
+
|
| 24 |
+
return file_path
|
| 25 |
+
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return str(e)
|
| 28 |
+
|
| 29 |
+
# UI + API
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=predict_structure,
|
| 32 |
+
inputs=gr.Textbox(label="Protein Sequence"),
|
| 33 |
+
outputs=gr.File(label="Download PDB"),
|
| 34 |
+
title="Protein Structure Predictor (ESMFold)"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
iface.launch()
|