chembfn-webui 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.whl

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/bin/app.py CHANGED
@@ -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,7 @@ 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
+ _result_count = 0
46
47
 
47
48
  HTML_STYLE = gr.InputHTMLAttributes(
48
49
  autocapitalize="off",
@@ -173,15 +174,16 @@ def run(
173
174
  batch_size: int,
174
175
  sequence_size: int,
175
176
  guidance_strength: float,
176
- method: str,
177
+ method: Literal["BFN", "ODE"],
177
178
  temperature: float,
178
179
  prompt: str,
179
180
  scaffold: str,
180
181
  template: str,
181
182
  sar_control: str,
182
183
  exclude_token: str,
183
- quantise: str,
184
- jited: str,
184
+ quantise: Literal["on", "off"],
185
+ jited: Literal["on", "off"],
186
+ sorted_: Literal["on", "off"],
185
187
  ) -> Tuple[Union[List, None], List[str], str, gr.TextArea, str]:
186
188
  """
187
189
  Run generation or inpainting.
@@ -202,6 +204,7 @@ def run(
202
204
  :param exclude_token: unwanted tokens
203
205
  :param quantise: `"on"` or `"off"`
204
206
  :param jited: `"on"` or `"off"`
207
+ :param sorted\\_: whether to sort the reulst; `"on"` or `"off"`
205
208
  :type model_name: str
206
209
  :type token_name: str
207
210
  :type vocab_fn: str
@@ -218,6 +221,7 @@ def run(
218
221
  :type exclude_token: str
219
222
  :type quantise: str
220
223
  :type jited: str
224
+ :type sorted\\_: str
221
225
  :return: list of images \n
222
226
  list of generated molecules \n
223
227
  Chemfig code \n
@@ -243,7 +247,7 @@ def run(
243
247
  if token_name == "FASTA":
244
248
  vocab_keys = FASTA_VOCAB_KEYS
245
249
  tokeniser = fasta2vec
246
- trans_fn = lambda x: x
250
+ trans_fn = lambda x: [i for i in x if i]
247
251
  img_fn = lambda _: None # senseless to provide dumb 2D images
248
252
  chemfig_fn = lambda _: [""] # senseless to provide very long Chemfig code
249
253
  if token_name == "SELFIES":
@@ -251,7 +255,7 @@ def run(
251
255
  vocab_keys = vocab_data["vocab_keys"]
252
256
  vocab_dict = vocab_data["vocab_dict"]
253
257
  tokeniser = partial(selfies2vec, vocab_dict=vocab_dict)
254
- trans_fn = lambda x: x
258
+ trans_fn = lambda x: [i for i in x if i]
255
259
  img_fn = lambda x: [
256
260
  Draw.MolToImage(MolFromSmiles(decoder(i)), (500, 500)) for i in x
257
261
  ]
@@ -285,7 +289,7 @@ def run(
285
289
  y = mlp.forward(y)
286
290
  else:
287
291
  y = None
288
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
292
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
289
293
  bfn.semi_autoregressive = sar_flag[0]
290
294
  if quantise == "on":
291
295
  quantise_model_(bfn)
@@ -317,7 +321,7 @@ def run(
317
321
  y = None
318
322
  if prompt_info["lora_scaling"][0] != 1.0:
319
323
  adjust_lora_(bfn, prompt_info["lora_scaling"][0])
320
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
324
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
321
325
  bfn.semi_autoregressive = sar_flag[0]
322
326
  if quantise == "on":
323
327
  quantise_model_(bfn)
@@ -348,7 +352,7 @@ def run(
348
352
  bfn.quantise()
349
353
  if jited == "on":
350
354
  bfn.compile()
351
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
355
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
352
356
  # ------- inference -------
353
357
  allowed_tokens = parse_exclude_token(exclude_token, vocab_keys)
354
358
  if not allowed_tokens:
@@ -368,6 +372,7 @@ def run(
368
372
  vocab_keys=vocab_keys,
369
373
  method=_method,
370
374
  allowed_tokens=allowed_tokens,
375
+ sort=sorted_ == "on",
371
376
  )
372
377
  mols = trans_fn(mols)
373
378
  imgs = img_fn(mols)
@@ -387,6 +392,7 @@ def run(
387
392
  vocab_keys=vocab_keys,
388
393
  method=_method,
389
394
  allowed_tokens=allowed_tokens,
395
+ sort=sorted_ == "on",
390
396
  )
391
397
  mols = trans_fn(mols)
392
398
  imgs = img_fn(mols)
@@ -402,6 +408,7 @@ def run(
402
408
  vocab_keys=vocab_keys,
403
409
  method=_method,
404
410
  allowed_tokens=allowed_tokens,
411
+ sort=sorted_ == "on",
405
412
  )
406
413
  mols = trans_fn(mols)
407
414
  imgs = img_fn(mols)
@@ -412,6 +419,8 @@ def run(
412
419
  _message.append(
413
420
  f"{n_mol} smaples generated and saved to cache that can be downloaded."
414
421
  )
422
+ global _result_count
423
+ _result_count = n_mol
415
424
  return (
416
425
  imgs,
417
426
  mols,
@@ -541,6 +550,12 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
541
550
  )
542
551
  quantise = gr.Radio(["on", "off"], value="off", label="quantisation")
543
552
  jited = gr.Radio(["on", "off"], value="off", label="JIT")
553
+ sorted_ = gr.Radio(
554
+ ["on", "off"],
555
+ value="off",
556
+ label="sort result",
557
+ info="sorting based on entropy",
558
+ )
544
559
  # ------ user interaction events -------
545
560
  btn.click(
546
561
  fn=run,
@@ -561,6 +576,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
561
576
  exclude_token,
562
577
  quantise,
563
578
  jited,
579
+ sorted_,
564
580
  ],
565
581
  outputs=[img, result, chemfig, message, btn_download],
566
582
  )
@@ -595,7 +611,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
595
611
  )
596
612
  lora_tabel.select(fn=select_lora, inputs=prompt, outputs=prompt)
597
613
  result.change(
598
- fn=lambda x: gr.File(x, label="download", visible=True),
614
+ fn=lambda x: gr.File(x, label="download", visible=_result_count > 0),
599
615
  inputs=btn_download,
600
616
  outputs=btn_download,
601
617
  )
@@ -1 +1,5 @@
1
- CC1(CON)CCC(N)CC1
1
+ CN(Cc1ccccc1)C(=O)Cc1cccc(F)c1F
2
+ Cc1cnc(NC(=O)c2cccc3ccccc23)s1
3
+ COc1ccc(NC(=O)Cc2ccccc2C)cc1
4
+ O=C(CNC(=O)c1ccccc1)NCc1ccccc1
5
+ CCOc1ccccc1C(=O)Nc1ccc(F)cc1
@@ -4,5 +4,5 @@
4
4
  Version info.
5
5
  """
6
6
 
7
- __version__ = "1.2.0"
7
+ __version__ = "1.2.1"
8
8
  __author__ = "Nianze A. TAO"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chembfn_webui
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: WebUI for ChemBFN
5
5
  Home-page: https://github.com/Augus1999/ChemBFN-WebUI
6
6
  Author: Nianze A. Tao
@@ -1,16 +1,16 @@
1
1
  chembfn_webui/__init__.py,sha256=AXUdd_PrlfVO56losFUP7A8XrqCDPylwRbTpe_WG3Uc,87
2
- chembfn_webui/bin/app.py,sha256=ZyiAYiTFtTUnyrlENqXV9ByDKMi2WtMJPnAMcaKTidM,21612
2
+ chembfn_webui/bin/app.py,sha256=Pe5KjPy-EOom-qUKSF0O8AeQLgpI6zg1DkM-V_G59-c,22249
3
3
  chembfn_webui/cache/cache_file_here.txt,sha256=hi60T_q6Cf5WPtXuwe4CqjiWpaUqrczsmGMhKIUL--M,28
4
- chembfn_webui/cache/results.csv,sha256=CaKNQmiX5sbUCdqndjWzllSVi_s9sev8i3Nj0hLJ4LU,17
4
+ chembfn_webui/cache/results.csv,sha256=Z1IOb5NqNuzCdq00TXex8cPpxWlTg5Qi-46HNINcNZg,151
5
5
  chembfn_webui/lib/utilities.py,sha256=ALPw-Evjd9DdsU_RQA6Zp2Gc6XnRR7Y_5fZrqG9azWo,7460
6
- chembfn_webui/lib/version.py,sha256=EBNxY5E7vFFhf4osZe_mH3SbhzHBV9PM1CC9AQ_7PWc,138
6
+ chembfn_webui/lib/version.py,sha256=5CABifnS6Arnwe8Or6Z9N5ZxwaP9EHjFHhaMM64RF-E,138
7
7
  chembfn_webui/model/base_model/place_base_model_here.txt,sha256=oa8_ILaAlWpTXICVDi-Y46_OahV7wB6Che6gbiEIh-c,39
8
8
  chembfn_webui/model/lora/place_lora_folder_here.txt,sha256=YYOo0Cj278DyRcgVrCLa1f2Q-cqgNeMnelaLiA3Fuic,69
9
9
  chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt,sha256=Dp42UscfI0Zp3SnvRv5vOfWiJZnxdY7rG3jo0kf86VM,80
10
10
  chembfn_webui/model/vocab/place_vocabulary_file_here.txt,sha256=fLOINvZP2022oE7RsmfDjgyaw2yMi7glmdu_cTwmo88,28
11
- chembfn_webui-1.2.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
12
- chembfn_webui-1.2.0.dist-info/METADATA,sha256=5OXhUF4QixSdnnSLTJkrLxznBQ8-y8UhCfxA7TzuliA,6412
13
- chembfn_webui-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- chembfn_webui-1.2.0.dist-info/entry_points.txt,sha256=fp8WTPybvwpeYKrUhTi456wwZbmCMJXN1TeFGpR1SlY,55
15
- chembfn_webui-1.2.0.dist-info/top_level.txt,sha256=VdWt3Z7jhbB0pQO_mkRawnU5s75SBT9BV8fGaAIJTDI,14
16
- chembfn_webui-1.2.0.dist-info/RECORD,,
11
+ chembfn_webui-1.2.1.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
12
+ chembfn_webui-1.2.1.dist-info/METADATA,sha256=NQBmy41ZZmg8sAFkddQBpWZMrdoVSRx2rZO_0kBHaG4,6412
13
+ chembfn_webui-1.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ chembfn_webui-1.2.1.dist-info/entry_points.txt,sha256=fp8WTPybvwpeYKrUhTi456wwZbmCMJXN1TeFGpR1SlY,55
15
+ chembfn_webui-1.2.1.dist-info/top_level.txt,sha256=VdWt3Z7jhbB0pQO_mkRawnU5s75SBT9BV8fGaAIJTDI,14
16
+ chembfn_webui-1.2.1.dist-info/RECORD,,