MetaLATTE-demo / app.py
yinuozhang's picture
Update app.py
4831657 verified
raw
history blame
1.26 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModel, AutoConfig
metalatte_path = './Chatterjeelab/MetaLATTE'
sys.path.insert(0, metalatte_path)
from metalatte import MetaLATTEConfig, MetaLATTEModel
AutoConfig.register("metalatte", MetaLATTEConfig)
AutoModel.register(MetaLATTEConfig, MetaLATTEModel)
tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t33_650M_UR50D")
config = AutoConfig.from_pretrained("ChatterjeeLab/MetaLATTE")
model = AutoModel.from_pretrained("ChatterjeeLab/MetaLATTE", config=config)
def predict(sequence):
inputs = tokenizer(sequence, return_tensors="pt")
raw_probs, predictions = model(**inputs)
id2label = config.id2label
results = {}
for i, pred in enumerate(predictions[0]):
metal = id2label[i]
probability = raw_probs[0][i].item()
results[metal] = '✓' if pred == 1 else ''
df = pd.DataFrame([results])
return df
iface = gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=3, placeholder="Enter protein sequence here..."),
outputs=gr.Dataframe(headers=list(config.id2label.values())),
title="MetaLATTE: Metal Binding Prediction",
description="Enter a protein sequence to predict its metal binding properties."
)
iface.launch()