chembfn-webui 1.1.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
@@ -42,9 +42,8 @@ from lib.version import __version__
42
42
 
43
43
  vocabs = find_vocab()
44
44
  models = find_model()
45
- _lora_selected = False # lora select flag
46
- _run_in_public = False # public flag
47
45
  cache_dir = Path(__file__).parent.parent / "cache"
46
+ _result_count = 0
48
47
 
49
48
  HTML_STYLE = gr.InputHTMLAttributes(
50
49
  autocapitalize="off",
@@ -131,13 +130,9 @@ def select_lora(evt: gr.SelectData, prompt: str) -> str:
131
130
  :return: new prompt string
132
131
  :rtype: str
133
132
  """
134
- global _lora_selected
135
- if _lora_selected and not _run_in_public: # avoid double select
136
- _lora_selected = False
137
- return prompt
138
133
  selected_lora = evt.value
139
- _lora_selected = True
140
- if evt.index[1] != 0:
134
+ exist_lora = parse_prompt(prompt)["lora"]
135
+ if evt.index[1] != 0 or selected_lora in exist_lora:
141
136
  return prompt
142
137
  if not prompt:
143
138
  return f"<{selected_lora}:1>"
@@ -179,15 +174,16 @@ def run(
179
174
  batch_size: int,
180
175
  sequence_size: int,
181
176
  guidance_strength: float,
182
- method: str,
177
+ method: Literal["BFN", "ODE"],
183
178
  temperature: float,
184
179
  prompt: str,
185
180
  scaffold: str,
186
181
  template: str,
187
182
  sar_control: str,
188
183
  exclude_token: str,
189
- quantise: str,
190
- jited: str,
184
+ quantise: Literal["on", "off"],
185
+ jited: Literal["on", "off"],
186
+ sorted_: Literal["on", "off"],
191
187
  ) -> Tuple[Union[List, None], List[str], str, gr.TextArea, str]:
192
188
  """
193
189
  Run generation or inpainting.
@@ -208,6 +204,7 @@ def run(
208
204
  :param exclude_token: unwanted tokens
209
205
  :param quantise: `"on"` or `"off"`
210
206
  :param jited: `"on"` or `"off"`
207
+ :param sorted\\_: whether to sort the reulst; `"on"` or `"off"`
211
208
  :type model_name: str
212
209
  :type token_name: str
213
210
  :type vocab_fn: str
@@ -224,6 +221,7 @@ def run(
224
221
  :type exclude_token: str
225
222
  :type quantise: str
226
223
  :type jited: str
224
+ :type sorted\\_: str
227
225
  :return: list of images \n
228
226
  list of generated molecules \n
229
227
  Chemfig code \n
@@ -249,7 +247,7 @@ def run(
249
247
  if token_name == "FASTA":
250
248
  vocab_keys = FASTA_VOCAB_KEYS
251
249
  tokeniser = fasta2vec
252
- trans_fn = lambda x: x
250
+ trans_fn = lambda x: [i for i in x if i]
253
251
  img_fn = lambda _: None # senseless to provide dumb 2D images
254
252
  chemfig_fn = lambda _: [""] # senseless to provide very long Chemfig code
255
253
  if token_name == "SELFIES":
@@ -257,7 +255,7 @@ def run(
257
255
  vocab_keys = vocab_data["vocab_keys"]
258
256
  vocab_dict = vocab_data["vocab_dict"]
259
257
  tokeniser = partial(selfies2vec, vocab_dict=vocab_dict)
260
- trans_fn = lambda x: x
258
+ trans_fn = lambda x: [i for i in x if i]
261
259
  img_fn = lambda x: [
262
260
  Draw.MolToImage(MolFromSmiles(decoder(i)), (500, 500)) for i in x
263
261
  ]
@@ -291,7 +289,7 @@ def run(
291
289
  y = mlp.forward(y)
292
290
  else:
293
291
  y = None
294
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
292
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
295
293
  bfn.semi_autoregressive = sar_flag[0]
296
294
  if quantise == "on":
297
295
  quantise_model_(bfn)
@@ -323,7 +321,7 @@ def run(
323
321
  y = None
324
322
  if prompt_info["lora_scaling"][0] != 1.0:
325
323
  adjust_lora_(bfn, prompt_info["lora_scaling"][0])
326
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
324
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
327
325
  bfn.semi_autoregressive = sar_flag[0]
328
326
  if quantise == "on":
329
327
  quantise_model_(bfn)
@@ -354,7 +352,7 @@ def run(
354
352
  bfn.quantise()
355
353
  if jited == "on":
356
354
  bfn.compile()
357
- _message.append(f"Sequence length is set to {lmax} from model metadata.")
355
+ _message.append(f"Sequence length set to {lmax} from model metadata.")
358
356
  # ------- inference -------
359
357
  allowed_tokens = parse_exclude_token(exclude_token, vocab_keys)
360
358
  if not allowed_tokens:
@@ -374,6 +372,7 @@ def run(
374
372
  vocab_keys=vocab_keys,
375
373
  method=_method,
376
374
  allowed_tokens=allowed_tokens,
375
+ sort=sorted_ == "on",
377
376
  )
378
377
  mols = trans_fn(mols)
379
378
  imgs = img_fn(mols)
@@ -393,6 +392,7 @@ def run(
393
392
  vocab_keys=vocab_keys,
394
393
  method=_method,
395
394
  allowed_tokens=allowed_tokens,
395
+ sort=sorted_ == "on",
396
396
  )
397
397
  mols = trans_fn(mols)
398
398
  imgs = img_fn(mols)
@@ -408,6 +408,7 @@ def run(
408
408
  vocab_keys=vocab_keys,
409
409
  method=_method,
410
410
  allowed_tokens=allowed_tokens,
411
+ sort=sorted_ == "on",
411
412
  )
412
413
  mols = trans_fn(mols)
413
414
  imgs = img_fn(mols)
@@ -418,6 +419,8 @@ def run(
418
419
  _message.append(
419
420
  f"{n_mol} smaples generated and saved to cache that can be downloaded."
420
421
  )
422
+ global _result_count
423
+ _result_count = n_mol
421
424
  return (
422
425
  imgs,
423
426
  mols,
@@ -547,6 +550,12 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
547
550
  )
548
551
  quantise = gr.Radio(["on", "off"], value="off", label="quantisation")
549
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
+ )
550
559
  # ------ user interaction events -------
551
560
  btn.click(
552
561
  fn=run,
@@ -567,6 +576,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
567
576
  exclude_token,
568
577
  quantise,
569
578
  jited,
579
+ sorted_,
570
580
  ],
571
581
  outputs=[img, result, chemfig, message, btn_download],
572
582
  )
@@ -601,7 +611,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
601
611
  )
602
612
  lora_tabel.select(fn=select_lora, inputs=prompt, outputs=prompt)
603
613
  result.change(
604
- fn=lambda x: gr.File(x, label="download", visible=True),
614
+ fn=lambda x: gr.File(x, label="download", visible=_result_count > 0),
605
615
  inputs=btn_download,
606
616
  outputs=btn_download,
607
617
  )
@@ -625,8 +635,6 @@ def main() -> None:
625
635
  )
626
636
  parser.add_argument("-V", "--version", action="version", version=__version__)
627
637
  args = parser.parse_args()
628
- global _run_in_public
629
- _run_in_public = args.public
630
638
  app.launch(share=args.public, allowed_paths=[cache_dir.absolute().__str__()])
631
639
 
632
640
 
@@ -0,0 +1,5 @@
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.1.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.1.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=Oguy3G8jaIuNT7RZWgtGweMKzCLipagMGH7E7y7C27A,21849
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=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
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=9gQIR8VWU0vhANDgg8w-friQemzdDuGMpih04LtIwCY,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.1.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
12
- chembfn_webui-1.1.0.dist-info/METADATA,sha256=zLnFwjbkQsvqAm2fg5f17A7N-4X2sIFvJ4n4tcr2Sa0,6412
13
- chembfn_webui-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- chembfn_webui-1.1.0.dist-info/entry_points.txt,sha256=fp8WTPybvwpeYKrUhTi456wwZbmCMJXN1TeFGpR1SlY,55
15
- chembfn_webui-1.1.0.dist-info/top_level.txt,sha256=VdWt3Z7jhbB0pQO_mkRawnU5s75SBT9BV8fGaAIJTDI,14
16
- chembfn_webui-1.1.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,,