File size: 1,049 Bytes
5a9a1ef
f1b26cb
5a9a1ef
bf91928
f1b26cb
7b3398a
 
f1b26cb
81c11f2
2b734c6
f1b26cb
2b734c6
9d0f6a3
 
 
 
 
 
2b734c6
 
5a9a1ef
331c1b3
b0151d2
 
 
2c6d721
13b5e43
b0151d2
 
 
 
 
 
059e909
13b5e43
bf91928
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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")
    
    # beam search
    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]'],['[C]']

]





iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="Molecular Language Model as Multi-task Generator",
    examples=examples, )
iface.launch()