chembfn-webui 0.2.0__tar.gz → 0.4.0__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.

Files changed (22) hide show
  1. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/PKG-INFO +1 -1
  2. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/bin/app.py +67 -17
  3. chembfn_webui-0.4.0/chembfn_webui/cache/results.csv +1 -0
  4. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/lib/version.py +1 -1
  5. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/PKG-INFO +1 -1
  6. chembfn_webui-0.2.0/chembfn_webui/cache/results.csv +0 -7
  7. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/LICENSE +0 -0
  8. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/README.md +0 -0
  9. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/__init__.py +0 -0
  10. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/cache/cache_file_here.txt +0 -0
  11. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/lib/utilities.py +0 -0
  12. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/model/base_model/place_base_model_here.txt +0 -0
  13. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/model/lora/place_lora_folder_here.txt +0 -0
  14. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt +0 -0
  15. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui/model/vocab/place_vocabulary_file_here.txt +0 -0
  16. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/SOURCES.txt +0 -0
  17. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/dependency_links.txt +0 -0
  18. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/entry_points.txt +0 -0
  19. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/requires.txt +0 -0
  20. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/chembfn_webui.egg-info/top_level.txt +0 -0
  21. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/setup.cfg +0 -0
  22. {chembfn_webui-0.2.0 → chembfn_webui-0.4.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chembfn_webui
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: WebUI for ChemBFN
5
5
  Home-page: https://github.com/Augus1999/ChemBFN-WebUI
6
6
  Author: Nianze A. Tao
@@ -7,10 +7,10 @@ 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
10
+ from typing import Tuple, List, Dict, Union
11
11
 
12
12
  sys.path.append(str(Path(__file__).parent.parent))
13
- from rdkit.Chem import Draw, MolFromSmiles, MolFromFASTA
13
+ from rdkit.Chem import Draw, MolFromSmiles
14
14
  from mol2chemfigPy3 import mol2chemfig
15
15
  import gradio as gr
16
16
  import torch
@@ -39,6 +39,14 @@ models = find_model()
39
39
  lora_selected = False # lora select flag
40
40
  cache_dir = Path(__file__).parent.parent / "cache"
41
41
 
42
+ HTML_STYLE = gr.InputHTMLAttributes(
43
+ autocapitalize="off",
44
+ autocorrect="off",
45
+ spellcheck=False,
46
+ autocomplete="off",
47
+ lang="en",
48
+ )
49
+
42
50
 
43
51
  def selfies2vec(sel: str, vocab_dict: Dict[str, int]) -> List[int]:
44
52
  """
@@ -93,12 +101,14 @@ def refresh(
93
101
  [i[0] for i in models["base"]] + [i[0] for i in models["standalone"]],
94
102
  value=model_selected,
95
103
  label="model",
104
+ filterable=False,
96
105
  )
97
106
  f = gr.Dropdown(
98
107
  list(vocabs.keys()),
99
108
  value=vocab_selected,
100
109
  label="vocabulary",
101
110
  visible=tokeniser_selected == "SELFIES",
111
+ filterable=False,
102
112
  )
103
113
  return a, b, c, d, e, f
104
114
 
@@ -127,6 +137,33 @@ def select_lora(evt: gr.SelectData, prompt: str) -> str:
127
137
  return f"{prompt};\n<{selected_lora}:1>"
128
138
 
129
139
 
140
+ def token_name_change_evt(
141
+ token_name: str, vocab_fn: str
142
+ ) -> Tuple[gr.Dropdown, gr.Tab, gr.Tab]:
143
+ """
144
+ Define token_name-dropdown item change event.
145
+
146
+ :param token_name: tokeniser name
147
+ :param vocab_fn: customised vocabulary name
148
+ :type token_name: str
149
+ :type vocab_fn: str
150
+ :return: Dropdown item \n
151
+ Tab item \n
152
+ Tab item \n
153
+ :rtype: tuple
154
+ """
155
+ a = gr.Dropdown(
156
+ list(vocabs.keys()),
157
+ value=vocab_fn,
158
+ label="vocabulary",
159
+ visible=token_name == "SELFIES",
160
+ filterable=False,
161
+ )
162
+ b = gr.Tab(label="LATEX Chemfig", visible=token_name != "FASTA")
163
+ c = gr.Tab(label="gallery", visible=token_name != "FASTA")
164
+ return a, b, c
165
+
166
+
130
167
  def run(
131
168
  model_name: str,
132
169
  token_name: str,
@@ -143,7 +180,7 @@ def run(
143
180
  exclude_token: str,
144
181
  quantise: str,
145
182
  jited: str,
146
- ) -> Tuple[List, List[str], str, str, str]:
183
+ ) -> Tuple[Union[List, None], List[str], str, str, str]:
147
184
  """
148
185
  Run generation or inpainting.
149
186
 
@@ -203,8 +240,8 @@ def run(
203
240
  vocab_keys = AA_VOCAB_KEYS
204
241
  tokeniser = aa2vec
205
242
  trans_fn = lambda x: x
206
- img_fn = lambda x: [Draw.MolToImage(MolFromFASTA(i), (500, 500)) for i in x]
207
- chemfig_fn = lambda x: ["null" for _ in x]
243
+ img_fn = lambda _: None # senseless to provide dumb 2D images
244
+ chemfig_fn = lambda _: [""] # senseless to provide very long Chemfig code
208
245
  if token_name == "SELFIES":
209
246
  vocab_data = load_vocab(vocabs[vocab_fn])
210
247
  vocab_keys = vocab_data["vocab_keys"]
@@ -364,14 +401,18 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
364
401
  model_name = gr.Dropdown(
365
402
  [i[0] for i in models["base"]] + [i[0] for i in models["standalone"]],
366
403
  label="model",
404
+ filterable=False,
367
405
  )
368
406
  token_name = gr.Dropdown(
369
- ["SMILES & SAFE", "SELFIES", "FASTA"], label="tokeniser"
407
+ ["SMILES & SAFE", "SELFIES", "FASTA"],
408
+ label="tokeniser",
409
+ filterable=False,
370
410
  )
371
411
  vocab_fn = gr.Dropdown(
372
412
  list(vocabs.keys()),
373
413
  label="vocabulary",
374
414
  visible=token_name.value == "SELFIES",
415
+ filterable=False,
375
416
  )
376
417
  step = gr.Slider(1, 5000, 100, step=1, precision=0, label="step")
377
418
  batch_size = gr.Slider(1, 512, 1, step=1, precision=0, label="batch size")
@@ -381,7 +422,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
381
422
  guidance_strength = gr.Slider(
382
423
  0, 25, 4, step=0.05, label="guidance strength"
383
424
  )
384
- method = gr.Dropdown(["BFN", "ODE"], label="method")
425
+ method = gr.Dropdown(["BFN", "ODE"], label="method", filterable=False)
385
426
  temperature = gr.Slider(
386
427
  0.0,
387
428
  2.5,
@@ -392,8 +433,10 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
392
433
  )
393
434
  with gr.Column(scale=2):
394
435
  with gr.Tab(label="prompt editor"):
395
- prompt = gr.TextArea(label="prompt", lines=12)
396
- scaffold = gr.Textbox(label="scaffold")
436
+ prompt = gr.TextArea(
437
+ label="prompt", lines=12, html_attributes=HTML_STYLE
438
+ )
439
+ scaffold = gr.Textbox(label="scaffold", html_attributes=HTML_STYLE)
397
440
  gr.Markdown("")
398
441
  message = gr.TextArea(label="message")
399
442
  with gr.Tab(label="result viewer"):
@@ -407,11 +450,15 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
407
450
  show_row_numbers=True,
408
451
  show_copy_button=True,
409
452
  )
410
- with gr.Tab(label="LATEX Chemfig"):
453
+ with gr.Tab(
454
+ label="LATEX Chemfig", visible=token_name.value != "FASTA"
455
+ ) as code:
411
456
  chemfig = gr.Code(
412
457
  label="", language="latex", show_line_numbers=True
413
458
  )
414
- with gr.Tab(label="gallery"):
459
+ with gr.Tab(
460
+ label="gallery", visible=token_name.value != "FASTA"
461
+ ) as gallery:
415
462
  img = gr.Gallery(label="molecule", columns=4, height=512)
416
463
  with gr.Tab(label="model explorer"):
417
464
  btn_refresh = gr.Button("refresh", variant="secondary")
@@ -452,11 +499,16 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
452
499
  show_row_numbers=True,
453
500
  )
