Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,20 @@ def greet1(name):
|
|
24 |
return sf_output
|
25 |
|
26 |
def greet2(name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
smis = [sf.decoder(i) for i in sf_output]
|
28 |
|
29 |
mols = []
|
@@ -43,12 +57,12 @@ def greet2(name):
|
|
43 |
|
44 |
|
45 |
|
46 |
-
greeter_1 = gr.Interface(greet1, inputs="text", outputs="text")
|
47 |
-
greeter_2 = gr.Interface(greet2 , inputs="text", outputs="image")
|
48 |
-
demo = gr.Parallel(greeter_1, greeter_2)
|
49 |
|
50 |
|
51 |
-
demo.launch()
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
24 |
return sf_output
|
25 |
|
26 |
def greet2(name):
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen")
|
28 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/MolGen")
|
29 |
+
|
30 |
+
sf_input = tokenizer(name, return_tensors="pt")
|
31 |
+
|
32 |
+
# beam search
|
33 |
+
molecules = model.generate(input_ids=sf_input["input_ids"],
|
34 |
+
attention_mask=sf_input["attention_mask"],
|
35 |
+
max_length=15,
|
36 |
+
min_length=5,
|
37 |
+
num_return_sequences=5,
|
38 |
+
num_beams=5)
|
39 |
+
|
40 |
+
sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
|
41 |
smis = [sf.decoder(i) for i in sf_output]
|
42 |
|
43 |
mols = []
|
|
|
57 |
|
58 |
|
59 |
|
60 |
+
#greeter_1 = gr.Interface(greet1, inputs="text", outputs="text")
|
61 |
+
#greeter_2 = gr.Interface(greet2 , inputs="text", outputs="image")
|
62 |
+
#demo = gr.Parallel(greeter_1, greeter_2)
|
63 |
|
64 |
|
65 |
+
#demo.launch()
|
66 |
+
iface = gr.Interface(fn=greet2, inputs="text", outputs="image", title="Molecular Language Model as Multi-task Generator",
|
67 |
+
)
|
68 |
+
iface.launch()
|