Update app.py
Browse files
app.py
CHANGED
|
@@ -1,123 +1,148 @@
|
|
| 1 |
-
# -----------------------------
|
| 2 |
# IMPORTS & CONFIGURATION
|
| 3 |
# -----------------------------
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
import seaborn as sns
|
| 8 |
import logging
|
| 9 |
import re
|
| 10 |
-
import
|
| 11 |
-
from
|
| 12 |
-
from rdkit.Chem import Draw
|
| 13 |
|
| 14 |
-
# Configure logging for
|
| 15 |
logging.basicConfig(
|
| 16 |
level=logging.INFO,
|
| 17 |
-
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 18 |
handlers=[logging.FileHandler("pris_debug.log"), logging.StreamHandler()]
|
| 19 |
)
|
| 20 |
logger = logging.getLogger("PRIS")
|
| 21 |
|
| 22 |
# -----------------------------
|
| 23 |
-
#
|
| 24 |
# -----------------------------
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"canonical_smiles": "CC(=O)OC1=CC=CC=C1C(=O)O", # Valid SMILES for Aspirin
|
| 31 |
-
"molecular_weight": "180.16",
|
| 32 |
-
"logp": "N/A"
|
| 33 |
-
},
|
| 34 |
-
"ibuprofen": {
|
| 35 |
-
"molecular_formula": "C13H18O2",
|
| 36 |
-
"iupac_name": "2-(4-isobutylphenyl)propanoic acid",
|
| 37 |
-
"canonical_smiles": "CC(C)Cc1ccc(cc1)C(C)C(=O)O",
|
| 38 |
-
"molecular_weight": "206.28",
|
| 39 |
-
"logp": "3.97"
|
| 40 |
-
}
|
| 41 |
}
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
"
|
| 46 |
-
{
|
| 47 |
-
"protocolSection": {
|
| 48 |
-
"identificationModule": {"briefTitle": "A Study of Novel Therapeutics in Diabetes"},
|
| 49 |
-
"statusModule": {"overallStatus": "Completed"},
|
| 50 |
-
"designModule": {"phases": ["Phase II"], "enrollmentInfo": {"count": "120"}}
|
| 51 |
-
}
|
| 52 |
-
},
|
| 53 |
-
{
|
| 54 |
-
"protocolSection": {
|
| 55 |
-
"identificationModule": {"briefTitle": "Evaluation of Biomarkers in Diabetic Patients"},
|
| 56 |
-
"statusModule": {"overallStatus": "Recruiting"},
|
| 57 |
-
"designModule": {"phases": ["Phase I"], "enrollmentInfo": {"count": "60"}}
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
],
|
| 61 |
-
"cancer": [
|
| 62 |
-
{
|
| 63 |
-
"protocolSection": {
|
| 64 |
-
"identificationModule": {"briefTitle": "Immunotherapy Trials in Advanced Cancer"},
|
| 65 |
-
"statusModule": {"overallStatus": "Active, not recruiting"},
|
| 66 |
-
"designModule": {"phases": ["Phase III"], "enrollmentInfo": {"count": "250"}}
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
]
|
| 70 |
}
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# -----------------------------
|
| 73 |
# CORE INFRASTRUCTURE
|
| 74 |
# -----------------------------
|
| 75 |
class PharmaResearchEngine:
|
| 76 |
-
"""
|
| 77 |
-
|
| 78 |
-
This engine simulates data retrieval without any external API calls.
|
| 79 |
-
"""
|
| 80 |
def __init__(self):
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
def get_compound_profile(self, identifier: str) ->
|
| 85 |
"""
|
| 86 |
-
Retrieve a
|
| 87 |
-
|
| 88 |
"""
|
| 89 |
if not self._is_valid_compound_input(identifier):
|
| 90 |
msg = (f"The input '{identifier}' appears to reference a disease term rather than a chemical compound. "
|
| 91 |
"For disease-related inquiries, please use the Clinical Trial Analytics module.")
|
| 92 |
logger.warning(msg)
|
| 93 |
st.error(msg)
|
| 94 |
-
return
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
"""
|
| 108 |
-
Determines
|
|
|
|
| 109 |
Rejects inputs containing known disease terms.
|
| 110 |
"""
|
| 111 |
input_lower = user_input.lower().strip()
|
|
|
|
| 112 |
disease_terms = ['diabetes', 'cancer', 'hypertension', 'asthma']
|
| 113 |
if any(term in input_lower for term in disease_terms):
|
| 114 |
return False
|
| 115 |
-
|
|
|
|
| 116 |
if re.search(r"[=\(\)#]", user_input):
|
| 117 |
return True
|
| 118 |
-
|
|
|
|
| 119 |
if re.match(r'^[A-Za-z0-9\s\-]+$', user_input):
|
| 120 |
return True
|
|
|
|
| 121 |
return False
|
| 122 |
|
| 123 |
# -----------------------------
|
|
@@ -125,83 +150,105 @@ class PharmaResearchEngine:
|
|
| 125 |
# -----------------------------
|
| 126 |
class ClinicalIntelligence:
|
| 127 |
"""
|
| 128 |
-
Module for clinical trial
|
|
|
|
| 129 |
"""
|
|
|
|
| 130 |
def __init__(self):
|
| 131 |
self.engine = PharmaResearchEngine()
|
| 132 |
-
|
| 133 |
-
def get_trial_landscape(self, query: str) ->
|
| 134 |
-
"""
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
if key in FALLBACK_CLINICAL_DATA:
|
| 140 |
-
logger.info(f"Using fallback clinical data for query '{query}'.")
|
| 141 |
-
return FALLBACK_CLINICAL_DATA[key]
|
| 142 |
-
else:
|
| 143 |
-
msg = f"No clinical trial data available for '{query}'."
|
| 144 |
-
logger.error(msg)
|
| 145 |
-
st.error("Failed to retrieve clinical trials. Please try a different query.")
|
| 146 |
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
class AIDrugInnovator:
|
| 149 |
"""
|
| 150 |
-
|
| 151 |
"""
|
|
|
|
| 152 |
def __init__(self):
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
def generate_strategy(self, target: str, strategy: str) -> str:
|
| 157 |
-
"""
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
-
|
| 165 |
-
-
|
| 166 |
-
-
|
| 167 |
-
-
|
| 168 |
|
| 169 |
-
|
| 170 |
-
-
|
| 171 |
-
-
|
| 172 |
-
-
|
| 173 |
-
-
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
-
-
|
| 177 |
-
-
|
| 178 |
-
-
|
| 179 |
-
-
|
| 180 |
-
- **Adaptive Designs:** Incorporate adaptive trial designs for efficiency.
|
| 181 |
|
| 182 |
-
|
| 183 |
-
-
|
| 184 |
-
-
|
| 185 |
-
-
|
| 186 |
-
-
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
# -----------------------------
|
| 197 |
# STREAMLIT INTERFACE
|
| 198 |
# -----------------------------
|
| 199 |
class PharmaResearchInterface:
|
| 200 |
"""
|
| 201 |
-
Streamlit interface for the Pharma Research Intelligence Suite
|
|
|
|
| 202 |
"""
|
|
|
|
| 203 |
def __init__(self):
|
| 204 |
-
self.engine = PharmaResearchEngine()
|
| 205 |
self.clinical_intel = ClinicalIntelligence()
|
| 206 |
self.ai_innovator = AIDrugInnovator()
|
| 207 |
self._configure_page()
|
|
@@ -213,17 +260,17 @@ class PharmaResearchInterface:
|
|
| 213 |
initial_sidebar_state="expanded"
|
| 214 |
)
|
| 215 |
st.markdown("""
|
| 216 |
-
|
| 217 |
-
.main {background-color: #f0f2f6;
|
| 218 |
-
.stAlert {padding: 20px;
|
| 219 |
-
.reportview-container .markdown-text-container {font-family: 'Helvetica Neue', Arial, sans-serif
|
| 220 |
-
|
| 221 |
-
|
| 222 |
|
| 223 |
def render(self):
|
| 224 |
st.title("Next-Generation Pharmaceutical Research Intelligence Suite")
|
| 225 |
self._render_navigation()
|
| 226 |
-
|
| 227 |
def _render_navigation(self):
|
| 228 |
tabs = st.tabs([
|
| 229 |
"🚀 Drug Innovation",
|
|
@@ -248,20 +295,21 @@ class PharmaResearchInterface:
|
|
| 248 |
col1, col2 = st.columns([1, 3])
|
| 249 |
with col1:
|
| 250 |
target = st.text_input("Target Pathobiology:", placeholder="e.g., EGFR mutant NSCLC")
|
| 251 |
-
|
|
|
|
| 252 |
if st.button("Generate Development Blueprint"):
|
| 253 |
with st.spinner("Formulating strategic plan..."):
|
| 254 |
-
blueprint = self.ai_innovator.generate_strategy(target,
|
| 255 |
st.markdown(blueprint, unsafe_allow_html=True)
|
| 256 |
|
| 257 |
def _trial_analytics(self):
|
| 258 |
st.header("Clinical Trial Landscape Analysis")
|
| 259 |
-
|
| 260 |
if st.button("Analyze Trial Landscape"):
|
| 261 |
with st.spinner("Fetching trial data..."):
|
| 262 |
-
trials = self.clinical_intel.get_trial_landscape(
|
| 263 |
if trials:
|
| 264 |
-
st.subheader("Top Clinical Trials")
|
| 265 |
trial_data = []
|
| 266 |
for study in trials:
|
| 267 |
title = study.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A")
|
|
@@ -288,16 +336,16 @@ class PharmaResearchInterface:
|
|
| 288 |
|
| 289 |
def _compound_profiler(self):
|
| 290 |
st.header("Advanced Multi-Omics Compound Profiler")
|
| 291 |
-
compound = st.text_input("Analyze Compound:", placeholder="Enter drug name or SMILES (e.g., Aspirin)")
|
| 292 |
if st.button("Profile Compound"):
|
| 293 |
with st.spinner("Decoding molecular profile..."):
|
| 294 |
-
profile =
|
| 295 |
if profile:
|
| 296 |
col1, col2 = st.columns(2)
|
| 297 |
with col1:
|
| 298 |
st.subheader("Structural Insights")
|
| 299 |
smiles = profile.get('canonical_smiles', '')
|
| 300 |
-
mol = Chem.MolFromSmiles(smiles) if smiles
|
| 301 |
if mol:
|
| 302 |
img = Draw.MolToImage(mol, size=(400, 300))
|
| 303 |
st.image(img, caption="2D Molecular Structure")
|
|
@@ -314,21 +362,20 @@ class PharmaResearchInterface:
|
|
| 314 |
|
| 315 |
def _regulatory_hub(self):
|
| 316 |
st.header("Regulatory Intelligence Hub")
|
| 317 |
-
st.write("Gain insights into FDA approvals and regulatory pathways
|
| 318 |
drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., Aspirin")
|
| 319 |
if st.button("Fetch Regulatory Data"):
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
st.json(sample_regulatory_data)
|
| 328 |
|
| 329 |
def _ai_strategist(self):
|
| 330 |
st.header("AI Drug Development Strategist")
|
| 331 |
-
st.write("Leverage
|
| 332 |
target = st.text_input("Enter Target Disease or Pathway:", placeholder="e.g., KRAS G12C mutation")
|
| 333 |
if st.button("Generate AI Strategy"):
|
| 334 |
with st.spinner("Generating AI-driven strategy..."):
|
|
@@ -340,4 +387,4 @@ class PharmaResearchInterface:
|
|
| 340 |
# -----------------------------
|
| 341 |
if __name__ == "__main__":
|
| 342 |
interface = PharmaResearchInterface()
|
| 343 |
-
interface.render()
|
|
|
|
|
|
|
| 1 |
# IMPORTS & CONFIGURATION
|
| 2 |
# -----------------------------
|
| 3 |
import streamlit as st
|
| 4 |
+
import requests
|
| 5 |
+
from rdkit import Chem
|
| 6 |
+
from rdkit.Chem import Draw
|
| 7 |
import pandas as pd
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
import seaborn as sns
|
| 10 |
import logging
|
| 11 |
import re
|
| 12 |
+
from typing import Optional, Dict, List, Any
|
| 13 |
+
from openai import OpenAI
|
|
|
|
| 14 |
|
| 15 |
+
# Configure advanced logging for full traceability and diagnostics
|
| 16 |
logging.basicConfig(
|
| 17 |
level=logging.INFO,
|
| 18 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 19 |
handlers=[logging.FileHandler("pris_debug.log"), logging.StreamHandler()]
|
| 20 |
)
|
| 21 |
logger = logging.getLogger("PRIS")
|
| 22 |
|
| 23 |
# -----------------------------
|
| 24 |
+
# GLOBAL CONSTANTS
|
| 25 |
# -----------------------------
|
| 26 |
+
API_ENDPOINTS = {
|
| 27 |
+
"clinical_trials": "https://clinicaltrials.gov/api/v2/studies",
|
| 28 |
+
"fda_drug_approval": "https://api.fda.gov/drug/label.json",
|
| 29 |
+
"pubchem": "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{}/JSON",
|
| 30 |
+
# ... other endpoints omitted for brevity ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
+
DEFAULT_HEADERS = {
|
| 34 |
+
"User-Agent": "PharmaResearchIntelligenceSuite/1.0 (Professional Use)",
|
| 35 |
+
"Accept": "application/json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
+
# -----------------------------
|
| 39 |
+
# SECRETS MANAGEMENT
|
| 40 |
+
# -----------------------------
|
| 41 |
+
class APIConfigurationError(Exception):
|
| 42 |
+
"""Custom exception for missing API configurations."""
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
| 47 |
+
BIOPORTAL_API_KEY = st.secrets["BIOPORTAL_API_KEY"]
|
| 48 |
+
PUB_EMAIL = st.secrets["PUB_EMAIL"]
|
| 49 |
+
OPENFDA_KEY = st.secrets["OPENFDA_KEY"]
|
| 50 |
+
|
| 51 |
+
if not all([OPENAI_API_KEY, BIOPORTAL_API_KEY, PUB_EMAIL, OPENFDA_KEY]):
|
| 52 |
+
raise APIConfigurationError("One or more required API credentials are missing.")
|
| 53 |
+
except (KeyError, APIConfigurationError) as e:
|
| 54 |
+
st.error(f"Critical configuration error: {str(e)}")
|
| 55 |
+
st.stop()
|
| 56 |
+
|
| 57 |
# -----------------------------
|
| 58 |
# CORE INFRASTRUCTURE
|
| 59 |
# -----------------------------
|
| 60 |
class PharmaResearchEngine:
|
| 61 |
+
"""Core engine for integrating diverse pharmaceutical datasets and performing advanced analyses."""
|
| 62 |
+
|
|
|
|
|
|
|
| 63 |
def __init__(self):
|
| 64 |
+
self.openai_client = OpenAI(api_key=OPENAI_API_KEY)
|
| 65 |
+
|
| 66 |
+
@staticmethod
|
| 67 |
+
def api_request(endpoint: str,
|
| 68 |
+
params: Optional[Dict] = None,
|
| 69 |
+
headers: Optional[Dict] = None) -> Optional[Dict]:
|
| 70 |
+
"""
|
| 71 |
+
Enterprise-grade API request handler with detailed error logging.
|
| 72 |
+
"""
|
| 73 |
+
try:
|
| 74 |
+
response = requests.get(
|
| 75 |
+
endpoint,
|
| 76 |
+
params=params,
|
| 77 |
+
headers={**DEFAULT_HEADERS, **(headers or {})},
|
| 78 |
+
timeout=(3.05, 15)
|
| 79 |
+
)
|
| 80 |
+
response.raise_for_status() # Raises HTTPError for 4xx/5xx responses
|
| 81 |
+
return response.json()
|
| 82 |
+
except requests.exceptions.HTTPError as e:
|
| 83 |
+
logger.error(f"HTTP Error {e.response.status_code} for {endpoint} with params {params}")
|
| 84 |
+
st.error(f"API Error: {e.response.status_code} - {e.response.reason}")
|
| 85 |
+
except Exception as e:
|
| 86 |
+
logger.error(f"Network error for {endpoint}: {str(e)}")
|
| 87 |
+
st.error(f"Network error: {str(e)}")
|
| 88 |
+
return None
|
| 89 |
|
| 90 |
+
def get_compound_profile(self, identifier: str) -> Optional[Dict]:
|
| 91 |
"""
|
| 92 |
+
Retrieve comprehensive chemical profile data from PubChem for a given compound.
|
| 93 |
+
Accepts both common compound names and SMILES strings.
|
| 94 |
"""
|
| 95 |
if not self._is_valid_compound_input(identifier):
|
| 96 |
msg = (f"The input '{identifier}' appears to reference a disease term rather than a chemical compound. "
|
| 97 |
"For disease-related inquiries, please use the Clinical Trial Analytics module.")
|
| 98 |
logger.warning(msg)
|
| 99 |
st.error(msg)
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
pubchem_url = API_ENDPOINTS["pubchem"].format(identifier)
|
| 103 |
+
pubchem_data = self.api_request(pubchem_url)
|
| 104 |
+
if not pubchem_data or not pubchem_data.get("PC_Compounds"):
|
| 105 |
+
logger.warning(f"No compound data returned for identifier: {identifier}")
|
| 106 |
+
st.error("No compound data found. Please verify your input (e.g., check for typos or use a recognized compound name).")
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
compound = pubchem_data["PC_Compounds"][0]
|
| 110 |
+
return {
|
| 111 |
+
'molecular_formula': self._extract_property(compound, 'Molecular Formula'),
|
| 112 |
+
'iupac_name': self._extract_property(compound, 'IUPAC Name'),
|
| 113 |
+
'canonical_smiles': self._extract_property(compound, 'Canonical SMILES'),
|
| 114 |
+
'molecular_weight': self._extract_property(compound, 'Molecular Weight'),
|
| 115 |
+
'logp': self._extract_property(compound, 'LogP')
|
| 116 |
+
}
|
| 117 |
|
| 118 |
+
def _extract_property(self, compound: Dict, prop_name: str) -> str:
|
| 119 |
+
"""Helper to extract a specific property from PubChem compound data."""
|
| 120 |
+
for prop in compound.get("props", []):
|
| 121 |
+
if prop.get("urn", {}).get("label") == prop_name:
|
| 122 |
+
return prop["value"].get("sval", "N/A")
|
| 123 |
+
return "N/A"
|
| 124 |
+
|
| 125 |
+
@staticmethod
|
| 126 |
+
def _is_valid_compound_input(user_input: str) -> bool:
|
| 127 |
"""
|
| 128 |
+
Determines whether the user input is a valid chemical compound identifier.
|
| 129 |
+
Accepts both conventional compound names and SMILES strings.
|
| 130 |
Rejects inputs containing known disease terms.
|
| 131 |
"""
|
| 132 |
input_lower = user_input.lower().strip()
|
| 133 |
+
# Known disease terms that should not be processed as compounds
|
| 134 |
disease_terms = ['diabetes', 'cancer', 'hypertension', 'asthma']
|
| 135 |
if any(term in input_lower for term in disease_terms):
|
| 136 |
return False
|
| 137 |
+
|
| 138 |
+
# If the input contains characters common in SMILES (e.g., '=', '(', ')', '#'), treat as SMILES.
|
| 139 |
if re.search(r"[=\(\)#]", user_input):
|
| 140 |
return True
|
| 141 |
+
|
| 142 |
+
# Otherwise, if input is alphanumeric with spaces or hyphens, assume it's a valid compound name.
|
| 143 |
if re.match(r'^[A-Za-z0-9\s\-]+$', user_input):
|
| 144 |
return True
|
| 145 |
+
|
| 146 |
return False
|
| 147 |
|
| 148 |
# -----------------------------
|
|
|
|
| 150 |
# -----------------------------
|
| 151 |
class ClinicalIntelligence:
|
| 152 |
"""
|
| 153 |
+
Module for clinical trial and regulatory intelligence.
|
| 154 |
+
Provides deep insights into trial landscapes and FDA approval data.
|
| 155 |
"""
|
| 156 |
+
|
| 157 |
def __init__(self):
|
| 158 |
self.engine = PharmaResearchEngine()
|
| 159 |
+
|
| 160 |
+
def get_trial_landscape(self, query: str) -> List[Dict]:
|
| 161 |
+
params = {"query.term": query, "retmax": 10} if not query.startswith("NCT") else {"id": query}
|
| 162 |
+
trials = self.engine.api_request(API_ENDPOINTS["clinical_trials"], params=params)
|
| 163 |
+
if trials is None:
|
| 164 |
+
logger.error(f"Clinical trial API returned no data for query: {query}")
|
| 165 |
+
st.error("Failed to retrieve clinical trials. Please try a different query or check your network connection.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
return []
|
| 167 |
+
return trials.get("studies", [])[:5]
|
| 168 |
+
|
| 169 |
+
def get_fda_approval(self, drug_name: str) -> Optional[Dict]:
|
| 170 |
+
if not OPENFDA_KEY:
|
| 171 |
+
st.error("OpenFDA API key not configured.")
|
| 172 |
+
return None
|
| 173 |
+
|
| 174 |
+
params = {
|
| 175 |
+
"api_key": OPENFDA_KEY,
|
| 176 |
+
"search": f'openfda.brand_name:"{drug_name}"',
|
| 177 |
+
"limit": 1
|
| 178 |
+
}
|
| 179 |
+
data = self.engine.api_request(API_ENDPOINTS["fda_drug_approval"], params=params)
|
| 180 |
+
if data and data.get("results"):
|
| 181 |
+
return data["results"][0]
|
| 182 |
+
logger.warning(f"No FDA data found for drug: {drug_name}")
|
| 183 |
+
st.error("No FDA regulatory data found for the specified drug.")
|
| 184 |
+
return None
|
| 185 |
|
| 186 |
class AIDrugInnovator:
|
| 187 |
"""
|
| 188 |
+
GPT-4 powered module for generating advanced, cutting-edge drug development strategies.
|
| 189 |
"""
|
| 190 |
+
|
| 191 |
def __init__(self):
|
| 192 |
+
self.engine = PharmaResearchEngine()
|
| 193 |
+
|
|
|
|
| 194 |
def generate_strategy(self, target: str, strategy: str) -> str:
|
| 195 |
+
prompt = f"""As the Chief Scientific Officer at a leading pharmaceutical company, please develop a {strategy} strategy for the target: {target}.
|
| 196 |
+
|
| 197 |
+
**Target Validation Approach**
|
| 198 |
+
- Perform an exhaustive literature review to understand the molecular basis of the disease.
|
| 199 |
+
- Validate targets using in vitro and in vivo models.
|
| 200 |
+
- Integrate genomic and proteomic data to identify actionable targets.
|
| 201 |
+
- Collaborate with top-tier academic and clinical institutions.
|
| 202 |
|
| 203 |
+
**Lead Optimization Tactics**
|
| 204 |
+
- Conduct chemical optimization to improve potency, selectivity, and pharmacokinetic properties.
|
| 205 |
+
- Utilize high-throughput screening and biological assays for iterative lead refinement.
|
| 206 |
+
- Perform rigorous in vivo efficacy and safety evaluations.
|
| 207 |
+
- Secure intellectual property through comprehensive patent landscaping.
|
| 208 |
|
| 209 |
+
**Clinical Trial Design**
|
| 210 |
+
- Initiate Phase I trials focused on safety and dosage determination.
|
| 211 |
+
- Scale to Phase II for efficacy and side-effect profiling in a broader patient cohort.
|
| 212 |
+
- Execute large-scale Phase III trials to validate clinical benefits against current standards of care.
|
| 213 |
+
- Plan for Phase IV post-marketing surveillance for long-term outcome assessment.
|
| 214 |
+
- Incorporate adaptive trial designs to enhance responsiveness and efficiency.
|
| 215 |
|
| 216 |
+
**Regulatory Pathway Analysis**
|
| 217 |
+
- Engage in early pre-IND consultations with regulatory authorities.
|
| 218 |
+
- Prepare robust IND submissions incorporating comprehensive preclinical data.
|
| 219 |
+
- Maintain continuous dialogue with regulators throughout clinical development.
|
| 220 |
+
- Strategize for expedited review pathways (e.g., Fast Track, Breakthrough Therapy).
|
|
|
|
| 221 |
|
| 222 |
+
**Commercial Potential Assessment**
|
| 223 |
+
- Conduct detailed market research to understand the competitive landscape and unmet needs.
|
| 224 |
+
- Segment patient populations to tailor therapeutic approaches.
|
| 225 |
+
- Devise dynamic pricing and reimbursement strategies aligned with payer requirements.
|
| 226 |
+
- Formulate a comprehensive go-to-market plan leveraging multi-channel marketing strategies.
|
| 227 |
|
| 228 |
+
Please format your response in Markdown with clear section headers."""
|
| 229 |
+
try:
|
| 230 |
+
response = self.engine.openai_client.chat.completions.create(
|
| 231 |
+
model="gpt-4",
|
| 232 |
+
messages=[{"role": "user", "content": prompt}],
|
| 233 |
+
temperature=0.7,
|
| 234 |
+
max_tokens=1500
|
| 235 |
+
)
|
| 236 |
+
return response.choices[0].message.content
|
| 237 |
+
except Exception as e:
|
| 238 |
+
logger.error(f"AI Strategy Generation Error: {str(e)}")
|
| 239 |
+
st.error("Failed to generate strategy. Please check the API configuration or try again later.")
|
| 240 |
+
return "Strategy generation failed due to an internal error."
|
| 241 |
|
| 242 |
# -----------------------------
|
| 243 |
# STREAMLIT INTERFACE
|
| 244 |
# -----------------------------
|
| 245 |
class PharmaResearchInterface:
|
| 246 |
"""
|
| 247 |
+
Next-generation Streamlit interface for the Pharma Research Intelligence Suite.
|
| 248 |
+
Provides an integrated, intuitive dashboard for advanced pharmaceutical data analytics and AI-driven strategy generation.
|
| 249 |
"""
|
| 250 |
+
|
| 251 |
def __init__(self):
|
|
|
|
| 252 |
self.clinical_intel = ClinicalIntelligence()
|
| 253 |
self.ai_innovator = AIDrugInnovator()
|
| 254 |
self._configure_page()
|
|
|
|
| 260 |
initial_sidebar_state="expanded"
|
| 261 |
)
|
| 262 |
st.markdown("""
|
| 263 |
+
<style>
|
| 264 |
+
.main {background-color: #f0f2f6;}
|
| 265 |
+
.stAlert {padding: 20px;}
|
| 266 |
+
.reportview-container .markdown-text-container {font-family: 'Helvetica Neue', Arial, sans-serif}
|
| 267 |
+
</style>
|
| 268 |
+
""", unsafe_allow_html=True)
|
| 269 |
|
| 270 |
def render(self):
|
| 271 |
st.title("Next-Generation Pharmaceutical Research Intelligence Suite")
|
| 272 |
self._render_navigation()
|
| 273 |
+
|
| 274 |
def _render_navigation(self):
|
| 275 |
tabs = st.tabs([
|
| 276 |
"🚀 Drug Innovation",
|
|
|
|
| 295 |
col1, col2 = st.columns([1, 3])
|
| 296 |
with col1:
|
| 297 |
target = st.text_input("Target Pathobiology:", placeholder="e.g., EGFR mutant NSCLC")
|
| 298 |
+
strategy = st.selectbox("Development Paradigm:",
|
| 299 |
+
["First-in-class", "Fast-follower", "Biologic", "ADC", "Gene Therapy"])
|
| 300 |
if st.button("Generate Development Blueprint"):
|
| 301 |
with st.spinner("Formulating strategic plan..."):
|
| 302 |
+
blueprint = self.ai_innovator.generate_strategy(target, strategy)
|
| 303 |
st.markdown(blueprint, unsafe_allow_html=True)
|
| 304 |
|
| 305 |
def _trial_analytics(self):
|
| 306 |
st.header("Clinical Trial Landscape Analysis")
|
| 307 |
+
trial_query = st.text_input("Search Clinical Trials:", placeholder="Enter condition, intervention, or NCT number")
|
| 308 |
if st.button("Analyze Trial Landscape"):
|
| 309 |
with st.spinner("Fetching trial data..."):
|
| 310 |
+
trials = self.clinical_intel.get_trial_landscape(trial_query)
|
| 311 |
if trials:
|
| 312 |
+
st.subheader("Top 5 Clinical Trials")
|
| 313 |
trial_data = []
|
| 314 |
for study in trials:
|
| 315 |
title = study.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A")
|
|
|
|
| 336 |
|
| 337 |
def _compound_profiler(self):
|
| 338 |
st.header("Advanced Multi-Omics Compound Profiler")
|
| 339 |
+
compound = st.text_input("Analyze Compound:", placeholder="Enter drug name or SMILES (e.g., Aspirin, CC(=O)OC1=CC=CC=C1C(=O)O)")
|
| 340 |
if st.button("Profile Compound"):
|
| 341 |
with st.spinner("Decoding molecular profile..."):
|
| 342 |
+
profile = PharmaResearchEngine().get_compound_profile(compound)
|
| 343 |
if profile:
|
| 344 |
col1, col2 = st.columns(2)
|
| 345 |
with col1:
|
| 346 |
st.subheader("Structural Insights")
|
| 347 |
smiles = profile.get('canonical_smiles', '')
|
| 348 |
+
mol = Chem.MolFromSmiles(smiles) if smiles != "N/A" else None
|
| 349 |
if mol:
|
| 350 |
img = Draw.MolToImage(mol, size=(400, 300))
|
| 351 |
st.image(img, caption="2D Molecular Structure")
|
|
|
|
| 362 |
|
| 363 |
def _regulatory_hub(self):
|
| 364 |
st.header("Regulatory Intelligence Hub")
|
| 365 |
+
st.write("Gain insights into FDA approvals and regulatory pathways.")
|
| 366 |
drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., Aspirin")
|
| 367 |
if st.button("Fetch Regulatory Data"):
|
| 368 |
+
with st.spinner("Retrieving regulatory information..."):
|
| 369 |
+
fda_data = self.clinical_intel.get_fda_approval(drug_name)
|
| 370 |
+
if fda_data:
|
| 371 |
+
st.subheader("FDA Approval Details")
|
| 372 |
+
st.json(fda_data)
|
| 373 |
+
else:
|
| 374 |
+
st.warning("No FDA regulatory data found for the specified drug.")
|
|
|
|
| 375 |
|
| 376 |
def _ai_strategist(self):
|
| 377 |
st.header("AI Drug Development Strategist")
|
| 378 |
+
st.write("Leverage GPT-4 to generate cutting-edge drug development strategies.")
|
| 379 |
target = st.text_input("Enter Target Disease or Pathway:", placeholder="e.g., KRAS G12C mutation")
|
| 380 |
if st.button("Generate AI Strategy"):
|
| 381 |
with st.spinner("Generating AI-driven strategy..."):
|
|
|
|
| 387 |
# -----------------------------
|
| 388 |
if __name__ == "__main__":
|
| 389 |
interface = PharmaResearchInterface()
|
| 390 |
+
interface.render()
|