Fredaaaaaa commited on
Commit
0eb7515
·
verified ·
1 Parent(s): 7e1c5ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -19
app.py CHANGED
@@ -21,14 +21,13 @@ def load_drug_interaction_dataset():
21
  df = pd.read_csv(dataset_path)
22
  print(f"Dataset columns: {df.columns.tolist()}")
23
  print(f"Dataset shape: {df.shape}")
24
- print(f"First few rows:\n{df.head().to_string()}")
25
 
26
  # Create interaction dictionary using your exact column names
27
  interaction_db = {}
28
  count = 0
29
- severe_count = 0 # Track severe interactions
30
 
31
- for index, row in df.iterrows():
32
  try:
33
  # Use your exact column names
34
  drug1 = str(row['Drug 1_normalized']).lower().strip()
@@ -39,7 +38,6 @@ def load_drug_interaction_dataset():
39
  if (not all([drug1, drug2, severity]) or
40
  drug1 == 'nan' or drug2 == 'nan' or
41
  severity == 'nan' or severity.lower() == 'none'):
42
- print(f"Skipping invalid row {index}: {drug1}, {drug2}, {severity}")
43
  continue
44
 
45
  # Clean up severity labels
@@ -49,19 +47,14 @@ def load_drug_interaction_dataset():
49
 
50
  # Add both orders to the dictionary
51
  interaction_db[(drug1, drug2)] = severity
52
- interaction_db[(drug2, drug1)] = severity
53
  count += 1
54
- if severity.lower() == 'severe':
55
- severe_count += 1
56
- if drug1 == 'warfarin' and drug2 == 'aspirin':
57
- print(f"Found Warfarin, Aspirin at row {index} with severity: {severity}")
58
 
59
  except Exception as e:
60
- print(f"Error processing row {index}: {e}")
61
  continue
62
 
63
  print(f"✅ Successfully loaded {count} drug interactions from dataset")
64
- print(f"Number of 'Severe' interactions: {severe_count}")
65
  print(f"Sample interactions: {list(interaction_db.items())[:5]}")
66
  return interaction_db
67
 
@@ -79,12 +72,86 @@ def create_fallback_database():
79
  ('ibuprofen', 'warfarin'): 'Severe',
80
  ('simvastatin', 'clarithromycin'): 'Severe',
81
  ('clarithromycin', 'simvastatin'): 'Severe',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  ('digoxin', 'quinine'): 'Moderate',
83
  ('quinine', 'digoxin'): 'Moderate',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ('metformin', 'ibuprofen'): 'Mild',
85
  ('ibuprofen', 'metformin'): 'Mild',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ('vitamin c', 'vitamin d'): 'No Interaction',
87
  ('vitamin d', 'vitamin c'): 'No Interaction',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
 
90
  # Load your dataset
@@ -121,14 +188,8 @@ def predict_interaction(drug_names):
121
  else:
122
  return f"📊 **INTERACTION LEVEL**: {prediction}"
123
  else:
124
- # Try to find similar drugs for debugging
125
- found_drugs = set()
126
- for d1, d2 in interaction_db.keys():
127
- found_drugs.add(d1)
128
- found_drugs.add(d2)
129
-
130
- print(f"Not found. Available drugs: {sorted(list(found_drugs))[:20]}...")
131
- print(f"Keys in interaction_db: {list(interaction_db.keys())[:5]}... (total {len(interaction_db)})")
132
 
133
  # Check if either drug exists in the database
134
  drug1_exists = any(d1 == drug1 or d2 == drug1 for d1, d2 in interaction_db.keys())
 
21
  df = pd.read_csv(dataset_path)
22
  print(f"Dataset columns: {df.columns.tolist()}")
23
  print(f"Dataset shape: {df.shape}")
24
+ print(f"First few rows:\n{df.head()}")
25
 
26
  # Create interaction dictionary using your exact column names
27
  interaction_db = {}
28
  count = 0
 
29
 
30
+ for _, row in df.iterrows():
31
  try:
32
  # Use your exact column names
33
  drug1 = str(row['Drug 1_normalized']).lower().strip()
 
38
  if (not all([drug1, drug2, severity]) or
39
  drug1 == 'nan' or drug2 == 'nan' or
40
  severity == 'nan' or severity.lower() == 'none'):
 
41
  continue
42
 
43
  # Clean up severity labels
 
47
 
48
  # Add both orders to the dictionary
49
  interaction_db[(drug1, drug2)] = severity
50
+ interaction_db[(drug2, drug1)] = severity # Add reverse order
51
  count += 1
 
 
 
 
52
 
53
  except Exception as e:
54
+ print(f"Error processing row {_}: {e}")
55
  continue
56
 
57
  print(f"✅ Successfully loaded {count} drug interactions from dataset")
 
58
  print(f"Sample interactions: {list(interaction_db.items())[:5]}")
59
  return interaction_db
60
 
 
72
  ('ibuprofen', 'warfarin'): 'Severe',
73
  ('simvastatin', 'clarithromycin'): 'Severe',
74
  ('clarithromycin', 'simvastatin'): 'Severe',
