Spaces:
Running
Running
Update prediction.py
Browse files- 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 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
82 |
doc = {
|
83 |
-
"smiles":
|
84 |
-
"predictions":
|
85 |
-
"timestamp": datetime.
|
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)
|