mgbam commited on
Commit
300a38a
·
verified ·
1 Parent(s): 92ff582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +201 -154
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 time
11
- from rdkit import Chem
12
- from rdkit.Chem import Draw
13
 
14
- # Configure logging for detailed diagnostics
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
- # FALLBACK / SCRAPED DATA
24
  # -----------------------------
25
- # Fallback data for compound profiling (simulated scraped or cached data)
26
- FALLBACK_COMPOUND_DATA = {
27
- "aspirin": {
28
- "molecular_formula": "C9H8O4",
29
- "iupac_name": "2-acetoxybenzoic acid",
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
- # Fallback clinical trial data (simulated scraped data)
44
- FALLBACK_CLINICAL_DATA = {
45
- "nct1": [
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
- Core engine using local fallback data.
78
- This engine simulates data retrieval without any external API calls.
79
- """
80
  def __init__(self):
81
- # In a live system, API clients would be initialized here.
82
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
- def get_compound_profile(self, identifier: str) -> dict:
85
  """
86
- Retrieve a comprehensive compound profile.
87
- Checks input validity and returns fallback data if available.
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
- key = identifier.lower().strip()
97
- if key in FALLBACK_COMPOUND_DATA:
98
- logger.info(f"Using fallback data for compound '{identifier}'.")
99
- return FALLBACK_COMPOUND_DATA[key]
100
- else:
101
- msg = f"No compound data found for '{identifier}'. Please verify the compound name or SMILES."
102
- logger.error(msg)
103
- st.error(msg)
104
- return {}
 
 
 
 
 
 
105
 
106
- def _is_valid_compound_input(self, user_input: str) -> bool:
 
 
 
 
 
 
 
 
107
  """
108
- Determines if the user input is a valid compound identifier.
 
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
- # Accept input with SMILES-specific characters (e.g., '=', '(', ')', '#')
 
116
  if re.search(r"[=\(\)#]", user_input):
117
  return True
118
- # Otherwise, accept if input is alphanumeric with spaces/hyphens
 
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 analytics using fallback data.
 
129
  """
 
130
  def __init__(self):
131
  self.engine = PharmaResearchEngine()
132
-
133
- def get_trial_landscape(self, query: str) -> list:
134
- """
135
- Retrieve clinical trial data based on the query.
136
- Returns fallback data if available.
137
- """
138
- key = query.lower().strip()
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
- Simulated AI module that returns a pre-defined drug development strategy.
151
  """
 
152
  def __init__(self):
153
- # No external AI API is used in offline mode.
154
- pass
155
-
156
  def generate_strategy(self, target: str, strategy: str) -> str:
157
- """
158
- Returns a comprehensive, simulated strategy for drug development.
159
- """
160
- simulated_response = f"""
161
- # First-in-Class Strategy for {target.title()}
 
 
162
 
163
- ## Target Validation Approach
164
- - **Literature Review:** Perform an exhaustive review of current literature to understand the molecular mechanisms of {target}.
165
- - **Preclinical Studies:** Validate targets using state-of-the-art in vitro and in vivo models.
166
- - **Omics Integration:** Analyze genomic and proteomic data to identify actionable targets.
167
- - **Collaborative Research:** Partner with leading academic and clinical institutions.
168
 
169
- ## Lead Optimization Tactics
170
- - **Chemical Optimization:** Enhance lead compounds to improve potency, selectivity, and pharmacokinetics.
171
- - **High-Throughput Screening:** Utilize modern screening techniques for iterative lead refinement.
172
- - **In Vivo Efficacy:** Conduct thorough animal studies to assess safety and efficacy.
173
- - **Intellectual Property:** Secure robust patents through comprehensive patent landscaping.
 
174
 
175
- ## Clinical Trial Design
176
- - **Phase I:** Safety and dosage studies.
177
- - **Phase II:** Efficacy and side-effect profiling.
178
- - **Phase III:** Large-scale trials comparing with current standards.
179
- - **Phase IV:** Post-marketing surveillance.
180
- - **Adaptive Designs:** Incorporate adaptive trial designs for efficiency.
181
 
182
- ## Regulatory Pathway Analysis
183
- - **Pre-IND Consultation:** Initiate early dialogue with regulatory authorities.
184
- - **IND Submission:** Prepare robust submissions with complete preclinical data.
185
- - **Continuous Engagement:** Maintain ongoing communication with regulators.
186
- - **Expedited Programs:** Explore Fast Track and Breakthrough Therapy designations.
187
 
188
- ## Commercial Potential Assessment
189
- - **Market Research:** Analyze market trends and unmet needs.
190
- - **Patient Segmentation:** Identify target patient demographics.
191
- - **Pricing & Reimbursement:** Develop strategic pricing and reimbursement plans.
192
- - **Go-To-Market Strategy:** Formulate a comprehensive marketing and sales plan.
193
- """
194
- return simulated_response
 
 
 
 
 
 
195
 
196
  # -----------------------------
197
  # STREAMLIT INTERFACE
198
  # -----------------------------
199
  class PharmaResearchInterface:
200
  """
201
- Streamlit interface for the Pharma Research Intelligence Suite using fallback data.
 
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
- <style>
217
- .main {background-color: #f0f2f6; padding: 20px;}
218
- .stAlert {padding: 20px; font-size: 1.1em;}
219
- .reportview-container .markdown-text-container {font-family: 'Helvetica Neue', Arial, sans-serif;}
220
- </style>
221
- """, unsafe_allow_html=True)
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
- paradigm = st.selectbox("Development Paradigm:", ["First-in-class", "Fast-follower", "Biologic", "ADC", "Gene Therapy"])
 
252
  if st.button("Generate Development Blueprint"):
253
  with st.spinner("Formulating strategic plan..."):
254
- blueprint = self.ai_innovator.generate_strategy(target, paradigm)
255
  st.markdown(blueprint, unsafe_allow_html=True)
256
 
257
  def _trial_analytics(self):
258
  st.header("Clinical Trial Landscape Analysis")
259
- query = st.text_input("Search Clinical Trials:", placeholder="Enter condition, intervention, or NCT number")
260
  if st.button("Analyze Trial Landscape"):
261
  with st.spinner("Fetching trial data..."):
262
- trials = self.clinical_intel.get_trial_landscape(query)
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 = self.engine.get_compound_profile(compound)
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 and smiles != "N/A" else None
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 using local sample data.")
318
  drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., Aspirin")
319
  if st.button("Fetch Regulatory Data"):
320
- sample_regulatory_data = {
321
- "drug_name": drug_name,
322
- "approval_status": "Approved",
323
- "approval_date": "1985-07-01",
324
- "label": "Sample regulatory label information."
325
- }
326
- st.subheader("FDA Approval Details")
327
- st.json(sample_regulatory_data)
328
 
329
  def _ai_strategist(self):
330
  st.header("AI Drug Development Strategist")
331
- st.write("Leverage our simulated GPT-4 engine to generate cutting-edge drug development strategies.")
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()