Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# Check if pubchempy is available
|
| 6 |
PUBCHEM_AVAILABLE = False
|
|
@@ -171,8 +172,10 @@ def get_pubchem_features(drug_name):
|
|
| 171 |
'molecular_weight': compound.molecular_weight,
|
| 172 |
'xlogp': compound.xlogp if compound.xlogp else 0,
|
| 173 |
'tpsa': compound.tpsa if compound.tpsa else 0,
|
| 174 |
-
'
|
| 175 |
-
'
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
except Exception as e:
|
| 178 |
print(f"Error fetching PubChem data for {drug_name}: {e}")
|
|
@@ -181,7 +184,8 @@ def get_pubchem_features(drug_name):
|
|
| 181 |
# Simple prediction based on PubChem features (placeholder logic)
|
| 182 |
def predict_from_features(drug1_features, drug2_features):
|
| 183 |
if not PUBCHEM_AVAILABLE or not drug1_features or not drug2_features:
|
| 184 |
-
|
|
|
|
| 185 |
|
| 186 |
weight_diff = abs(drug1_features['molecular_weight'] - drug2_features['molecular_weight'])
|
| 187 |
if weight_diff > 200: # Arbitrary threshold for severe interaction
|
|
@@ -220,7 +224,8 @@ def predict_interaction(drug_names, dataset_db, fallback_db):
|
|
| 220 |
if drug1_features and drug2_features:
|
| 221 |
return predict_from_features(drug1_features, drug2_features)
|
| 222 |
else:
|
| 223 |
-
|
|
|
|
| 224 |
|
| 225 |
except Exception:
|
| 226 |
return "No Interaction"
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
# Check if pubchempy is available
|
| 7 |
PUBCHEM_AVAILABLE = False
|
|
|
|
| 172 |
'molecular_weight': compound.molecular_weight,
|
| 173 |
'xlogp': compound.xlogp if compound.xlogp else 0,
|
| 174 |
'tpsa': compound.tpsa if compound.tpsa else 0,
|
| 175 |
+
'canonical_smiles': compound.canonical_smiles,
|
| 176 |
+
'canonical_smiles_2': compound.canonical_smiles_2,
|
| 177 |
+
'molecular_formula': compound.molecular_formula,
|
| 178 |
+
'molecular_formula_2': compound.molecular_formula_2
|
| 179 |
}
|
| 180 |
except Exception as e:
|
| 181 |
print(f"Error fetching PubChem data for {drug_name}: {e}")
|
|
|
|
| 184 |
# Simple prediction based on PubChem features (placeholder logic)
|
| 185 |
def predict_from_features(drug1_features, drug2_features):
|
| 186 |
if not PUBCHEM_AVAILABLE or not drug1_features or not drug2_features:
|
| 187 |
+
# Balanced random choice for unknown drugs
|
| 188 |
+
return random.choice(['Moderate', 'Mild'])
|
| 189 |
|
| 190 |
weight_diff = abs(drug1_features['molecular_weight'] - drug2_features['molecular_weight'])
|
| 191 |
if weight_diff > 200: # Arbitrary threshold for severe interaction
|
|
|
|
| 224 |
if drug1_features and drug2_features:
|
| 225 |
return predict_from_features(drug1_features, drug2_features)
|
| 226 |
else:
|
| 227 |
+
# Balanced random choice for completely unknown drugs
|
| 228 |
+
return random.choice(['Moderate', 'Mild'])
|
| 229 |
|
| 230 |
except Exception:
|
| 231 |
return "No Interaction"
|