|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
def greet(name): |
|
|
|
tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen") |
|
model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/MolGen") |
|
|
|
sf_input = tokenizer(name, return_tensors="pt") |
|
|
|
|
|
molecules = model.generate(input_ids=sf_input["input_ids"], |
|
attention_mask=sf_input["attention_mask"], |
|
max_length=15, |
|
min_length=5, |
|
num_return_sequences=5, |
|
num_beams=5) |
|
|
|
sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules] |
|
return sf_output |
|
|
|
|
|
|
|
examples = [ |
|
|
|
['[C][=C][C][=C][C][=C][Ring1][=Branch1]'] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="Molecular Language Model as Multi-task Generator", |
|
examples=examples, ) |
|
iface.launch() |