transpolymer commited on
Commit
833f4a5
·
verified ·
1 Parent(s): a9fbb73

Update prediction.py

Browse files
Files changed (1) hide show
  1. prediction.py +13 -6
prediction.py CHANGED
@@ -76,16 +76,23 @@ def is_valid_smiles(smiles):
76
  return mol is not None
77
 
78
  # Function to save prediction to MongoDB
79
- def save_to_db(smiles_input, predictions):
80
- db = get_database()
81
- collection = db["polymers"] # your collection
 
 
 
82
  doc = {
83
- "smiles": smiles_input,
84
- "predictions": predictions,
85
- "timestamp": datetime.datetime.utcnow()
86
  }
 
 
 
87
  collection.insert_one(doc)
88
 
 
89
  # Prediction Page UI
90
  def show():
91
  st.markdown("<h1 style='text-align: center; color: #4CAF50;'>🔬 Polymer Property Prediction</h1>", unsafe_allow_html=True)
 
76
  return mol is not None
77
 
78
  # Function to save prediction to MongoDB
79
+ from datetime import datetime
80
+
81
+ def save_to_db(smiles, predictions):
82
+ # Convert all prediction values to native Python float
83
+ predictions_clean = {k: float(v) for k, v in predictions.items()}
84
+
85
  doc = {
86
+ "smiles": smiles,
87
+ "predictions": predictions_clean,
88
+ "timestamp": datetime.now()
89
  }
90
+
91
+ db = get_database()
92
+ collection = db["polymer_predictions"]
93
  collection.insert_one(doc)
94
 
95
+
96
  # Prediction Page UI
97
  def show():
98
  st.markdown("<h1 style='text-align: center; color: #4CAF50;'>🔬 Polymer Property Prediction</h1>", unsafe_allow_html=True)