chembfn-webui 1.1.0__tar.gz → 1.2.1__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.1.0 → chembfn_webui-1.2.1}/PKG-INFO +1 -1
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/bin/app.py +28 -20
- chembfn_webui-1.2.1/chembfn_webui/cache/results.csv +5 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/lib/version.py +1 -1
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/PKG-INFO +1 -1
- chembfn_webui-1.1.0/chembfn_webui/cache/results.csv +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/LICENSE +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/README.md +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/__init__.py +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/cache/cache_file_here.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/lib/utilities.py +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/base_model/place_base_model_here.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/lora/place_lora_folder_here.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/vocab/place_vocabulary_file_here.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/SOURCES.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/dependency_links.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/entry_points.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/requires.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui.egg-info/top_level.txt +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/setup.cfg +0 -0
- {chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/setup.py +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
|
|
@@ -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
|
-
|
|
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:
|
|
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:
|
|
190
|
-
jited:
|
|
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
|
|
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
|
|
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
|
|
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=
|
|
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
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/base_model/place_base_model_here.txt
RENAMED
|
File without changes
|
{chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/chembfn_webui/model/lora/place_lora_folder_here.txt
RENAMED
|
File without changes
|
|
File without changes
|
{chembfn_webui-1.1.0 → chembfn_webui-1.2.1}/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
|
|
File without changes
|
|
File without changes
|