as-cle-bert commited on
Commit
0cf7233
·
verified ·
1 Parent(s): 1fa228e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -22
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("cpu")
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
- seq = protein.sequence
82
- protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8))
83
- protein.to_pdb("./generation.pdb")
84
- protein.sequence = None
85
- protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8))
86
- protein.coordinates = None
87
- protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8))
88
- protein.to_pdb("./round_tripped.pdb")
89
- html1 = molecule("./round_tripped.pdb")
90
- html = molecule("./generation.pdb")
91
- return seq, protein.sequence, html, html1, "./generation.pdb", "./round_tripped.pdb"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- def return_stuff(prompt, temperature):
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
- if __name__ == '__main__':
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()