chembfn-webui 1.2.0__tar.gz → 1.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chembfn-webui might be problematic. Click here for more details.
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/PKG-INFO +1 -1
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/bin/app.py +33 -11
- chembfn_webui-1.2.2/chembfn_webui/bin/favicon.png +0 -0
- chembfn_webui-1.2.2/chembfn_webui/cache/results.csv +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/lib/version.py +1 -1
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/PKG-INFO +1 -1
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/SOURCES.txt +1 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/setup.py +7 -1
- chembfn_webui-1.2.0/chembfn_webui/cache/results.csv +0 -1
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/LICENSE +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/README.md +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/__init__.py +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/cache/cache_file_here.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/lib/utilities.py +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/base_model/place_base_model_here.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/lora/place_lora_folder_here.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/vocab/place_vocabulary_file_here.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/dependency_links.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/entry_points.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/requires.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui.egg-info/top_level.txt +0 -0
- {chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/setup.cfg +0 -0
|
@@ -7,7 +7,7 @@ import sys
|
|
|
7
7
|
import argparse
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from functools import partial
|
|
10
|
-
from typing import Tuple, List, Dict, Union
|
|
10
|
+
from typing import Tuple, List, Dict, Union, Literal
|
|
11
11
|
|
|
12
12
|
sys.path.append(str(Path(__file__).parent.parent))
|
|
13
13
|
from rdkit.Chem import Draw, MolFromSmiles # type: ignore
|
|
@@ -43,6 +43,8 @@ from lib.version import __version__
|
|
|
43
43
|
vocabs = find_vocab()
|
|
44
44
|
models = find_model()
|
|
45
45
|
cache_dir = Path(__file__).parent.parent / "cache"
|
|
46
|
+
favicon_dir = Path(__file__).parent / "favicon.png"
|
|
47
|
+
_result_count = 0
|
|
46
48
|
|
|
47
49
|
HTML_STYLE = gr.InputHTMLAttributes(
|
|
48
50
|
autocapitalize="off",
|
|
@@ -173,15 +175,16 @@ def run(
|
|
|
173
175
|
batch_size: int,
|
|
174
176
|
sequence_size: int,
|
|
175
177
|
guidance_strength: float,
|
|
176
|
-
method:
|
|
178
|
+
method: Literal["BFN", "ODE"],
|
|
177
179
|
temperature: float,
|
|
178
180
|
prompt: str,
|
|
179
181
|
scaffold: str,
|
|
180
182
|
template: str,
|
|
181
183
|
sar_control: str,
|
|
182
184
|
exclude_token: str,
|
|
183
|
-
quantise:
|
|
184
|
-
jited:
|
|
185
|
+
quantise: Literal["on", "off"],
|
|
186
|
+
jited: Literal["on", "off"],
|
|
187
|
+
sorted_: Literal["on", "off"],
|
|
185
188
|
) -> Tuple[Union[List, None], List[str], str, gr.TextArea, str]:
|
|
186
189
|
"""
|
|
187
190
|
Run generation or inpainting.
|
|
@@ -202,6 +205,7 @@ def run(
|
|
|
202
205
|
:param exclude_token: unwanted tokens
|
|
203
206
|
:param quantise: `"on"` or `"off"`
|
|
204
207
|
:param jited: `"on"` or `"off"`
|
|
208
|
+
:param sorted\\_: whether to sort the reulst; `"on"` or `"off"`
|
|
205
209
|
:type model_name: str
|
|
206
210
|
:type token_name: str
|
|
207
211
|
:type vocab_fn: str
|
|
@@ -218,6 +222,7 @@ def run(
|
|
|
218
222
|
:type exclude_token: str
|
|
219
223
|
:type quantise: str
|
|
220
224
|
:type jited: str
|
|
225
|
+
:type sorted\\_: str
|
|
221
226
|
:return: list of images \n
|
|
222
227
|
list of generated molecules \n
|
|
223
228
|
Chemfig code \n
|
|
@@ -243,7 +248,7 @@ def run(
|
|
|
243
248
|
if token_name == "FASTA":
|
|
244
249
|
vocab_keys = FASTA_VOCAB_KEYS
|
|
245
250
|
tokeniser = fasta2vec
|
|
246
|
-
trans_fn = lambda x: x
|
|
251
|
+
trans_fn = lambda x: [i for i in x if i]
|
|
247
252
|
img_fn = lambda _: None # senseless to provide dumb 2D images
|
|
248
253
|
chemfig_fn = lambda _: [""] # senseless to provide very long Chemfig code
|
|
249
254
|
if token_name == "SELFIES":
|
|
@@ -251,7 +256,7 @@ def run(
|
|
|
251
256
|
vocab_keys = vocab_data["vocab_keys"]
|
|
252
257
|
vocab_dict = vocab_data["vocab_dict"]
|
|
253
258
|
tokeniser = partial(selfies2vec, vocab_dict=vocab_dict)
|
|
254
|
-
trans_fn = lambda x: x
|
|
259
|
+
trans_fn = lambda x: [i for i in x if i]
|
|
255
260
|
img_fn = lambda x: [
|
|
256
261
|
Draw.MolToImage(MolFromSmiles(decoder(i)), (500, 500)) for i in x
|
|
257
262
|
]
|
|
@@ -285,7 +290,7 @@ def run(
|
|
|
285
290
|
y = mlp.forward(y)
|
|
286
291
|
else:
|
|
287
292
|
y = None
|
|
288
|
-
_message.append(f"Sequence length
|
|
293
|
+
_message.append(f"Sequence length set to {lmax} from model metadata.")
|
|
289
294
|
bfn.semi_autoregressive = sar_flag[0]
|
|
290
295
|
if quantise == "on":
|
|
291
296
|
quantise_model_(bfn)
|
|
@@ -317,7 +322,7 @@ def run(
|
|
|
317
322
|
y = None
|
|
318
323
|
if prompt_info["lora_scaling"][0] != 1.0:
|
|
319
324
|
adjust_lora_(bfn, prompt_info["lora_scaling"][0])
|
|
320
|
-
_message.append(f"Sequence length
|
|
325
|
+
_message.append(f"Sequence length set to {lmax} from model metadata.")
|
|
321
326
|
bfn.semi_autoregressive = sar_flag[0]
|
|
322
327
|
if quantise == "on":
|
|
323
328
|
quantise_model_(bfn)
|
|
@@ -348,7 +353,7 @@ def run(
|
|
|
348
353
|
bfn.quantise()
|
|
349
354
|
if jited == "on":
|
|
350
355
|
bfn.compile()
|
|
351
|
-
_message.append(f"Sequence length
|
|
356
|
+
_message.append(f"Sequence length set to {lmax} from model metadata.")
|
|
352
357
|
# ------- inference -------
|
|
353
358
|
allowed_tokens = parse_exclude_token(exclude_token, vocab_keys)
|
|
354
359
|
if not allowed_tokens:
|
|
@@ -368,6 +373,7 @@ def run(
|
|
|
368
373
|
vocab_keys=vocab_keys,
|
|
369
374
|
method=_method,
|
|
370
375
|
allowed_tokens=allowed_tokens,
|
|
376
|
+
sort=sorted_ == "on",
|
|
371
377
|
)
|
|
372
378
|
mols = trans_fn(mols)
|
|
373
379
|
imgs = img_fn(mols)
|
|
@@ -387,6 +393,7 @@ def run(
|
|
|
387
393
|
vocab_keys=vocab_keys,
|
|
388
394
|
method=_method,
|
|
389
395
|
allowed_tokens=allowed_tokens,
|
|
396
|
+
sort=sorted_ == "on",
|
|
390
397
|
)
|
|
391
398
|
mols = trans_fn(mols)
|
|
392
399
|
imgs = img_fn(mols)
|
|
@@ -402,6 +409,7 @@ def run(
|
|
|
402
409
|
vocab_keys=vocab_keys,
|
|
403
410
|
method=_method,
|
|
404
411
|
allowed_tokens=allowed_tokens,
|
|
412
|
+
sort=sorted_ == "on",
|
|
405
413
|
)
|
|
406
414
|
mols = trans_fn(mols)
|
|
407
415
|
imgs = img_fn(mols)
|
|
@@ -412,6 +420,8 @@ def run(
|
|
|
412
420
|
_message.append(
|
|
413
421
|
f"{n_mol} smaples generated and saved to cache that can be downloaded."
|
|
414
422
|
)
|
|
423
|
+
global _result_count
|
|
424
|
+
_result_count = n_mol
|
|
415
425
|
return (
|
|
416
426
|
imgs,
|
|
417
427
|
mols,
|
|
@@ -541,6 +551,12 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
|
|
|
541
551
|
)
|
|
542
552
|
quantise = gr.Radio(["on", "off"], value="off", label="quantisation")
|
|
543
553
|
jited = gr.Radio(["on", "off"], value="off", label="JIT")
|
|
554
|
+
sorted_ = gr.Radio(
|
|
555
|
+
["on", "off"],
|
|
556
|
+
value="off",
|
|
557
|
+
label="sort result",
|
|
558
|
+
info="sorting based on entropy",
|
|
559
|
+
)
|
|
544
560
|
# ------ user interaction events -------
|
|
545
561
|
btn.click(
|
|
546
562
|
fn=run,
|
|
@@ -561,6 +577,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
|
|
|
561
577
|
exclude_token,
|
|
562
578
|
quantise,
|
|
563
579
|
jited,
|
|
580
|
+
sorted_,
|
|
564
581
|
],
|
|
565
582
|
outputs=[img, result, chemfig, message, btn_download],
|
|
566
583
|
)
|
|
@@ -595,7 +612,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
|
|
|
595
612
|
)
|
|
596
613
|
lora_tabel.select(fn=select_lora, inputs=prompt, outputs=prompt)
|
|
597
614
|
result.change(
|
|
598
|
-
fn=lambda x: gr.File(x, label="download", visible=
|
|
615
|
+
fn=lambda x: gr.File(x, label="download", visible=_result_count > 0),
|
|
599
616
|
inputs=btn_download,
|
|
600
617
|
outputs=btn_download,
|
|
601
618
|
)
|
|
@@ -619,7 +636,12 @@ def main() -> None:
|
|
|
619
636
|
)
|
|
620
637
|
parser.add_argument("-V", "--version", action="version", version=__version__)
|
|
621
638
|
args = parser.parse_args()
|
|
622
|
-
|
|
639
|
+
print(f"This is ChemBFN WebUI version {__version__}")
|
|
640
|
+
app.launch(
|
|
641
|
+
share=args.public,
|
|
642
|
+
allowed_paths=[cache_dir.absolute().__str__()],
|
|
643
|
+
favicon_path=favicon_dir.absolute().__str__(),
|
|
644
|
+
)
|
|
623
645
|
|
|
624
646
|
|
|
625
647
|
if __name__ == "__main__":
|
|
Binary file
|
|
File without changes
|
|
@@ -9,6 +9,7 @@ chembfn_webui.egg-info/entry_points.txt
|
|
|
9
9
|
chembfn_webui.egg-info/requires.txt
|
|
10
10
|
chembfn_webui.egg-info/top_level.txt
|
|
11
11
|
chembfn_webui/bin/app.py
|
|
12
|
+
chembfn_webui/bin/favicon.png
|
|
12
13
|
chembfn_webui/cache/cache_file_here.txt
|
|
13
14
|
chembfn_webui/cache/results.csv
|
|
14
15
|
chembfn_webui/lib/utilities.py
|
|
@@ -48,7 +48,13 @@ setup(
|
|
|
48
48
|
license_files=["LICEN[CS]E*"],
|
|
49
49
|
package_dir={"chembfn_webui": "chembfn_webui"},
|
|
50
50
|
package_data={
|
|
51
|
-
"chembfn_webui": [
|
|
51
|
+
"chembfn_webui": [
|
|
52
|
+
"./*/*/place_*.txt",
|
|
53
|
+
"./*/*.txt",
|
|
54
|
+
"./*/*.py",
|
|
55
|
+
"./*/*.csv",
|
|
56
|
+
"./*/*.png",
|
|
57
|
+
]
|
|
52
58
|
},
|
|
53
59
|
include_package_data=True,
|
|
54
60
|
author="Nianze A. Tao",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
CC1(CON)CCC(N)CC1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/base_model/place_base_model_here.txt
RENAMED
|
File without changes
|
{chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/lora/place_lora_folder_here.txt
RENAMED
|
File without changes
|
|
File without changes
|
{chembfn_webui-1.2.0 → chembfn_webui-1.2.2}/chembfn_webui/model/vocab/place_vocabulary_file_here.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|