Spaces:
Runtime error
Runtime error
as-cle-bert
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from transformers import AutoTokenizer, EsmForProteinFolding
|
2 |
from transformers.models.esm.openfold_utils.protein import to_pdb, Protein as OFProtein
|
3 |
from transformers.models.esm.openfold_utils.feats import atom14_to_atom37
|
|
|
4 |
import gradio as gr
|
5 |
import spaces
|
6 |
from gradio_molecule3d import Molecule3D
|
@@ -129,8 +130,26 @@ def fold_protein(test_protein):
|
|
129 |
html = molecule("output_structure.pdb")
|
130 |
return html, "output_structure.pdb"
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
iface = gr.Interface(
|
133 |
-
title="
|
134 |
fn=fold_protein,
|
135 |
inputs=gr.Textbox(
|
136 |
label="Protein Sequence",
|
@@ -146,4 +165,20 @@ iface = gr.Interface(
|
|
146 |
]
|
147 |
)
|
148 |
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import AutoTokenizer, EsmForProteinFolding
|
2 |
from transformers.models.esm.openfold_utils.protein import to_pdb, Protein as OFProtein
|
3 |
from transformers.models.esm.openfold_utils.feats import atom14_to_atom37
|
4 |
+
from Bio import SeqIO
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
from gradio_molecule3d import Molecule3D
|
|
|
130 |
html = molecule("output_structure.pdb")
|
131 |
return html, "output_structure.pdb"
|
132 |
|
133 |
+
@spaces.GPU(duration=180)
|
134 |
+
def fold_protein_wpdb(test_protein, pdb_path):
|
135 |
+
tokenized_input = tokenizer([test_protein], return_tensors="pt", add_special_tokens=False)['input_ids']
|
136 |
+
tokenized_input = tokenized_input.cuda()
|
137 |
+
with torch.no_grad():
|
138 |
+
output = model(tokenized_input)
|
139 |
+
pdb = convert_outputs_to_pdb(output)
|
140 |
+
with open(pdb_path, "w") as f:
|
141 |
+
f.write("".join(pdb))
|
142 |
+
html = molecule(pdb_path)
|
143 |
+
return html, pdb_path
|
144 |
+
|
145 |
+
def load_protein_sequences(fasta_file):
|
146 |
+
protein_sequences = {}
|
147 |
+
for record in SeqIO.parse(fasta_file, "fasta"):
|
148 |
+
protein_sequences[record.id] = str(record.seq)
|
149 |
+
return protein_sequences
|
150 |
+
|
151 |
iface = gr.Interface(
|
152 |
+
title="Proteinviz",
|
153 |
fn=fold_protein,
|
154 |
inputs=gr.Textbox(
|
155 |
label="Protein Sequence",
|
|
|
165 |
]
|
166 |
)
|
167 |
|
168 |
+
with gr.Blocks() as demo1:
|
169 |
+
input_seqs = gr.File(label="FASTA File", info="FASTA-formatted file with headers starting with '>' and protein sequences")
|
170 |
+
@gr.render(inputs=input_text)
|
171 |
+
def show_split(inputfile):
|
172 |
+
if type(inputfile) == type(None):
|
173 |
+
gr.Markdown("## No Input Provided")
|
174 |
+
else:
|
175 |
+
seqs = load_protein_sequences(inputfile)
|
176 |
+
for header in seqs:
|
177 |
+
pdb_path = f"{seq.replace(" ", "_").replace(",","")}.pdb"
|
178 |
+
html, pdb = fold_protein_wpdb(seqs[seq], pdb_path)
|
179 |
+
gr.HTML(html, label=f"{seq} structural representation")
|
180 |
+
Molecule3D(pdb, label=f"{seq} molecular representation")
|
181 |
+
|
182 |
+
demo = gr.TabbedInterface([iface, demo0], ["Single Protein Structure Prediction", "Bulk Protein Structure Prediction"])
|
183 |
+
|
184 |
+
demo.launch(server_name="0.0.0.0", share=False)
|