75
+ ('clopidogrel', 'omeprazole'): 'Severe',
76
+ ('omeprazole', 'clopidogrel'): 'Severe',
77
+ ('methotrexate', 'naproxen'): 'Severe',
78
+ ('naproxen', 'methotrexate'): 'Severe',
79
+ ('lithium', 'ibuprofen'): 'Severe',
80
+ ('ibuprofen', 'lithium'): 'Severe',
81
+ ('ssri', 'maoi'): 'Severe',
82
+ ('maoi', 'ssri'): 'Severe',
83
+ ('simvastatin', 'verapamil'): 'Severe',
84
+ ('verapamil', 'simvastatin'): 'Severe',
85
+ ('warfarin', 'fluconazole'): 'Severe',
86
+ ('fluconazole', 'warfarin'): 'Severe',
87
+ ('digoxin', 'verapamil'): 'Severe',
88
+ ('verapamil', 'digoxin'): 'Severe',
89
+
90
+ # Moderate interactions
91
  ('digoxin', 'quinine'): 'Moderate',
92
  ('quinine', 'digoxin'): 'Moderate',
93
+ ('lisinopril', 'ibuprofen'): 'Moderate',
94
+ ('ibuprofen', 'lisinopril'): 'Moderate',
95
+ ('metformin', 'alcohol'): 'Moderate',
96
+ ('alcohol', 'metformin'): 'Moderate',
97
+ ('levothyroxine', 'calcium'): 'Moderate',
98
+ ('calcium', 'levothyroxine'): 'Moderate',
99
+ ('atorvastatin', 'orange juice'): 'Moderate',
100
+ ('orange juice', 'atorvastatin'): 'Moderate',
101
+ ('phenytoin', 'warfarin'): 'Moderate',
102
+ ('warfarin', 'phenytoin'): 'Moderate',
103
+ ('theophylline', 'ciprofloxacin'): 'Moderate',
104
+ ('ciprofloxacin', 'theophylline'): 'Moderate',
105
+ ('warfarin', 'acetaminophen'): 'Moderate',
106
+ ('acetaminophen', 'warfarin'): 'Moderate',
107
+ ('metoprolol', 'verapamil'): 'Moderate',
108
+ ('verapamil', 'metoprolol'): 'Moderate',
109
+ ('spironolactone', 'digoxin'): 'Moderate',
110
+ ('digoxin', 'spironolactone'): 'Moderate',
111
+
112
+ # Mild interactions
113
  ('metformin', 'ibuprofen'): 'Mild',
114
  ('ibuprofen', 'metformin'): 'Mild',
115
+ ('omeprazole', 'calcium'): 'Mild',
116
+ ('calcium', 'omeprazole'): 'Mild',
117
+ ('vitamin d', 'calcium'): 'Mild',
118
+ ('calcium', 'vitamin d'): 'Mild',
119
+ ('aspirin', 'vitamin c'): 'Mild',
120
+ ('vitamin c', 'aspirin'): 'Mild',
121
+ ('atorvastatin', 'vitamin d'): 'Mild',
122
+ ('vitamin d', 'atorvastatin'): 'Mild',
123
+ ('metformin', 'vitamin b12'): 'Mild',
124
+ ('vitamin b12', 'metformin'): 'Mild',
125
+ ('omeprazole', 'vitamin b12'): 'Mild',
126
+ ('vitamin b12', 'omeprazole'): 'Mild',
127
+ ('aspirin', 'ginger'): 'Mild',
128
+ ('ginger', 'aspirin'): 'Mild',
129
+ ('warfarin', 'green tea'): 'Mild',
130
+ ('green tea', 'warfarin'): 'Mild',
131
+ ('levothyroxine', 'iron'): 'Mild',
132
+ ('iron', 'levothyroxine'): 'Mild',
133
+
134
+ # No interactions
135
  ('vitamin c', 'vitamin d'): 'No Interaction',
136
  ('vitamin d', 'vitamin c'): 'No Interaction',
137
+ ('calcium', 'vitamin d'): 'No Interaction',
138
+ ('vitamin d', 'calcium'): 'No Interaction',
139
+ ('omeprazole', 'vitamin d'): 'No Interaction',
140
+ ('vitamin d', 'omeprazole'): 'No Interaction',
141
+ ('metformin', 'vitamin d'): 'No Interaction',
142
+ ('vitamin d', 'metformin'): 'No Interaction',
143
+ ('aspirin', 'vitamin e'): 'No Interaction',
144
+ ('vitamin e', 'aspirin'): 'No Interaction',
145
+ ('atorvastatin', 'coenzyme q10'): 'No Interaction',
146
+ ('coenzyme q10', 'atorvastatin'): 'No Interaction',
147
+ ('levothyroxine', 'vitamin d'): 'No Interaction',
148
+ ('vitamin d', 'levothyroxine'): 'No Interaction',
149
+ ('metoprolol', 'magnesium'): 'No Interaction',
150
+ ('magnesium', 'metoprolol'): 'No Interaction',
151
+ ('lisinopril', 'potassium'): 'No Interaction',
152
+ ('potassium', 'lisinopril'): 'No Interaction',
153
+ ('simvastatin', 'vitamin e'): 'No Interaction',
154
+ ('vitamin e', 'simvastatin'): 'No Interaction',
155
  }
156
 
157
  # Load your dataset
 
188
  else:
189
  return f"📊 **INTERACTION LEVEL**: {prediction}"
190
  else:
191
+ # Log all available keys for debugging
192
+ print(f"Keys in interaction_db: {list(interaction_db.keys())[:10]}... (total {len(interaction_db)})")
 
 
 
 
 
 
193
 
194
  # Check if either drug exists in the database
195
  drug1_exists = any(d1 == drug1 or d2 == drug1 for d1, d2 in interaction_db.keys())