Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
from rdkit import Chem
|
@@ -5,276 +13,347 @@ from rdkit.Chem import Draw
|
|
5 |
import pandas as pd
|
6 |
import matplotlib.pyplot as plt
|
7 |
import seaborn as sns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from openai import OpenAI
|
9 |
-
from typing import Optional, Dict, List, Any
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
page_icon="🧬",
|
17 |
-
layout="wide"
|
18 |
)
|
|
|
19 |
|
20 |
-
#
|
21 |
-
#
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
def
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
try:
|
43 |
-
response =
|
44 |
-
|
45 |
-
params=
|
46 |
-
|
|
|
47 |
)
|
48 |
response.raise_for_status()
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
except Exception as e:
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
def get_fda_approval(self, drug_name: str) -> Optional[Dict]:
|
56 |
-
"""Retrieve FDA approval information"""
|
57 |
-
|
58 |
-
|
59 |
-
FDA_API,
|
60 |
-
params={
|
61 |
-
"api_key": st.secrets["OPENFDA_KEY"],
|
62 |
-
"search": f'openfda.brand_name:"{drug_name}"',
|
63 |
-
"limit": 1
|
64 |
-
},
|
65 |
-
timeout=10
|
66 |
-
)
|
67 |
-
response.raise_for_status()
|
68 |
-
data = response.json()
|
69 |
-
return data.get("results", [None])[0]
|
70 |
-
except Exception as e:
|
71 |
-
st.error(f"FDA API error: {str(e)}")
|
72 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
try:
|
77 |
-
response = self.
|
78 |
-
|
79 |
-
|
|
|
|
|
80 |
)
|
81 |
-
response.
|
82 |
-
data = response.json()
|
83 |
-
return data.get("PC_Compounds", [{}])[0]
|
84 |
except Exception as e:
|
85 |
-
|
86 |
-
return
|
87 |
|
88 |
-
#
|
89 |
-
#
|
90 |
-
#
|
91 |
-
class
|
92 |
-
"""
|
93 |
|
94 |
def __init__(self):
|
95 |
-
self.
|
96 |
-
self.
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
st.markdown("""
|
101 |
<style>
|
102 |
-
.main {background-color: #
|
103 |
-
.
|
104 |
-
.
|
105 |
-
.metric {background-color: white; padding: 1.5rem; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);}
|
106 |
-
.plot-container {background-color: white; padding: 1rem; border-radius: 10px; margin-top: 1rem;}
|
107 |
</style>
|
108 |
-
|
109 |
-
|
110 |
def render(self):
|
111 |
"""Main application interface"""
|
112 |
-
st.
|
|
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
"
|
|
|
|
|
|
|
|
|
118 |
])
|
119 |
|
120 |
-
with
|
121 |
-
|
122 |
-
with
|
123 |
-
|
124 |
-
with
|
125 |
-
self._render_regulatory_info()
|
126 |
-
|
127 |
-
def _render_compound_analyzer(self):
|
128 |
-
"""Compound analysis section"""
|
129 |
-
st.subheader("Molecular Analysis")
|
130 |
-
col1, col2 = st.columns([1, 2])
|
131 |
-
|
132 |
-
with col1:
|
133 |
-
compound = st.text_input("Enter compound name:", "Aspirin")
|
134 |
-
if st.button("Analyze"):
|
135 |
-
with st.spinner("Analyzing compound..."):
|
136 |
-
data = self.service.get_compound_data(compound)
|
137 |
-
if data:
|
138 |
-
self._display_compound_info(data)
|
139 |
-
else:
|
140 |
-
st.warning("Compound not found")
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
def _display_compound_info(self, data: Dict):
|
147 |
-
"""Show compound information"""
|
148 |
-
properties = self._extract_properties(data)
|
149 |
|
150 |
-
col1, col2, col3 = st.columns(3)
|
151 |
with col1:
|
152 |
-
st.
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
def _extract_properties(self, data: Dict) -> Dict:
|
165 |
-
"""Extract chemical properties from PubChem data"""
|
166 |
-
return {
|
167 |
-
"formula": next(
|
168 |
-
(p["value"]["sval"] for p in data.get("props", [])
|
169 |
-
if p.get("urn", {}).get("label") == "Molecular Formula"),
|
170 |
-
"N/A"
|
171 |
-
),
|
172 |
-
"weight": next(
|
173 |
-
(p["value"]["sval"] for p in data.get("props", [])
|
174 |
-
if p.get("urn", {}).get("label") == "Molecular Weight"),
|
175 |
-
"N/A"
|
176 |
-
),
|
177 |
-
"iupac": next(
|
178 |
-
(p["value"]["sval"] for p in data.get("props", [])
|
179 |
-
if p.get("urn", {}).get("name") == "Preferred"),
|
180 |
-
"N/A"
|
181 |
-
),
|
182 |
-
"smiles": next(
|
183 |
-
(p["value"]["sval"] for p in data.get("props", [])
|
184 |
-
if p.get("name") == "Canonical SMILES"),
|
185 |
-
"N/A"
|
186 |
-
)
|
187 |
-
}
|
188 |
-
|
189 |
-
def _render_clinical_trials(self):
|
190 |
-
"""Clinical trials analysis section"""
|
191 |
-
st.subheader("Clinical Trial Explorer")
|
192 |
-
query = st.text_input("Search for trials:", "Diabetes")
|
193 |
|
194 |
-
if st.button("
|
195 |
-
with st.spinner("
|
196 |
-
trials = self.
|
|
|
197 |
if trials:
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
else:
|
200 |
-
st.warning("No trials found for
|
201 |
-
|
202 |
-
def
|
203 |
-
"""
|
204 |
-
|
205 |
-
|
206 |
-
"Title": t.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A"),
|
207 |
-
"Status": t.get("protocolSection", {}).get("statusModule", {}).get("overallStatus", "N/A"),
|
208 |
-
"Phase": self._parse_phase(t),
|
209 |
-
"Enrollment": t.get("protocolSection", {}).get("designModule", {}).get("enrollmentInfo", {}).get("count", "N/A")
|
210 |
-
} for t in trials])
|
211 |
-
|
212 |
-
st.dataframe(
|
213 |
-
df,
|
214 |
-
use_container_width=True,
|
215 |
-
hide_index=True,
|
216 |
-
column_config={
|
217 |
-
"NCT ID": st.column_config.TextColumn(width="medium"),
|
218 |
-
"Title": st.column_config.TextColumn(width="large"),
|
219 |
-
"Status": st.column_config.TextColumn(width="small"),
|
220 |
-
"Phase": st.column_config.TextColumn(width="small"),
|
221 |
-
"Enrollment": st.column_config.NumberColumn(format="%d")
|
222 |
-
}
|
223 |
-
)
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
st.
|
248 |
-
|
249 |
-
|
250 |
-
"""Regulatory information section"""
|
251 |
-
st.subheader("Regulatory Intelligence")
|
252 |
-
drug_name = st.text_input("Enter drug name:", "Aspirin")
|
253 |
|
254 |
-
if st.button("
|
255 |
-
with st.spinner("Retrieving
|
256 |
-
fda_data = self.
|
257 |
if fda_data:
|
258 |
-
|
|
|
259 |
else:
|
260 |
-
st.warning("No FDA data found for
|
261 |
-
|
262 |
-
def
|
263 |
-
"""
|
264 |
-
|
265 |
-
st.
|
266 |
-
|
267 |
-
**Manufacturer**: {', '.join(openfda.get('manufacturer_name', ['N/A']))}
|
268 |
-
**Approval Date**: {data.get('effective_time', 'N/A')}
|
269 |
-
**Dosage Form**: {', '.join(openfda.get('dosage_form', ['N/A']))}
|
270 |
-
""")
|
271 |
|
272 |
-
st.
|
273 |
-
|
|
|
|
|
274 |
|
275 |
-
#
|
276 |
-
#
|
277 |
-
#
|
278 |
if __name__ == "__main__":
|
279 |
-
|
280 |
-
|
|
|
1 |
+
"""
|
2 |
+
Pharma Research Intelligence Suite (PRIS)
|
3 |
+
A Next-Generation Platform for AI-Driven Drug Discovery and Development
|
4 |
+
"""
|
5 |
+
|
6 |
+
# -----------------------------
|
7 |
+
# IMPORTS & CONFIGURATION
|
8 |
+
# -----------------------------
|
9 |
import streamlit as st
|
10 |
import requests
|
11 |
from rdkit import Chem
|
|
|
13 |
import pandas as pd
|
14 |
import matplotlib.pyplot as plt
|
15 |
import seaborn as sns
|
16 |
+
from fpdf import FPDF
|
17 |
+
import tempfile
|
18 |
+
import logging
|
19 |
+
import os
|
20 |
+
import plotly.graph_objects as go
|
21 |
+
import networkx as nx
|
22 |
+
from typing import Optional, Dict, List, Any, Tuple
|
23 |
from openai import OpenAI
|
|
|
24 |
|
25 |
+
# Configure professional logging
|
26 |
+
logging.basicConfig(
|
27 |
+
level=logging.INFO,
|
28 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
29 |
+
handlers=[logging.FileHandler("pris_debug.log")]
|
|
|
|
|
30 |
)
|
31 |
+
logger = logging.getLogger("PRIS")
|
32 |
|
33 |
+
# -----------------------------
|
34 |
+
# GLOBAL CONSTANTS
|
35 |
+
# -----------------------------
|
36 |
+
API_ENDPOINTS = {
|
37 |
+
# Clinical Data Services
|
38 |
+
"clinical_trials": "https://clinicaltrials.gov/api/v2/studies",
|
39 |
+
"fda_drug_approval": "https://api.fda.gov/drug/label.json",
|
40 |
+
"faers_adverse_events": "https://api.fda.gov/drug/event.json",
|
41 |
+
|
42 |
+
# Chemical & Biological Data
|
43 |
+
"pubchem": "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{}/JSON",
|
44 |
+
"pubmed": "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi",
|
45 |
+
|
46 |
+
# Pharmacogenomics Resources
|
47 |
+
"pharmgkb_variant_clinical_annotations": "https://api.pharmgkb.org/v1/data/variant/{}/clinicalAnnotations",
|
48 |
+
"pharmgkb_gene": "https://api.pharmgkb.org/v1/data/gene/{}",
|
49 |
+
"pharmgkb_gene_variants": "https://api.pharmgkb.org/v1/data/gene/{}/variants",
|
50 |
+
|
51 |
+
# Semantic Medical Resources
|
52 |
+
"bioportal_search": "https://data.bioontology.org/search",
|
53 |
+
|
54 |
+
# Drug Classification Systems
|
55 |
+
"rxnorm_rxcui": "https://rxnav.nlm.nih.gov/REST/rxcui.json",
|
56 |
+
"rxnorm_properties": "https://rxnav.nlm.nih.gov/REST/rxcui/{}/properties.json",
|
57 |
+
"rxclass_by_drug": "https://rxnav.nlm.nih.gov/REST/class/byDrugName.json"
|
58 |
+
}
|
59 |
|
60 |
+
DEFAULT_HEADERS = {
|
61 |
+
"User-Agent": "PharmaResearchIntelligenceSuite/1.0 (Professional Use)",
|
62 |
+
"Accept": "application/json"
|
63 |
+
}
|
64 |
+
|
65 |
+
# -----------------------------
|
66 |
+
# SECRETS MANAGEMENT
|
67 |
+
# -----------------------------
|
68 |
+
class APIConfigurationError(Exception):
|
69 |
+
"""Custom exception for missing API configurations"""
|
70 |
+
pass
|
71 |
+
|
72 |
+
try:
|
73 |
+
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
74 |
+
BIOPORTAL_API_KEY = st.secrets["BIOPORTAL_API_KEY"]
|
75 |
+
PUB_EMAIL = st.secrets["PUB_EMAIL"]
|
76 |
+
OPENFDA_KEY = st.secrets["OPENFDA_KEY"]
|
77 |
|
78 |
+
# Validate essential configurations
|
79 |
+
if not all([OPENAI_API_KEY, BIOPORTAL_API_KEY, PUB_EMAIL, OPENFDA_KEY]):
|
80 |
+
raise APIConfigurationError("Missing one or more required API credentials")
|
81 |
+
|
82 |
+
except (KeyError, APIConfigurationError) as e:
|
83 |
+
st.error(f"Critical configuration error: {str(e)}")
|
84 |
+
st.stop()
|
85 |
+
|
86 |
+
# -----------------------------
|
87 |
+
# CORE INFRASTRUCTURE
|
88 |
+
# -----------------------------
|
89 |
+
class PharmaResearchEngine:
|
90 |
+
"""Core engine for pharmaceutical data integration and analysis"""
|
91 |
|
92 |
+
def __init__(self):
|
93 |
+
self.openai_client = OpenAI(api_key=OPENAI_API_KEY)
|
94 |
+
|
95 |
+
@staticmethod
|
96 |
+
def api_request(endpoint: str,
|
97 |
+
params: Optional[Dict] = None,
|
98 |
+
headers: Optional[Dict] = None) -> Optional[Dict]:
|
99 |
+
"""Enterprise-grade API request handler with advanced resilience"""
|
100 |
try:
|
101 |
+
response = requests.get(
|
102 |
+
endpoint,
|
103 |
+
params=params,
|
104 |
+
headers={**DEFAULT_HEADERS, **(headers or {})},
|
105 |
+
timeout=(3.05, 15)
|
106 |
)
|
107 |
response.raise_for_status()
|
108 |
+
return response.json()
|
109 |
+
except requests.exceptions.HTTPError as e:
|
110 |
+
logger.error(f"HTTP Error {e.response.status_code} for {endpoint}")
|
111 |
+
st.error(f"API Error: {e.response.status_code} - {e.response.reason}")
|
112 |
except Exception as e:
|
113 |
+
logger.error(f"Network error for {endpoint}: {str(e)}")
|
114 |
+
st.error(f"Network error: {str(e)}")
|
115 |
+
return None
|
116 |
+
|
117 |
+
def get_compound_profile(self, identifier: str) -> Optional[Dict]:
|
118 |
+
"""Retrieve comprehensive chemical profile"""
|
119 |
+
pubchem_data = self.api_request(
|
120 |
+
API_ENDPOINTS["pubchem"].format(identifier)
|
121 |
+
)
|
122 |
+
|
123 |
+
if not pubchem_data or not pubchem_data.get("PC_Compounds"):
|
124 |
+
return None
|
125 |
+
|
126 |
+
compound = pubchem_data["PC_Compounds"][0]
|
127 |
+
return {
|
128 |
+
'molecular_formula': self._extract_property(compound, 'Molecular Formula'),
|
129 |
+
'iupac_name': self._extract_property(compound, 'IUPAC Name'),
|
130 |
+
'canonical_smiles': self._extract_property(compound, 'Canonical SMILES'),
|
131 |
+
'molecular_weight': self._extract_property(compound, 'Molecular Weight'),
|
132 |
+
'logp': self._extract_property(compound, 'LogP')
|
133 |
+
}
|
134 |
+
|
135 |
+
def _extract_property(self, compound: Dict, prop_name: str) -> str:
|
136 |
+
"""Helper for property extraction from PubChem data"""
|
137 |
+
for prop in compound.get("props", []):
|
138 |
+
if prop.get("urn", {}).get("label") == prop_name:
|
139 |
+
return prop["value"]["sval"]
|
140 |
+
return "N/A"
|
141 |
+
|
142 |
+
# -----------------------------
|
143 |
+
# INTELLIGENCE MODULES
|
144 |
+
# -----------------------------
|
145 |
+
class ClinicalIntelligence:
|
146 |
+
"""Handles clinical trial and regulatory data analysis"""
|
147 |
+
|
148 |
+
def __init__(self):
|
149 |
+
self.engine = PharmaResearchEngine()
|
150 |
+
|
151 |
+
def get_trial_landscape(self, query: str) -> List[Dict]:
|
152 |
+
"""Analyze clinical trial landscape for given query"""
|
153 |
+
params = {"query.term": query, "retmax": 10} if not query.startswith("NCT") else {"id": query}
|
154 |
+
trials = self.engine.api_request(API_ENDPOINTS["clinical_trials"], params=params)
|
155 |
+
return trials.get("studies", [])[:5]
|
156 |
|
157 |
def get_fda_approval(self, drug_name: str) -> Optional[Dict]:
|
158 |
+
"""Retrieve FDA approval information for a drug"""
|
159 |
+
if not OPENFDA_KEY:
|
160 |
+
st.error("OpenFDA API key not configured.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
return None
|
162 |
+
|
163 |
+
params = {
|
164 |
+
"api_key": OPENFDA_KEY,
|
165 |
+
"search": f'openfda.brand_name:"{drug_name}"',
|
166 |
+
"limit": 1
|
167 |
+
}
|
168 |
+
|
169 |
+
data = self.engine.api_request(
|
170 |
+
API_ENDPOINTS["fda_drug_approval"],
|
171 |
+
params=params
|
172 |
+
)
|
173 |
+
|
174 |
+
if data and data.get("results"):
|
175 |
+
return data["results"][0]
|
176 |
+
return None
|
177 |
|
178 |
+
class AIDrugInnovator:
|
179 |
+
"""GPT-4 powered drug development strategist"""
|
180 |
+
|
181 |
+
def __init__(self):
|
182 |
+
self.engine = PharmaResearchEngine()
|
183 |
+
|
184 |
+
def generate_strategy(self, target: str, strategy: str) -> str:
|
185 |
+
"""Generate AI-driven development strategy"""
|
186 |
+
prompt = f"""As Chief Scientific Officer of a top pharmaceutical company, develop a {strategy} strategy for {target}.
|
187 |
+
Include:
|
188 |
+
- Target validation approach
|
189 |
+
- Lead optimization tactics
|
190 |
+
- Clinical trial design
|
191 |
+
- Regulatory pathway analysis
|
192 |
+
- Commercial potential assessment
|
193 |
+
Format in Markdown with clear sections."""
|
194 |
+
|
195 |
try:
|
196 |
+
response = self.engine.openai_client.chat.completions.create(
|
197 |
+
model="gpt-4",
|
198 |
+
messages=[{"role": "user", "content": prompt}],
|
199 |
+
temperature=0.7,
|
200 |
+
max_tokens=1500
|
201 |
)
|
202 |
+
return response.choices[0].message.content
|
|
|
|
|
203 |
except Exception as e:
|
204 |
+
logger.error(f"AI Strategy Error: {str(e)}")
|
205 |
+
return "Strategy generation failed. Please check API configuration."
|
206 |
|
207 |
+
# -----------------------------
|
208 |
+
# STREAMLIT INTERFACE
|
209 |
+
# -----------------------------
|
210 |
+
class PharmaResearchInterface:
|
211 |
+
"""Modern UI for pharmaceutical research platform"""
|
212 |
|
213 |
def __init__(self):
|
214 |
+
self.clinical_intel = ClinicalIntelligence()
|
215 |
+
self.ai_innovator = AIDrugInnovator()
|
216 |
+
self._configure_page()
|
217 |
+
|
218 |
+
def _configure_page(self):
|
219 |
+
"""Setup Streamlit page configuration"""
|
220 |
+
st.set_page_config(
|
221 |
+
page_title="PRIS - Pharma Research Intelligence Suite",
|
222 |
+
layout="wide",
|
223 |
+
initial_sidebar_state="expanded"
|
224 |
+
)
|
225 |
st.markdown("""
|
226 |
<style>
|
227 |
+
.main {background-color: #f9f9f9;}
|
228 |
+
.stAlert {padding: 20px;}
|
229 |
+
.reportview-container .markdown-text-container {font-family: 'Arial'}
|
|
|
|
|
230 |
</style>
|
231 |
+
""", unsafe_allow_html=True)
|
232 |
+
|
233 |
def render(self):
|
234 |
"""Main application interface"""
|
235 |
+
st.title("Pharma Research Intelligence Suite")
|
236 |
+
self._render_navigation()
|
237 |
|
238 |
+
def _render_navigation(self):
|
239 |
+
"""Dynamic tab-based navigation system"""
|
240 |
+
tabs = st.tabs([
|
241 |
+
"🚀 Drug Innovation",
|
242 |
+
"📈 Trial Analytics",
|
243 |
+
"🧪 Compound Profiler",
|
244 |
+
"📜 Regulatory Hub",
|
245 |
+
"🤖 AI Strategist"
|
246 |
])
|
247 |
|
248 |
+
with tabs[0]: self._drug_innovation()
|
249 |
+
with tabs[1]: self._trial_analytics()
|
250 |
+
with tabs[2]: self._compound_profiler()
|
251 |
+
with tabs[3]: self._regulatory_hub()
|
252 |
+
with tabs[4]: self._ai_strategist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
+
def _drug_innovation(self):
|
255 |
+
"""Drug development strategy interface"""
|
256 |
+
st.header("AI-Powered Drug Innovation Engine")
|
257 |
+
col1, col2 = st.columns([1, 3])
|
|
|
|
|
|
|
258 |
|
|
|
259 |
with col1:
|
260 |
+
target = st.text_input("Target Pathobiology:", placeholder="e.g., EGFR mutant NSCLC")
|
261 |
+
strategy = st.selectbox("Development Paradigm:",
|
262 |
+
["First-in-class", "Fast-follower", "Biologic", "ADC", "Gene Therapy"])
|
263 |
+
if st.button("Generate Development Blueprint"):
|
264 |
+
with st.spinner("Formulating strategic plan..."):
|
265 |
+
blueprint = self.ai_innovator.generate_strategy(target, strategy)
|
266 |
+
st.markdown(blueprint, unsafe_allow_html=True)
|
267 |
+
|
268 |
+
def _trial_analytics(self):
|
269 |
+
"""Clinical trial analytics interface"""
|
270 |
+
st.header("Clinical Trial Landscape Analysis")
|
271 |
+
trial_query = st.text_input("Search Clinical Trials:", placeholder="Enter condition, intervention, or NCT number")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
+
if st.button("Analyze Trial Landscape"):
|
274 |
+
with st.spinner("Fetching trial data..."):
|
275 |
+
trials = self.clinical_intel.get_trial_landscape(trial_query)
|
276 |
+
|
277 |
if trials:
|
278 |
+
st.subheader("Top 5 Clinical Trials")
|
279 |
+
trial_data = []
|
280 |
+
for study in trials:
|
281 |
+
trial_data.append({
|
282 |
+
"Title": study.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A"),
|
283 |
+
"Status": study.get("protocolSection", {}).get("statusModule", {}).get("overallStatus", "N/A"),
|
284 |
+
"Phase": study.get("protocolSection", {}).get("designModule", {}).get("phases", ["N/A"])[0],
|
285 |
+
"Enrollment": study.get("protocolSection", {}).get("designModule", {}).get("enrollmentInfo", {}).get("count", "N/A")
|
286 |
+
})
|
287 |
+
|
288 |
+
# Display as a DataFrame
|
289 |
+
df = pd.DataFrame(trial_data)
|
290 |
+
st.dataframe(df)
|
291 |
+
|
292 |
+
# Visualization
|
293 |
+
st.subheader("Trial Phase Distribution")
|
294 |
+
phase_counts = df["Phase"].value_counts()
|
295 |
+
fig, ax = plt.subplots()
|
296 |
+
sns.barplot(x=phase_counts.index, y=phase_counts.values, ax=ax)
|
297 |
+
ax.set_xlabel("Trial Phase")
|
298 |
+
ax.set_ylabel("Number of Trials")
|
299 |
+
st.pyplot(fig)
|
300 |
else:
|
301 |
+
st.warning("No clinical trials found for the query.")
|
302 |
+
|
303 |
+
def _compound_profiler(self):
|
304 |
+
"""Advanced chemical analysis interface"""
|
305 |
+
st.header("Multi-Omics Compound Profiler")
|
306 |
+
compound = st.text_input("Analyze Compound:", placeholder="Enter drug name or SMILES")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
if compound:
|
309 |
+
with st.spinner("Decoding molecular profile..."):
|
310 |
+
profile = PharmaResearchEngine().get_compound_profile(compound)
|
311 |
+
|
312 |
+
if profile:
|
313 |
+
col1, col2 = st.columns(2)
|
314 |
+
with col1:
|
315 |
+
st.subheader("Structural Insights")
|
316 |
+
mol = Chem.MolFromSmiles(profile['canonical_smiles'])
|
317 |
+
if mol:
|
318 |
+
img = Draw.MolToImage(mol, size=(400, 300))
|
319 |
+
st.image(img, caption="2D Molecular Structure")
|
320 |
+
|
321 |
+
with col2:
|
322 |
+
st.subheader("Physicochemical Profile")
|
323 |
+
st.metric("Molecular Weight", profile['molecular_weight'])
|
324 |
+
st.metric("LogP", profile['logp'])
|
325 |
+
st.metric("IUPAC Name", profile['iupac_name'])
|
326 |
+
st.code(f"SMILES: {profile['canonical_smiles']}")
|
327 |
+
|
328 |
+
def _regulatory_hub(self):
|
329 |
+
"""Regulatory intelligence interface"""
|
330 |
+
st.header("Regulatory Intelligence Hub")
|
331 |
+
st.write("This section provides insights into FDA approvals and regulatory pathways.")
|
332 |
+
drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., aspirin")
|
|
|
|
|
|
|
333 |
|
334 |
+
if st.button("Fetch Regulatory Data"):
|
335 |
+
with st.spinner("Retrieving regulatory information..."):
|
336 |
+
fda_data = self.clinical_intel.get_fda_approval(drug_name)
|
337 |
if fda_data:
|
338 |
+
st.subheader("FDA Approval Details")
|
339 |
+
st.json(fda_data)
|
340 |
else:
|
341 |
+
st.warning("No FDA data found for the specified drug.")
|
342 |
+
|
343 |
+
def _ai_strategist(self):
|
344 |
+
"""AI-driven drug strategy interface"""
|
345 |
+
st.header("AI Drug Development Strategist")
|
346 |
+
st.write("Leverage GPT-4 for innovative drug development strategies.")
|
347 |
+
target = st.text_input("Enter Target Disease or Pathway:", placeholder="e.g., KRAS G12C mutation")
|
|
|
|
|
|
|
|
|
348 |
|
349 |
+
if st.button("Generate AI Strategy"):
|
350 |
+
with st.spinner("Generating AI-driven strategy..."):
|
351 |
+
strategy = self.ai_innovator.generate_strategy(target, "First-in-class")
|
352 |
+
st.markdown(strategy, unsafe_allow_html=True)
|
353 |
|
354 |
+
# -----------------------------
|
355 |
+
# MAIN EXECUTION
|
356 |
+
# -----------------------------
|
357 |
if __name__ == "__main__":
|
358 |
+
interface = PharmaResearchInterface()
|
359 |
+
interface.render()
|