Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ TOKEN = os.getenv("HF_TOKEN")
|
|
13 |
login(TOKEN)
|
14 |
|
15 |
# This will download the model weights and instantiate the model on your machine.
|
16 |
-
model: ESM3InferenceClient = ESM3.from_pretrained("esm3_sm_open_v1").to("
|
17 |
|
18 |
def read_mol(molpath):
|
19 |
with open(molpath, "r") as fp:
|
@@ -75,30 +75,38 @@ def molecule(input_pdb):
|
|
75 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
76 |
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
77 |
|
78 |
-
def prediction(prompt, temperature):
|
79 |
protein = ESMProtein(sequence=prompt)
|
80 |
protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8, temperature=temperature))
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
94 |
-
seq, sequence, html, html1, pdb, pdb1 = prediction(prompt, temperature)
|
95 |
-
return seq, sequence, html, html1, pdb, pdb1
|
96 |
-
|
97 |
-
demo = gr.Interface(fn = return_stuff, inputs = [gr.Textbox(label="Masked protein sequence", info="Use '_' as masking character", value="___________________________________________________DQATSLRILNNGHAFNVEFDDSQDKAVLKGGPLDGTYRLIQFHFHWGSLDGQGSEHTVDKKKYAAELHLVHWNTKYGDFGKAVQQPDGLAVLGIFLKVGSAKPGLQKVVDVLDSIKTKGKSADFTNFDPRGLLPESLDYWTYPGSLTTPP___________________________________________________________"), gr.Slider(0,1,label="Temperature")], outputs = [gr.Textbox(label="Originally predicted sequence"),gr.Textbox(label="Inverse folding predicted sequence"),gr.HTML(label="Predicted 3D structure"),gr.HTML(label="Inverse-folding predicted 3D structure"), Molecule3D(label="Predicted molecular structure"), Molecule3D(label="Inverse-folding predicted molecular structure")], title="""<h1 align='center'>Proteins with ESM</h1>
|
98 |
<h2 align='center'>Predict the whole sequence and 3D structure of masked protein sequences!</h2>
|
99 |
<h3 align='center'>Support this space with a ⭐ on <a href='https://github.com/AstraBert/proteins-w-esm'>GitHub</a></h3>
|
100 |
-
<h3 align='center'>Support Evolutionary Scale's ESM with a ⭐ on <a href='https://github.com/evolutionaryscale/esm'>GitHub</a></h3>""", examples = [["___________________________________________________DQATSLRILNNGHAFNVEFDDSQDKAVLKGGPLDGTYRLIQFHFHWGSLDGQGSEHTVDKKKYAAELHLVHWNTKYGDFGKAVQQPDGLAVLGIFLKVGSAKPGLQKVVDVLDSIKTKGKSADFTNFDPRGLLPESLDYWTYPGSLTTPP___________________________________________________________", 0.7], ["__________________________________________________________AGQEEYSAMRDQYMRTGEGFLCVFAINNTKSFEDIHQYREQIKRVKDSDDVPMVLVGNKCDLAARTVESRQAQDLARSYGIPYIETSAKTRQGVEDAFYTLVRE___________________________", 0.2], ["__________KTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLH________", 0.5]], cache_examples=False)
|
101 |
-
|
102 |
|
103 |
-
|
104 |
-
demo.launch()
|
|
|
13 |
login(TOKEN)
|
14 |
|
15 |
# This will download the model weights and instantiate the model on your machine.
|
16 |
+
model: ESM3InferenceClient = ESM3.from_pretrained("esm3_sm_open_v1").to("cuda")
|
17 |
|
18 |
def read_mol(molpath):
|
19 |
with open(molpath, "r") as fp:
|
|
|
75 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
76 |
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
77 |
|
78 |
+
def prediction(prompt, temperature, do_structure, enable_roundtrip):
|
79 |
protein = ESMProtein(sequence=prompt)
|
80 |
protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8, temperature=temperature))
|
81 |
+
if do_structure == "Yes":
|
82 |
+
protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8))
|
83 |
+
protein.to_pdb("./generation.pdb")
|
84 |
+
html = molecule("./generation.pdb")
|
85 |
+
if enable_roundtrip == "Yes":
|
86 |
+
seq = protein.sequence
|
87 |
+
protein.sequence = None
|
88 |
+
protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8))
|
89 |
+
protein.coordinates = None
|
90 |
+
protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8))
|
91 |
+
protein.to_pdb("./round_tripped.pdb")
|
92 |
+
html1 = molecule("./round_tripped.pdb")
|
93 |
+
return seq, protein.sequence, html, html1, "./generation.pdb", "./round_tripped.pdb"
|
94 |
+
else:
|
95 |
+
html1 = "<h3>Inverse folding and re-generation not enabled</h3>"
|
96 |
+
f = open("./round_tripped.pdb", "w")
|
97 |
+
f.write("\n")
|
98 |
+
f.close()
|
99 |
+
return protein.sequence, "Inverse folding and re-generation not enabled", html, html1, "./generation.pdb", "./round_tripped.pdb"
|
100 |
+
else:
|
101 |
+
f = open("./empty.pdb", "w")
|
102 |
+
f.write("\n")
|
103 |
+
f.close()
|
104 |
+
return protein.sequence, "Inverse folding and re-generation not enabled", "<h3>Structure reconstruction not enabled</h3>", "<h3>Inverse folding and re-generation not enabled</h3>", "./empty.pdb", "./empty.pdb"
|
105 |
+
|
106 |
|
107 |
+
demo = gr.Interface(fn = prediction, inputs = [gr.Textbox(label="Masked protein sequence", info="Use '_' as masking character", value="___________________________________________________DQATSLRILNNGHAFNVEFDDSQDKAVLKGGPLDGTYRLIQFHFHWGSLDGQGSEHTVDKKKYAAELHLVHWNTKYGDFGKAVQQPDGLAVLGIFLKVGSAKPGLQKVVDVLDSIKTKGKSADFTNFDPRGLLPESLDYWTYPGSLTTPP___________________________________________________________"), gr.Slider(0,1,label="Temperature"), gr.Radio(["Yes", "No"], label="Reconstruct structure", info="Choose wheter to reconstruct structure or not"), gr.Radio(["Yes", "No"], label="Allow inverse-folding", info="Choose wether to allow double check of prediction with inverse folding (ONLY when 'Reconstruct structure' is set to 'Yes')")], outputs = [gr.Textbox(label="Originally predicted sequence"),gr.Textbox(label="Inverse folding predicted sequence"),gr.HTML(label="Predicted 3D structure"),gr.HTML(label="Inverse-folding predicted 3D structure"), Molecule3D(label="Predicted molecular structure"), Molecule3D(label="Inverse-folding predicted molecular structure")], title="""<h1 align='center'>Proteins with ESM</h1>
|
|
|
|
|
|
|
|
|
108 |
<h2 align='center'>Predict the whole sequence and 3D structure of masked protein sequences!</h2>
|
109 |
<h3 align='center'>Support this space with a ⭐ on <a href='https://github.com/AstraBert/proteins-w-esm'>GitHub</a></h3>
|
110 |
+
<h3 align='center'>Support Evolutionary Scale's ESM with a ⭐ on <a href='https://github.com/evolutionaryscale/esm'>GitHub</a></h3>""", examples = [["___________________________________________________DQATSLRILNNGHAFNVEFDDSQDKAVLKGGPLDGTYRLIQFHFHWGSLDGQGSEHTVDKKKYAAELHLVHWNTKYGDFGKAVQQPDGLAVLGIFLKVGSAKPGLQKVVDVLDSIKTKGKSADFTNFDPRGLLPESLDYWTYPGSLTTPP___________________________________________________________", 0.7, "No", "No"], ["__________________________________________________________AGQEEYSAMRDQYMRTGEGFLCVFAINNTKSFEDIHQYREQIKRVKDSDDVPMVLVGNKCDLAARTVESRQAQDLARSYGIPYIETSAKTRQGVEDAFYTLVRE___________________________", 0.2, "Yes", "No"], ["__________KTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLH________", 0.5, "Yes", "Yes"]], cache_examples=False)
|
|
|
111 |
|
112 |
+
demo.launch()
|
|