from huggingface_hub import login from esm.models.esm3 import ESM3 from esm.sdk.api import ESM3InferenceClient, ESMProtein, GenerationConfig import spaces import os import gradio as gr from gradio_molecule3d import Molecule3D # This will prompt you to get an API key from huggingface hub, make one with # "Read" or "Write" permission and copy it back here. TOKEN = os.getenv("HF_TOKEN") login(TOKEN) # This will download the model weights and instantiate the model on your machine. model: ESM3InferenceClient = ESM3.from_pretrained("esm3_sm_open_v1").to("cuda") def read_mol(molpath): with open(molpath, "r") as fp: lines = fp.readlines() mol = "" for l in lines: mol += l return mol def molecule(input_pdb): mol = read_mol(input_pdb) x = ( """
""" ) return f"""""" @spaces.GPU(duration=300) def prediction(prompt, temperature): protein = ESMProtein(sequence=prompt) protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8, temperature=temperature)) seq = protein.sequence protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8)) protein.to_pdb("./generation.pdb") protein.sequence = None protein = model.generate(protein, GenerationConfig(track="sequence", num_steps=8)) protein.coordinates = None protein = model.generate(protein, GenerationConfig(track="structure", num_steps=8)) protein.to_pdb("./round_tripped.pdb") html1 = molecule("./round_tripped.pdb") html = molecule("./generation.pdb") return seq, protein.sequence, html, html1, "./generation.pdb", "./round_tripped.pdb" 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")], 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="""