File size: 1,272 Bytes
c3652ea
ae11df6
 
 
 
c3652ea
ae11df6
c3652ea
ae11df6
 
 
 
 
 
 
 
 
 
 
 
 
5e4cf73
 
 
 
 
 
 
 
 
707ff3d
5e4cf73
 
 
 
 
 
 
 
 
1893020
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
import pandas as pd
from rdkit import Chem
from rdkit.Chem import AllChem
import joblib

model = joblib.load('CHO.pkl')

def predict(smiles):
    if smiles.strip() == "":
        raise gr.Error("SMILES input error")

    mol = Chem.MolFromSmiles(smiles)
    if mol == None:
        raise gr.Error("SMILES input error")
    mol_ECFP4 = list(AllChem.GetMorganFingerprintAsBitVect(mol, 2, nBits=1024).ToBitString())
    preprocess_data = pd.DataFrame([mol_ECFP4])
    result = model.predict(preprocess_data)
    postprocess_data = '{:.2e}'.format(pow(10, result[0]))
    return postprocess_data


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            inputs=gr.Textbox(lines=2, label="Please enter SMILES for the compound")
            with gr.Row():
                btn = gr.Button(variant="primary",value="submit")
                clear_btn = gr.ClearButton(value="clear")
        with gr.Column():
            outputs=gr.Textbox(lines=1, label="Predicted CHO cytotoxicity of the chemical is:",info="Unit: mol/L")

    btn.click(predict, inputs=[inputs], outputs=[outputs])
    clear_btn.add([inputs,outputs])

    gr.Examples(
        [["O=C(O)CBr"],["O=CC(Br)(Br)Br"],["IC(Br)Br"]],
        [inputs],
    )


demo.launch()