454
501
  with gr.Tab(label="advanced control"):
455
- sar_control = gr.Textbox("F", label="semi-autoregressive behaviour")
502
+ sar_control = gr.Textbox(
503
+ "F",
504
+ label="semi-autoregressive behaviour",
505
+ html_attributes=HTML_STYLE,
506
+ )
456
507
  gr.Markdown("")
457
508
  exclude_token = gr.TextArea(
458
509
  label="exclude tokens",
459
510
  placeholder="key in unwanted tokens separated by comma.",
511
+ html_attributes=HTML_STYLE,
460
512
  )
461
513
  quantise = gr.Radio(["on", "off"], value="off", label="quantisation")
462
514
  jited = gr.Radio(["on", "off"], value="off", label="JIT")
@@ -495,11 +547,9 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
495
547
  ],
496
548
  )
497
549
  token_name.input(
498
- fn=lambda x, y: gr.Dropdown(
499
- list(vocabs.keys()), value=y, label="vocabulary", visible=x == "SELFIES"
500
- ),
550
+ fn=token_name_change_evt,
501
551
  inputs=[token_name, vocab_fn],
502
- outputs=vocab_fn,
552
+ outputs=[vocab_fn, code, gallery],
503
553
  )
504
554
  method.input(
505
555
  fn=lambda x, y: gr.Slider(
@@ -534,7 +584,7 @@ def main() -> None:
534
584
  )
535
585
  parser.add_argument("-V", "--version", action="version", version=__version__)
536
586
  args = parser.parse_args()
537
- app.launch(share=args.public)
587
+ app.launch(share=args.public, allowed_paths=[cache_dir.absolute().__str__()])
538
588
 
539
589
 
540
590
  if __name__ == "__main__":
@@ -0,0 +1 @@
1
+ CCOCC(=O)N1CCC[C@@H](C2CC2)CC1
@@ -4,5 +4,5 @@
4
4
  Version info.
5
5
  """
6
6
 
7
- __version__ = "0.2.0"
7
+ __version__ = "0.4.0"
8
8
  __author__ = "Nianze A. TAO"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chembfn_webui
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: WebUI for ChemBFN
5
5
  Home-page: https://github.com/Augus1999/ChemBFN-WebUI
6
6
  Author: Nianze A. Tao
@@ -1,7 +0,0 @@
1
- CC(C)(CC#N)C#N
2
- CCC(C)(C#N)C#N
3
- C1C(C)(C#N)C1C#N
4
- C(C)(C)C(C#N)C#N
5
- C(C)CC(C#N)C#N
6
- CCC(C)(C#N)C#N
7
- CC(C)(C#N)C#N
File without changes
File without changes
File without changes
File without changes