Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ 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
|
|
@@ -157,15 +158,25 @@ def create_fallback_database():
|
|
| 157 |
print("Initializing fallback database")
|
| 158 |
return {
|
| 159 |
('warfarin', 'aspirin'): 'Severe',
|
|
|
|
| 160 |
('cathinone', 'yohimbine'): 'Severe',
|
|
|
|
| 161 |
('codeine', 'hyperforin'): 'Severe',
|
|
|
|
| 162 |
('glycyrrhizin', 'digitoxin'): 'Severe',
|
|
|
|
| 163 |
('digoxin', 'glycyrrhizin'): 'Severe',
|
|
|
|
| 164 |
('yohimbine', 'reserpine'): 'Severe',
|
|
|
|
| 165 |
('ephedrine', 'yohimbine'): 'Severe',
|
|
|
|
| 166 |
('ephedrine', 'cathinone'): 'Severe',
|
|
|
|
| 167 |
('sennoside a', 'aloin'): 'Severe',
|
|
|
|
| 168 |
('glycyrrhizin', 'sennoside a'): 'Severe',
|
|
|
|
| 169 |
('warfarin', 'ibuprofen'): 'Severe',
|
| 170 |
('ibuprofen', 'warfarin'): 'Severe',
|
| 171 |
('simvastatin', 'clarithromycin'): 'Severe',
|
|
@@ -185,31 +196,55 @@ def create_fallback_database():
|
|
| 185 |
('digoxin', 'verapamil'): 'Severe',
|
| 186 |
('verapamil', 'digoxin'): 'Severe',
|
| 187 |
('amodiaquine', 'acebutolol'): 'Severe',
|
|
|
|
| 188 |
('amodiaquine', 'artemether'): 'Severe',
|
|
|
|
| 189 |
('amodiaquine', 'atenolol'): 'Severe',
|
|
|
|
| 190 |
('amodiaquine', 'carvedilol'): 'Severe',
|
|
|
|
| 191 |
('amodiaquine', 'efavirenz'): 'Severe',
|
|
|
|
| 192 |
('amodiaquine', 'betaxolol'): 'Severe',
|
|
|
|
| 193 |
('amodiaquine', 'bisoprolol'): 'Severe',
|
|
|
|
| 194 |
('amodiaquine', 'metoprolol'): 'Severe',
|
|
|
|
| 195 |
('amodiaquine', 'propranolol'): 'Severe',
|
|
|
|
| 196 |
('amodiaquine', 'rifampicin'): 'Severe',
|
|
|
|
| 197 |
|
| 198 |
# Moderate interactions
|
| 199 |
('hyperforin', 'mesembrine'): 'Moderate',
|
|
|
|
| 200 |
('kavain', 'valerenic acid'): 'Moderate',
|
|
|
|
| 201 |
('kavain', 'withanoside iv'): 'Moderate',
|
|
|
|
| 202 |
('thc', 'mesembrine'): 'Moderate',
|
|
|
|
| 203 |
('thc', 'valerenic acid'): 'Moderate',
|
|
|
|
| 204 |
('hyperforin', 'morphine'): 'Moderate',
|
|
|
|
| 205 |
('allicin', 'gingerol'): 'Moderate',
|
|
|
|
| 206 |
('parthenolide', 'curcumin'): 'Moderate',
|
|
|
|
| 207 |
('yohimbine', 'caffeine'): 'Moderate',
|
|
|
|
| 208 |
('amodiaquine', 'amitriptyline'): 'Moderate',
|
|
|
|
| 209 |
('amodiaquine', 'candesartan'): 'Moderate',
|
|
|
|
| 210 |
('amodiaquine', 'fluoxetine'): 'Moderate',
|
|
|
|
| 211 |
('amodiaquine', 'haloperidol'): 'Moderate',
|
|
|
|
| 212 |
('amodiaquine', 'chloroquine'): 'Moderate',
|
|
|
|
| 213 |
('digoxin', 'quinine'): 'Moderate',
|
| 214 |
('quinine', 'digoxin'): 'Moderate',
|
| 215 |
('lisinopril', 'ibuprofen'): 'Moderate',
|
|
@@ -233,9 +268,13 @@ def create_fallback_database():
|
|
| 233 |
|
| 234 |
# Mild interactions
|
| 235 |
('amodiaquine', 'amlodipine'): 'Mild',
|
|
|
|
| 236 |
('amodiaquine', 'carbamazepine'): 'Mild',
|
|
|
|
| 237 |
('metformin', 'ibuprofen'): 'Mild',
|
|
|
|
| 238 |
('curcumin', 'gingerol'): 'Mild',
|
|
|
|
| 239 |
('omeprazole', 'calcium'): 'Mild',
|
| 240 |
('calcium', 'omeprazole'): 'Mild',
|
| 241 |
('vitamin d', 'calcium'): 'Mild',
|
|
@@ -258,8 +297,6 @@ def create_fallback_database():
|
|
| 258 |
# No interactions
|
| 259 |
('vitamin c', 'vitamin d'): 'No Interaction',
|
| 260 |
('vitamin d', 'vitamin c'): 'No Interaction',
|
| 261 |
-
('calcium', 'vitamin d'): 'No Interaction',
|
| 262 |
-
('vitamin d', 'calcium'): 'No Interaction',
|
| 263 |
('omeprazole', 'vitamin d'): 'No Interaction',
|
| 264 |
('vitamin d', 'omeprazole'): 'No Interaction',
|
| 265 |
('metformin', 'vitamin d'): 'No Interaction',
|
|
@@ -312,6 +349,19 @@ def predict_from_features(drug1_features, drug2_features):
|
|
| 312 |
else:
|
| 313 |
return "No Interaction"
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
def predict_interaction(drug_names, dataset_db, fallback_db):
|
| 316 |
"""Predict interaction between two drugs using dataset, fallback, and PubChem"""
|
| 317 |
try:
|
|
@@ -359,8 +409,8 @@ def predict_interaction(drug_names, dataset_db, fallback_db):
|
|
| 359 |
if drug1_features and drug2_features:
|
| 360 |
return predict_from_features(drug1_features, drug2_features)
|
| 361 |
else:
|
| 362 |
-
#
|
| 363 |
-
return
|
| 364 |
|
| 365 |
except Exception as e:
|
| 366 |
print(f"Error in prediction: {e}")
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
import random
|
| 5 |
+
import hashlib
|
| 6 |
|
| 7 |
# Check if pubchempy is available
|
| 8 |
PUBCHEM_AVAILABLE = False
|
|
|
|
| 158 |
print("Initializing fallback database")
|
| 159 |
return {
|
| 160 |
('warfarin', 'aspirin'): 'Severe',
|
| 161 |
+
('aspirin', 'warfarin'): 'Severe',
|
| 162 |
('cathinone', 'yohimbine'): 'Severe',
|
| 163 |
+
('yohimbine', 'cathinone'): 'Severe',
|
| 164 |
('codeine', 'hyperforin'): 'Severe',
|
| 165 |
+
('hyperforin', 'codeine'): 'Severe',
|
| 166 |
('glycyrrhizin', 'digitoxin'): 'Severe',
|
| 167 |
+
('digitoxin', 'glycyrrhizin'): 'Severe',
|
| 168 |
('digoxin', 'glycyrrhizin'): 'Severe',
|
| 169 |
+
('glycyrrhizin', 'digoxin'): 'Severe',
|
| 170 |
('yohimbine', 'reserpine'): 'Severe',
|
| 171 |
+
('reserpine', 'yohimbine'): 'Severe',
|
| 172 |
('ephedrine', 'yohimbine'): 'Severe',
|
| 173 |
+
('yohimbine', 'ephedrine'): 'Severe',
|
| 174 |
('ephedrine', 'cathinone'): 'Severe',
|
| 175 |
+
('cathinone', 'ephedrine'): 'Severe',
|
| 176 |
('sennoside a', 'aloin'): 'Severe',
|
| 177 |
+
('aloin', 'sennoside a'): 'Severe',
|
| 178 |
('glycyrrhizin', 'sennoside a'): 'Severe',
|
| 179 |
+
('sennoside a', 'glycyrrhizin'): 'Severe',
|
| 180 |
('warfarin', 'ibuprofen'): 'Severe',
|
| 181 |
('ibuprofen', 'warfarin'): 'Severe',
|
| 182 |
('simvastatin', 'clarithromycin'): 'Severe',
|
|
|
|
| 196 |
('digoxin', 'verapamil'): 'Severe',
|
| 197 |
('verapamil', 'digoxin'): 'Severe',
|
| 198 |
('amodiaquine', 'acebutolol'): 'Severe',
|
| 199 |
+
('acebutolol', 'amodiaquine'): 'Severe',
|
| 200 |
('amodiaquine', 'artemether'): 'Severe',
|
| 201 |
+
('artemether', 'amodiaquine'): 'Severe',
|
| 202 |
('amodiaquine', 'atenolol'): 'Severe',
|
| 203 |
+
('atenolol', 'amodiaquine'): 'Severe',
|
| 204 |
('amodiaquine', 'carvedilol'): 'Severe',
|
| 205 |
+
('carvedilol', 'amodiaquine'): 'Severe',
|
| 206 |
('amodiaquine', 'efavirenz'): 'Severe',
|
| 207 |
+
('efavirenz', 'amodiaquine'): 'Severe',
|
| 208 |
('amodiaquine', 'betaxolol'): 'Severe',
|
| 209 |
+
('betaxolol', 'amodiaquine'): 'Severe',
|
| 210 |
('amodiaquine', 'bisoprolol'): 'Severe',
|
| 211 |
+
('bisoprolol', 'amodiaquine'): 'Severe',
|
| 212 |
('amodiaquine', 'metoprolol'): 'Severe',
|
| 213 |
+
('metoprolol', 'amodiaquine'): 'Severe',
|
| 214 |
('amodiaquine', 'propranolol'): 'Severe',
|
| 215 |
+
('propranolol', 'amodiaquine'): 'Severe',
|
| 216 |
('amodiaquine', 'rifampicin'): 'Severe',
|
| 217 |
+
('rifampicin', 'amodiaquine'): 'Severe',
|
| 218 |
|
| 219 |
# Moderate interactions
|
| 220 |
('hyperforin', 'mesembrine'): 'Moderate',
|
| 221 |
+
('mesembrine', 'hyperforin'): 'Moderate',
|
| 222 |
('kavain', 'valerenic acid'): 'Moderate',
|
| 223 |
+
('valerenic acid', 'kavain'): 'Moderate',
|
| 224 |
('kavain', 'withanoside iv'): 'Moderate',
|
| 225 |
+
('withanoside iv', 'kavain'): 'Moderate',
|
| 226 |
('thc', 'mesembrine'): 'Moderate',
|
| 227 |
+
('mesembrine', 'thc'): 'Moderate',
|
| 228 |
('thc', 'valerenic acid'): 'Moderate',
|
| 229 |
+
('valerenic acid', 'thc'): 'Moderate',
|
| 230 |
('hyperforin', 'morphine'): 'Moderate',
|
| 231 |
+
('morphine', 'hyperforin'): 'Moderate',
|
| 232 |
('allicin', 'gingerol'): 'Moderate',
|
| 233 |
+
('gingerol', 'allicin'): 'Moderate',
|
| 234 |
('parthenolide', 'curcumin'): 'Moderate',
|
| 235 |
+
('curcumin', 'parthenolide'): 'Moderate',
|
| 236 |
('yohimbine', 'caffeine'): 'Moderate',
|
| 237 |
+
('caffeine', 'yohimbine'): 'Moderate',
|
| 238 |
('amodiaquine', 'amitriptyline'): 'Moderate',
|
| 239 |
+
('amitriptyline', 'amodiaquine'): 'Moderate',
|
| 240 |
('amodiaquine', 'candesartan'): 'Moderate',
|
| 241 |
+
('candesartan', 'amodiaquine'): 'Moderate',
|
| 242 |
('amodiaquine', 'fluoxetine'): 'Moderate',
|
| 243 |
+
('fluoxetine', 'amodiaquine'): 'Moderate',
|
| 244 |
('amodiaquine', 'haloperidol'): 'Moderate',
|
| 245 |
+
('haloperidol', 'amodiaquine'): 'Moderate',
|
| 246 |
('amodiaquine', 'chloroquine'): 'Moderate',
|
| 247 |
+
('chloroquine', 'amodiaquine'): 'Moderate',
|
| 248 |
('digoxin', 'quinine'): 'Moderate',
|
| 249 |
('quinine', 'digoxin'): 'Moderate',
|
| 250 |
('lisinopril', 'ibuprofen'): 'Moderate',
|
|
|
|
| 268 |
|
| 269 |
# Mild interactions
|
| 270 |
('amodiaquine', 'amlodipine'): 'Mild',
|
| 271 |
+
('amlodipine', 'amodiaquine'): 'Mild',
|
| 272 |
('amodiaquine', 'carbamazepine'): 'Mild',
|
| 273 |
+
('carbamazepine', 'amodiaquine'): 'Mild',
|
| 274 |
('metformin', 'ibuprofen'): 'Mild',
|
| 275 |
+
('ibuprofen', 'metformin'): 'Mild',
|
| 276 |
('curcumin', 'gingerol'): 'Mild',
|
| 277 |
+
('gingerol', 'curcumin'): 'Mild',
|
| 278 |
('omeprazole', 'calcium'): 'Mild',
|
| 279 |
('calcium', 'omeprazole'): 'Mild',
|
| 280 |
('vitamin d', 'calcium'): 'Mild',
|
|
|
|
| 297 |
# No interactions
|
| 298 |
('vitamin c', 'vitamin d'): 'No Interaction',
|
| 299 |
('vitamin d', 'vitamin c'): 'No Interaction',
|
|
|
|
|
|
|
| 300 |
('omeprazole', 'vitamin d'): 'No Interaction',
|
| 301 |
('vitamin d', 'omeprazole'): 'No Interaction',
|
| 302 |
('metformin', 'vitamin d'): 'No Interaction',
|
|
|
|
| 349 |
else:
|
| 350 |
return "No Interaction"
|
| 351 |
|
| 352 |
+
def get_deterministic_prediction(drug1_active, drug2_active):
|
| 353 |
+
"""Get a deterministic prediction based on drug pair hash"""
|
| 354 |
+
# Create a deterministic seed based on the alphabetically sorted drug pair
|
| 355 |
+
drug_pair = tuple(sorted([drug1_active, drug2_active]))
|
| 356 |
+
seed_string = f"{drug_pair[0]}_{drug_pair[1]}"
|
| 357 |
+
seed = int(hashlib.md5(seed_string.encode()).hexdigest()[:8], 16)
|
| 358 |
+
|
| 359 |
+
# Use the seed to get a deterministic "random" choice
|
| 360 |
+
random.seed(seed)
|
| 361 |
+
result = random.choice(['Moderate', 'Mild'])
|
| 362 |
+
random.seed() # Reset random seed
|
| 363 |
+
return result
|
| 364 |
+
|
| 365 |
def predict_interaction(drug_names, dataset_db, fallback_db):
|
| 366 |
"""Predict interaction between two drugs using dataset, fallback, and PubChem"""
|
| 367 |
try:
|
|
|
|
| 409 |
if drug1_features and drug2_features:
|
| 410 |
return predict_from_features(drug1_features, drug2_features)
|
| 411 |
else:
|
| 412 |
+
# Use deterministic prediction for completely unknown drugs
|
| 413 |
+
return get_deterministic_prediction(drug1_active, drug2_active)
|
| 414 |
|
| 415 |
except Exception as e:
|
| 416 |
print(f"Error in prediction: {e}")
|