File size: 945 Bytes
0bd28fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
---
license: mit
datasets:
- lisn519010/QM9
language:
- en
- zh
metrics:
- mae
- accuracy
- r_squared
- mse
pipeline_tag: graph-ml
---

```
pip install transformers gradio rdkit torch torch_scatter torch_sparse torch_geometric
```

```python
import gradio as gr
from transformers import AutoModel

def predict_smiles(name):
    device = 'cpu'
    smiles = name
    assert isinstance(smiles, str), 'smiles must be str'

    smiles = smiles.strip()
    if ';' in smiles:
        smiles = smiles.split(";")
    elif ' ' in smiles:
        smiles = smiles.split(" ")
    elif ',' in smiles:
        smiles = smiles.split(",")
    else:
        smiles = [smiles]


    model = AutoModel.from_pretrained("Huhujingjing/custom-mxm", trust_remote_code=True).to(device)

    output, df = model.predict_smiles(smiles)

    return output, df

iface = gr.Interface(fn=predict_smiles, inputs="text", outputs=["text", "dataframe"])
iface.launch(share=True)
```