shreyab21 commited on
Commit
9f90436
·
verified ·
1 Parent(s): 5d4d9d2

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +13 -3
streamlit_app.py CHANGED
@@ -65,7 +65,13 @@ def load_stability_model():
65
 
66
  embeddings_dict = load_embeddings()
67
  final_df = load_results()
68
- stability_model = load_stability_model()
 
 
 
 
 
 
69
  # --------------------------------------------------
70
  # TOP: Molecule of Interest (Primary Input)
71
  # --------------------------------------------------
@@ -87,8 +93,10 @@ if top_predict and top_smiles.strip():
87
  if mol:
88
  mw = Descriptors.MolWt(mol)
89
  emb = embeddings_dict.get(top_smiles, torch.randn(256)).unsqueeze(0)
 
90
  with torch.no_grad():
91
- stab = stability_model(emb).item()
 
92
 
93
  res1, res2 = st.columns(2)
94
  res1.metric("Zone-IV Shelf-Life (days)", f"{stab:.2f}")
@@ -146,8 +154,10 @@ if st.sidebar.button("Predict"):
146
  if mol:
147
  mw = Descriptors.MolWt(mol)
148
  emb = embeddings_dict.get(user_smiles, torch.randn(256)).unsqueeze(0)
 
149
  with torch.no_grad():
150
- stab = stability_model(emb).item()
 
151
  st.sidebar.success(f"Zone-IV Shelf-life: {stab:.2f} days")
152
  st.sidebar.info(f"Molecular Weight: {mw:.2f}")
153
  else:
 
65
 
66
  embeddings_dict = load_embeddings()
67
  final_df = load_results()
68
+
69
+ def get_stability_model():
70
+ if "stability_model" not in st.session_state:
71
+ with st.spinner("Loading stability model..."):
72
+ st.session_state.stability_model = load_stability_model()
73
+ return st.session_state.stability_model
74
+
75
  # --------------------------------------------------
76
  # TOP: Molecule of Interest (Primary Input)
77
  # --------------------------------------------------
 
93
  if mol:
94
  mw = Descriptors.MolWt(mol)
95
  emb = embeddings_dict.get(top_smiles, torch.randn(256)).unsqueeze(0)
96
+ model = get_stability_model()
97
  with torch.no_grad():
98
+ stab = model(emb).item()
99
+
100
 
101
  res1, res2 = st.columns(2)
102
  res1.metric("Zone-IV Shelf-Life (days)", f"{stab:.2f}")
 
154
  if mol:
155
  mw = Descriptors.MolWt(mol)
156
  emb = embeddings_dict.get(user_smiles, torch.randn(256)).unsqueeze(0)
157
+ model = get_stability_model()
158
  with torch.no_grad():
159
+ stab = model(emb).item()
160
+
161
  st.sidebar.success(f"Zone-IV Shelf-life: {stab:.2f} days")
162
  st.sidebar.info(f"Molecular Weight: {mw:.2f}")
163
  else: