Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -163,50 +163,10 @@ def get_drug_features_from_dataset(drug1, drug2, df):
|
|
| 163 |
return drug_data.iloc[0] # Returns the first match
|
| 164 |
else:
|
| 165 |
print(f"Drugs '{drug1}' and '{drug2}' not found in the dataset.")
|
| 166 |
-
# Debug print to help identify any potential matches
|
| 167 |
-
for col in drug_columns:
|
| 168 |
-
if col in df.columns:
|
| 169 |
-
if col.endswith('1') or col.endswith('_1') or col.endswith(' 1'):
|
| 170 |
-
matching_rows = df[df[col].astype(str).str.lower().str.strip() == drug1]
|
| 171 |
-
if not matching_rows.empty:
|
| 172 |
-
print(f"Found '{drug1}' in column '{col}' in {len(matching_rows)} rows")
|
| 173 |
-
if col.endswith('2') or col.endswith('_2') or col.endswith(' 2'):
|
| 174 |
-
matching_rows = df[df[col].astype(str).str.lower().str.strip() == drug2]
|
| 175 |
-
if not matching_rows.empty:
|
| 176 |
-
print(f"Found '{drug2}' in column '{col}' in {len(matching_rows)} rows")
|
| 177 |
return None
|
| 178 |
|
| 179 |
except Exception as e:
|
| 180 |
print(f"Error searching for drugs in dataset: {e}")
|
| 181 |
-
# Print column names to help debug
|
| 182 |
-
print(f"Available columns: {df.columns.tolist()}")
|
| 183 |
-
return None
|
| 184 |
-
|
| 185 |
-
# Function to fetch drug features from PubChem API
|
| 186 |
-
def get_drug_features_from_api(drug_name):
|
| 187 |
-
drug_name = clean_drug_name(drug_name)
|
| 188 |
-
print(f"Fetching data for '{drug_name}' from PubChem API...")
|
| 189 |
-
|
| 190 |
-
try:
|
| 191 |
-
api_url = f'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{drug_name}/property/SMILES,MolecularFormula,MolecularWeight/JSON'
|
| 192 |
-
response = requests.get(api_url, timeout=10)
|
| 193 |
-
|
| 194 |
-
if response.status_code == 200:
|
| 195 |
-
data = response.json()
|
| 196 |
-
if 'PropertyTable' in data and 'Properties' in data['PropertyTable'] and len(data['PropertyTable']['Properties']) > 0:
|
| 197 |
-
properties = data['PropertyTable']['Properties'][0]
|
| 198 |
-
return {
|
| 199 |
-
'SMILES': properties.get('SMILES', 'No data'),
|
| 200 |
-
'MolecularFormula': properties.get('MolecularFormula', 'No data'),
|
| 201 |
-
'MolecularWeight': properties.get('MolecularWeight', 'No data'),
|
| 202 |
-
'pharmacodynamics': 'Data from API - limited information',
|
| 203 |
-
'toxicity': 'Data from API - limited information'
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
print(f"Could not fetch data for '{drug_name}' from PubChem (Status: {response.status_code})")
|
| 207 |
-
return None
|
| 208 |
-
except Exception as e:
|
| 209 |
-
print(f"API Error for '{drug_name}': {e}")
|
| 210 |
return None
|
| 211 |
|
| 212 |
# Function to predict the severity based on the drugs' data
|
|
@@ -378,4 +338,4 @@ interface = gr.Interface(
|
|
| 378 |
|
| 379 |
# Launch the interface
|
| 380 |
if __name__ == "__main__":
|
| 381 |
-
interface.launch(debug=True)
|
|
|
|
| 163 |
return drug_data.iloc[0] # Returns the first match
|
| 164 |
else:
|
| 165 |
print(f"Drugs '{drug1}' and '{drug2}' not found in the dataset.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
return None
|
| 167 |
|
| 168 |
except Exception as e:
|
| 169 |
print(f"Error searching for drugs in dataset: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
return None
|
| 171 |
|
| 172 |
# Function to predict the severity based on the drugs' data
|
|
|
|
| 338 |
|
| 339 |
# Launch the interface
|
| 340 |
if __name__ == "__main__":
|
| 341 |
+
interface.launch(debug=True)
|