uragankatrrin commited on
Commit
b18e18b
1 Parent(s): 14ebfa4

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -61
app.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- from mhnreact.inspect import list_models, load_clf
3
- from rdkit.Chem import rdChemReactions as Reaction
4
- from rdkit.Chem.Draw import rdMolDraw2D
5
- from PIL import Image, ImageDraw
6
- from ssretro_template import ssretro
7
-
8
-
9
- def get_output(p):
10
- rxn = Reaction.ReactionFromSmarts(p, useSmiles=False)
11
- d = rdMolDraw2D.MolDraw2DCairo(800, 200)
12
- d.DrawReaction(rxn, highlightByReactant=False)
13
- d.FinishDrawing()
14
- text = d.GetDrawingText()
15
-
16
- return text
17
-
18
- def ssretro_prediction(molecule):
19
-
20
- model_fn = list_models()[0]
21
- retro_clf = load_clf(model_fn)
22
-
23
- outputs = ssretro(molecule, retro_clf)
24
- predict, txt = [], []
25
- for pred in outputs:
26
- txt.append(f'predicted top-{pred["template_rank"]-1}, prob: {pred["prob"]:2.1f}%; {pred["reaction"]}')
27
- predict.append(get_output(pred["reaction"]))
28
-
29
- return predict, txt
30
-
31
-
32
- def mhn_react_backend(mol):
33
-
34
- output_dir = "outputs"
35
- formatter = "03d"
36
- images = []
37
-
38
- predictions, comments = ssretro_prediction(mol)
39
-
40
- for i in range(len(predictions)):
41
- output_im = f"{str(output_dir)}/{format(i, formatter)}.png"
42
-
43
- with open(output_im, "wb") as fh:
44
- fh.write(predictions[i])
45
- fh.close()
46
-
47
- img = Image.open(output_im)
48
- I1 = ImageDraw.Draw(img)
49
-
50
- I1.text((20, 10), comments[i], fill=(30, 0, 44))
51
-
52
- images.append(img)
53
- img.save(output_im)
54
-
55
- return images
56
-
57
-
58
- demo = gr.Interface(fn=mhn_react_backend, inputs="text", outputs="gallery")
59
- demo.launch()
60
-
61
-