Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,25 @@ from rdkit.Chem import Draw
|
|
4 |
from rdkit import Chem
|
5 |
import selfies as sf
|
6 |
|
|
|
7 |
def greet1(name):
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
18 |
smis = [sf.decoder(i) for i in sf_output]
|
19 |
|
20 |
mols = []
|
@@ -31,9 +39,6 @@ def greet2(name):
|
|
31 |
|
32 |
return img
|
33 |
|
34 |
-
def greet3(name):
|
35 |
-
|
36 |
-
return name+"11"
|
37 |
|
38 |
|
39 |
|
|
|
4 |
from rdkit import Chem
|
5 |
import selfies as sf
|
6 |
|
7 |
+
sf_input
|
8 |
def greet1(name):
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen")
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/MolGen")
|
11 |
|
12 |
+
sf_input = tokenizer(name, return_tensors="pt")
|
13 |
+
|
14 |
+
# beam search
|
15 |
+
molecules = model.generate(input_ids=sf_input["input_ids"],
|
16 |
+
attention_mask=sf_input["attention_mask"],
|
17 |
+
max_length=15,
|
18 |
+
min_length=5,
|
19 |
+
num_return_sequences=5,
|
20 |
+
num_beams=5)
|
21 |
+
|
22 |
+
sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
|
23 |
+
return sf_output
|
24 |
|
25 |
+
def greet2(name):
|
26 |
smis = [sf.decoder(i) for i in sf_output]
|
27 |
|
28 |
mols = []
|
|
|
39 |
|
40 |
return img
|
41 |
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
|