-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (45 loc) · 1.74 KB
/
app.py
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
49
50
51
52
53
54
55
import torch
import streamlit as st
from src.prediction import draw, predict_from_smiles
from src.prediction import validate_smiles_string
st.title("Graph-Cure")
prob = None
res = None
submit = None
model = torch.load("best_model.pth")
model.to(torch.device("cpu"))
model.eval()
page = st.sidebar.selectbox("Select Page", ["Home", "Prediction"])
if page == "Home":
st.header("Identify molecules that can inhibit HIV")
else:
st.markdown("Select input molecule.")
upload_columns = st.columns([2, 1])
# Smiles input
smiles_select = upload_columns[0].expander(label="Specify SMILES string")
smiles_string = smiles_select.text_input("Enter a valid SMILES string.")
if smiles_string and validate_smiles_string(smiles_string):
try:
upload_columns[1].image(draw(smiles_string))
submit = upload_columns[1].button("Get predictions")
if submit:
print(smiles_string)
with st.spinner(text="Fetching model prediction..."):
res, prob = predict_from_smiles(smiles_string, model)
result_blocks = st.columns([2, 1])
result_blocks[0].subheader("HIV Inhibition Status")
if res == 1:
result_blocks[1].success("Positive")
else:
result_blocks[1].error("Negative")
st.markdown("""---""")
detail_blocks = st.columns([2, 1])
detail_blocks[0].subheader("Confidence")
detail_blocks[1].subheader(f"{round(prob, 2)} %")
except:
st.error("Enter a valid smiles string")
elif not smiles_string:
pass
else:
st.error("Enter a valid smiles string")
st.markdown("""---""")