Redesign: KPI header, date-precision honesty, paired charts
Browse files
app.py
CHANGED
|
@@ -1,91 +1,133 @@
|
|
| 1 |
"""BioIntel β biotech catalyst and wet-lab demand intelligence.
|
| 2 |
|
| 3 |
-
|
| 4 |
-
* SEC EDGAR 8-K full-text search β catalysts that have happened
|
| 5 |
* ClinicalTrials.gov v2 β dated catalysts that have not happened yet
|
| 6 |
|
| 7 |
Data is produced by the ingest pipeline and published as parquet to a Hugging
|
| 8 |
Face Dataset repo; this app downloads it once at startup and queries it in
|
| 9 |
-
memory.
|
| 10 |
-
which parts of the original thesis are not obtainable from public data.
|
| 11 |
"""
|
| 12 |
from __future__ import annotations
|
| 13 |
|
| 14 |
import json
|
| 15 |
import os
|
| 16 |
-
from datetime import
|
| 17 |
from pathlib import Path
|
| 18 |
|
| 19 |
import gradio as gr
|
| 20 |
import pandas as pd
|
| 21 |
import plotly.express as px
|
|
|
|
| 22 |
|
| 23 |
DATASET_REPO = os.environ.get("BIOINTEL_DATASET", "Umesh1608/biointel-data")
|
| 24 |
LOCAL_DATA = Path(os.environ.get("BIOINTEL_DATA",
|
| 25 |
Path.home() / "biointel" / "data"))
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
# --------------------------------------------------------------------------
|
| 33 |
-
# data
|
| 34 |
# --------------------------------------------------------------------------
|
| 35 |
-
def
|
| 36 |
-
|
| 37 |
-
local = LOCAL_DATA / f"{name}.parquet"
|
| 38 |
if local.exists():
|
| 39 |
-
return pd.read_parquet(local)
|
| 40 |
try:
|
| 41 |
from huggingface_hub import hf_hub_download
|
| 42 |
-
p = hf_hub_download(DATASET_REPO,
|
|
|
|
| 43 |
repo_type="dataset")
|
| 44 |
-
return pd.read_parquet(p)
|
| 45 |
-
except Exception as e: # noqa: BLE001 β
|
| 46 |
print(f"[warn] could not load {name}: {e}")
|
| 47 |
-
return pd.DataFrame()
|
| 48 |
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def freshness() -> str:
|
| 69 |
ts = MANIFEST.get("generated_at")
|
| 70 |
if not ts:
|
| 71 |
-
return "β
|
| 72 |
try:
|
| 73 |
gen = datetime.fromisoformat(ts)
|
| 74 |
-
|
| 75 |
except ValueError:
|
| 76 |
-
return f"Data generated {ts}
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
return (f"
|
| 80 |
-
f"
|
| 81 |
-
f"{c.get('catalysts', 0):,} catalysts Β· "
|
| 82 |
-
f"{c.get('readouts', 0):,} upcoming readouts")
|
| 83 |
|
| 84 |
|
| 85 |
# --------------------------------------------------------------------------
|
| 86 |
# tab 1 β catalyst feed
|
| 87 |
# --------------------------------------------------------------------------
|
| 88 |
-
|
| 89 |
|
| 90 |
|
| 91 |
def filter_catalysts(signals, neg_only, search, limit):
|
|
@@ -100,34 +142,56 @@ def filter_catalysts(signals, neg_only, search, limit):
|
|
| 100 |
s = search.strip().lower()
|
| 101 |
df = df[df.company.str.lower().str.contains(s, na=False)
|
| 102 |
| df.ticker.fillna("").str.lower().str.contains(s)]
|
| 103 |
-
out = df.sort_values("filed_date", ascending=False)[
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
def catalyst_trend(signals):
|
| 108 |
df = CATALYSTS
|
| 109 |
if df.empty:
|
| 110 |
-
return
|
| 111 |
if signals:
|
| 112 |
df = df[df.signal.isin(signals)]
|
|
|
|
|
|
|
| 113 |
d = df.copy()
|
| 114 |
-
d["week"] =
|
| 115 |
g = d.groupby(["week", "signal"]).size().reset_index(name="filings")
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
|
| 123 |
# --------------------------------------------------------------------------
|
| 124 |
# tab 2 β readout calendar
|
| 125 |
# --------------------------------------------------------------------------
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
|
| 130 |
-
def filter_readouts(phases, modalities, sponsor, months, limit):
|
| 131 |
df = READOUTS
|
| 132 |
if df.empty:
|
| 133 |
return pd.DataFrame({"note": ["No readout data loaded."]})
|
|
@@ -137,168 +201,259 @@ def filter_readouts(phases, modalities, sponsor, months, limit):
|
|
| 137 |
df = df[df.modality.isin(modalities)]
|
| 138 |
if sponsor:
|
| 139 |
df = df[df.sponsor.str.lower().str.contains(sponsor.strip().lower(), na=False)]
|
|
|
|
|
|
|
| 140 |
if months:
|
| 141 |
-
cutoff =
|
| 142 |
-
df = df[df.
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
def readout_chart(phases, modalities):
|
| 148 |
df = READOUTS
|
| 149 |
if df.empty:
|
| 150 |
-
return
|
| 151 |
if phases:
|
| 152 |
df = df[df.phase.isin(phases)]
|
| 153 |
if modalities:
|
| 154 |
df = df[df.modality.isin(modalities)]
|
|
|
|
|
|
|
| 155 |
d = df.copy()
|
| 156 |
-
d["month"] =
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
|
| 165 |
-
def
|
| 166 |
if READOUTS.empty:
|
| 167 |
-
return
|
| 168 |
-
g =
|
| 169 |
-
g.columns = ["
|
| 170 |
-
fig = px.
|
| 171 |
-
title="
|
| 172 |
-
fig.
|
| 173 |
-
|
| 174 |
-
return fig
|
| 175 |
|
| 176 |
|
| 177 |
-
# --------------------------------------------------------------------------
|
| 178 |
-
# UI
|
| 179 |
-
# --------------------------------------------------------------------------
|
| 180 |
def _choices(df, col):
|
| 181 |
return sorted(df[col].dropna().unique().tolist()) if not df.empty else []
|
| 182 |
|
| 183 |
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
ABOUT = f"""
|
| 187 |
-
## What this
|
| 188 |
|
| 189 |
Two public sources, joined into one view of biotech catalysts.
|
| 190 |
|
| 191 |
-
**SEC EDGAR 8-K full-text search** β what already happened. An 8-K is how a
|
| 192 |
US-listed company must announce a material event, so it is the closest public
|
| 193 |
thing to a ground-truth catalyst feed. Twelve signal types are matched on
|
| 194 |
-
phrase groups chosen by measurement, not guesswork: over a sample window
|
| 195 |
*"met its primary endpoint"* appeared in 54 filings where *"met the primary
|
| 196 |
-
endpoint"* appeared in 19, so both are searched.
|
|
|
|
| 197 |
|
| 198 |
-
**ClinicalTrials.gov API v2** β what is coming. A trial whose primary
|
| 199 |
completion date falls next quarter is a dated, public, not-yet-happened
|
| 200 |
catalyst. Only industry-sponsored trials are kept.
|
| 201 |
|
| 202 |
-
##
|
| 203 |
-
|
| 204 |
-
* **
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
* **
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
## Attribution and licensing
|
| 226 |
|
| 227 |
**ClinicalTrials.gov.** Trial data courtesy of the U.S. National Library of
|
| 228 |
Medicine, retrieved from the ClinicalTrials.gov API v2. **Processing date:
|
| 229 |
-
{PROC_DATE}.** The data
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
market-data free tier. There is **no free, redistributable source of options
|
| 245 |
-
or intraday price data**, so the options-flow signal in the original thesis is
|
| 246 |
-
not replicated here rather than being approximated from a prohibited source.
|
| 247 |
"""
|
| 248 |
|
| 249 |
-
with gr.Blocks(title="BioIntel") as demo:
|
| 250 |
-
gr.
|
| 251 |
-
|
| 252 |
-
gr.
|
| 253 |
-
|
| 254 |
-
"(ClinicalTrials.gov), modified β see **About**. SEC filings are public "
|
| 255 |
-
"domain. Not investment advice.</sub>")
|
| 256 |
|
| 257 |
with gr.Tab("Catalyst feed"):
|
| 258 |
-
gr.
|
| 259 |
-
|
|
|
|
| 260 |
with gr.Row():
|
| 261 |
f_sig = gr.Dropdown(_choices(CATALYSTS, "signal"), multiselect=True,
|
| 262 |
label="Signal", scale=3)
|
|
|
|
|
|
|
| 263 |
f_neg = gr.Checkbox(label="Negative only", scale=1)
|
| 264 |
-
f_q = gr.Textbox(label="Company or ticker", scale=2)
|
| 265 |
f_lim = gr.Slider(25, 1000, value=150, step=25, label="Rows", scale=2)
|
| 266 |
t_cat = gr.Dataframe(value=filter_catalysts([], False, "", 150),
|
| 267 |
-
wrap=True, max_height=
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
f_sig
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
with gr.Tab("Readout calendar"):
|
| 274 |
-
gr.
|
| 275 |
-
|
|
|
|
|
|
|
| 276 |
with gr.Row():
|
| 277 |
r_ph = gr.Dropdown(_choices(READOUTS, "phase"), multiselect=True,
|
| 278 |
label="Phase", scale=2)
|
| 279 |
r_mod = gr.Dropdown(_choices(READOUTS, "modality"), multiselect=True,
|
| 280 |
label="Modality", scale=2)
|
| 281 |
-
r_sp = gr.Textbox(label="Sponsor contains",
|
|
|
|
| 282 |
r_mo = gr.Slider(1, 12, value=6, step=1, label="Within months", scale=2)
|
|
|
|
| 283 |
r_lim = gr.Slider(25, 1000, value=150, step=25, label="Rows", scale=1)
|
| 284 |
-
t_ro = gr.Dataframe(value=filter_readouts([], [], "", 6, 150),
|
| 285 |
-
wrap=True, max_height=
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
| 289 |
for c in (r_ph, r_mod):
|
| 290 |
c.change(readout_chart, [r_ph, r_mod], p_ro)
|
|
|
|
| 291 |
|
| 292 |
-
with gr.Tab("
|
| 293 |
-
gr.
|
| 294 |
-
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
-
with gr.Tab("About"):
|
| 298 |
gr.Markdown(ABOUT)
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
if __name__ == "__main__":
|
| 301 |
-
|
| 302 |
-
# HF Spaces runs this file as __main__, so the theme applies there too.
|
| 303 |
-
demo.launch(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="blue"),
|
| 304 |
server_name="0.0.0.0")
|
|
|
|
| 1 |
"""BioIntel β biotech catalyst and wet-lab demand intelligence.
|
| 2 |
|
| 3 |
+
Two public sources, joined into one view:
|
| 4 |
+
* SEC EDGAR 8-K full-text search β catalysts that have already happened
|
| 5 |
* ClinicalTrials.gov v2 β dated catalysts that have not happened yet
|
| 6 |
|
| 7 |
Data is produced by the ingest pipeline and published as parquet to a Hugging
|
| 8 |
Face Dataset repo; this app downloads it once at startup and queries it in
|
| 9 |
+
memory. Not investment advice.
|
|
|
|
| 10 |
"""
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
import json
|
| 14 |
import os
|
| 15 |
+
from datetime import datetime, timezone
|
| 16 |
from pathlib import Path
|
| 17 |
|
| 18 |
import gradio as gr
|
| 19 |
import pandas as pd
|
| 20 |
import plotly.express as px
|
| 21 |
+
import plotly.graph_objects as go
|
| 22 |
|
| 23 |
DATASET_REPO = os.environ.get("BIOINTEL_DATASET", "Umesh1608/biointel-data")
|
| 24 |
LOCAL_DATA = Path(os.environ.get("BIOINTEL_DATA",
|
| 25 |
Path.home() / "biointel" / "data"))
|
| 26 |
|
| 27 |
+
# A restrained palette: one accent, one alarm colour, everything else neutral.
|
| 28 |
+
INK, ACCENT, ALARM, MUTED = "#0F172A", "#0D9488", "#DC2626", "#64748B"
|
| 29 |
+
SERIES = ["#0D9488", "#0EA5E9", "#8B5CF6", "#F59E0B", "#DC2626", "#10B981",
|
| 30 |
+
"#6366F1", "#EC4899", "#14B8A6", "#F97316", "#64748B", "#84CC16"]
|
| 31 |
+
NEGATIVE_SIGNALS = {"endpoint_missed", "crl", "clinical_hold", "discontinue"}
|
| 32 |
|
| 33 |
|
| 34 |
# --------------------------------------------------------------------------
|
| 35 |
+
# data
|
| 36 |
# --------------------------------------------------------------------------
|
| 37 |
+
def _load(name: str, parquet: bool = True):
|
| 38 |
+
local = LOCAL_DATA / (f"{name}.parquet" if parquet else name)
|
|
|
|
| 39 |
if local.exists():
|
| 40 |
+
return pd.read_parquet(local) if parquet else json.loads(local.read_text())
|
| 41 |
try:
|
| 42 |
from huggingface_hub import hf_hub_download
|
| 43 |
+
p = hf_hub_download(DATASET_REPO,
|
| 44 |
+
f"data/{name}.parquet" if parquet else f"data/{name}",
|
| 45 |
repo_type="dataset")
|
| 46 |
+
return pd.read_parquet(p) if parquet else json.loads(Path(p).read_text())
|
| 47 |
+
except Exception as e: # noqa: BLE001 β render the shell even with no data
|
| 48 |
print(f"[warn] could not load {name}: {e}")
|
| 49 |
+
return pd.DataFrame() if parquet else {}
|
| 50 |
|
| 51 |
|
| 52 |
+
CATALYSTS = _load("catalysts")
|
| 53 |
+
READOUTS = _load("readouts")
|
| 54 |
+
MANIFEST = _load("manifest.json", parquet=False)
|
| 55 |
+
PROC_DATE = (MANIFEST.get("generated_at") or "unknown")[:10]
|
| 56 |
+
|
| 57 |
+
for _df, _col in ((CATALYSTS, "filed_date"), (READOUTS, "primary_completion")):
|
| 58 |
+
if not _df.empty:
|
| 59 |
+
_df["_dt"] = pd.to_datetime(_df[_col], errors="coerce")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _style(fig, height=380):
|
| 63 |
+
"""One chart style everywhere: no chartjunk, muted grid, honest axes."""
|
| 64 |
+
fig.update_layout(
|
| 65 |
+
height=height, margin=dict(l=8, r=8, t=48, b=8),
|
| 66 |
+
font=dict(family="Inter, ui-sans-serif, system-ui", size=12.5),
|
| 67 |
+
title=dict(font=dict(size=15), x=0, xanchor="left"),
|
| 68 |
+
plot_bgcolor="rgba(0,0,0,0)", paper_bgcolor="rgba(0,0,0,0)",
|
| 69 |
+
legend=dict(title_text="", orientation="h", y=-0.18, font=dict(size=11)),
|
| 70 |
+
colorway=SERIES, hoverlabel=dict(font_size=12),
|
| 71 |
+
)
|
| 72 |
+
fig.update_xaxes(showgrid=False, linecolor="rgba(100,116,139,.25)", title=None)
|
| 73 |
+
fig.update_yaxes(gridcolor="rgba(100,116,139,.15)", zeroline=False,
|
| 74 |
+
linecolor="rgba(0,0,0,0)", title=None)
|
| 75 |
+
return fig
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _empty(msg="No data loaded"):
|
| 79 |
+
f = go.Figure()
|
| 80 |
+
f.add_annotation(text=msg, showarrow=False, font=dict(size=14, color=MUTED))
|
| 81 |
+
f.update_layout(height=320, plot_bgcolor="rgba(0,0,0,0)",
|
| 82 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
| 83 |
+
xaxis=dict(visible=False), yaxis=dict(visible=False))
|
| 84 |
+
return f
|
| 85 |
|
| 86 |
|
| 87 |
+
# --------------------------------------------------------------------------
|
| 88 |
+
# header
|
| 89 |
+
# --------------------------------------------------------------------------
|
| 90 |
+
def kpis() -> str:
|
| 91 |
+
if CATALYSTS.empty and READOUTS.empty:
|
| 92 |
+
return "<div class='bi-kpis'><div class='bi-card'>No data</div></div>"
|
| 93 |
+
n_cat = len(CATALYSTS)
|
| 94 |
+
n_neg = int(CATALYSTS.negative.sum()) if not CATALYSTS.empty else 0
|
| 95 |
+
n_co = CATALYSTS.company.nunique() if not CATALYSTS.empty else 0
|
| 96 |
+
n_ro = len(READOUTS)
|
| 97 |
+
n_ph3 = int(READOUTS.phase.str.contains("Ph3", na=False).sum()) if not READOUTS.empty else 0
|
| 98 |
+
cards = [
|
| 99 |
+
("Catalyst events", f"{n_cat:,}", "8-K filings Β· last 90 days"),
|
| 100 |
+
("Companies", f"{n_co:,}", "distinct issuers"),
|
| 101 |
+
("Negative signals", f"{n_neg:,}", f"{n_neg / max(n_cat, 1):.0%} of events"),
|
| 102 |
+
("Upcoming readouts", f"{n_ro:,}", "industry trials Β· next 12 mo"),
|
| 103 |
+
("Phase 3 ahead", f"{n_ph3:,}", "highest-stakes subset"),
|
| 104 |
+
]
|
| 105 |
+
html = "".join(
|
| 106 |
+
f"<div class='bi-card'><div class='bi-label'>{lbl}</div>"
|
| 107 |
+
f"<div class='bi-value'>{val}</div><div class='bi-sub'>{sub}</div></div>"
|
| 108 |
+
for lbl, val, sub in cards)
|
| 109 |
+
return f"<div class='bi-kpis'>{html}</div>"
|
| 110 |
|
| 111 |
|
| 112 |
def freshness() -> str:
|
| 113 |
ts = MANIFEST.get("generated_at")
|
| 114 |
if not ts:
|
| 115 |
+
return "<div class='bi-stale'>β No manifest found β data may be missing.</div>"
|
| 116 |
try:
|
| 117 |
gen = datetime.fromisoformat(ts)
|
| 118 |
+
age = (datetime.now(timezone.utc) - gen).total_seconds() / 3600
|
| 119 |
except ValueError:
|
| 120 |
+
return f"<div class='bi-fresh'>Data generated {ts}</div>"
|
| 121 |
+
cls = "bi-stale" if age > 48 else "bi-fresh"
|
| 122 |
+
note = " β stale, the refresh job may have failed" if age > 48 else ""
|
| 123 |
+
return (f"<div class='{cls}'>β Data generated "
|
| 124 |
+
f"<b>{gen:%d %b %Y, %H:%M} UTC</b> Β· {age:.0f}h ago{note}</div>")
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
# --------------------------------------------------------------------------
|
| 128 |
# tab 1 β catalyst feed
|
| 129 |
# --------------------------------------------------------------------------
|
| 130 |
+
CAT_COLS = ["filed_date", "ticker", "company", "signal", "negative", "url"]
|
| 131 |
|
| 132 |
|
| 133 |
def filter_catalysts(signals, neg_only, search, limit):
|
|
|
|
| 142 |
s = search.strip().lower()
|
| 143 |
df = df[df.company.str.lower().str.contains(s, na=False)
|
| 144 |
| df.ticker.fillna("").str.lower().str.contains(s)]
|
| 145 |
+
out = df.sort_values("filed_date", ascending=False)[CAT_COLS].head(int(limit)).copy()
|
| 146 |
+
out["negative"] = out.negative.map({True: "βΌ negative", False: ""})
|
| 147 |
+
return out.rename(columns={"filed_date": "Filed", "ticker": "Ticker",
|
| 148 |
+
"company": "Company", "signal": "Signal",
|
| 149 |
+
"negative": "Tone", "url": "Filing"})
|
| 150 |
|
| 151 |
|
| 152 |
def catalyst_trend(signals):
|
| 153 |
df = CATALYSTS
|
| 154 |
if df.empty:
|
| 155 |
+
return _empty()
|
| 156 |
if signals:
|
| 157 |
df = df[df.signal.isin(signals)]
|
| 158 |
+
if df.empty:
|
| 159 |
+
return _empty("No events match these filters")
|
| 160 |
d = df.copy()
|
| 161 |
+
d["week"] = d._dt.dt.to_period("W").dt.start_time
|
| 162 |
g = d.groupby(["week", "signal"]).size().reset_index(name="filings")
|
| 163 |
+
return _style(px.bar(g, x="week", y="filings", color="signal",
|
| 164 |
+
title="Catalyst filings per week"))
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def catalyst_mix(signals):
|
| 168 |
+
df = CATALYSTS
|
| 169 |
+
if df.empty:
|
| 170 |
+
return _empty()
|
| 171 |
+
if signals:
|
| 172 |
+
df = df[df.signal.isin(signals)]
|
| 173 |
+
if df.empty:
|
| 174 |
+
return _empty("No events match these filters")
|
| 175 |
+
g = df.signal.value_counts().reset_index()
|
| 176 |
+
g.columns = ["signal", "events"]
|
| 177 |
+
g["tone"] = g.signal.isin(NEGATIVE_SIGNALS).map(
|
| 178 |
+
{True: "negative", False: "neutral / positive"})
|
| 179 |
+
fig = px.bar(g, x="events", y="signal", orientation="h", color="tone",
|
| 180 |
+
color_discrete_map={"negative": ALARM,
|
| 181 |
+
"neutral / positive": ACCENT},
|
| 182 |
+
title="Which signals are firing")
|
| 183 |
+
fig.update_layout(yaxis=dict(autorange="reversed"))
|
| 184 |
+
return _style(fig)
|
| 185 |
|
| 186 |
|
| 187 |
# --------------------------------------------------------------------------
|
| 188 |
# tab 2 β readout calendar
|
| 189 |
# --------------------------------------------------------------------------
|
| 190 |
+
RO_COLS = ["primary_completion", "date_precision", "phase", "sponsor",
|
| 191 |
+
"modality", "conditions", "enrollment", "url"]
|
| 192 |
|
| 193 |
|
| 194 |
+
def filter_readouts(phases, modalities, sponsor, months, exact_only, limit):
|
| 195 |
df = READOUTS
|
| 196 |
if df.empty:
|
| 197 |
return pd.DataFrame({"note": ["No readout data loaded."]})
|
|
|
|
| 201 |
df = df[df.modality.isin(modalities)]
|
| 202 |
if sponsor:
|
| 203 |
df = df[df.sponsor.str.lower().str.contains(sponsor.strip().lower(), na=False)]
|
| 204 |
+
if exact_only and "date_precision" in df.columns:
|
| 205 |
+
df = df[df.date_precision == "day"]
|
| 206 |
if months:
|
| 207 |
+
cutoff = pd.Timestamp.today() + pd.DateOffset(months=int(months))
|
| 208 |
+
df = df[df._dt <= cutoff]
|
| 209 |
+
cols = [c for c in RO_COLS if c in df.columns]
|
| 210 |
+
out = df.sort_values("primary_completion")[cols].head(int(limit)).copy()
|
| 211 |
+
if "date_precision" in out.columns:
|
| 212 |
+
out["date_precision"] = out.date_precision.map(
|
| 213 |
+
{"day": "exact", "month": "month only",
|
| 214 |
+
"year": "year only"}).fillna("β")
|
| 215 |
+
return out.rename(columns={"primary_completion": "Readout due",
|
| 216 |
+
"date_precision": "Date precision",
|
| 217 |
+
"phase": "Phase", "sponsor": "Sponsor",
|
| 218 |
+
"modality": "Modality", "conditions": "Condition",
|
| 219 |
+
"enrollment": "N", "url": "Registry"})
|
| 220 |
|
| 221 |
|
| 222 |
def readout_chart(phases, modalities):
|
| 223 |
df = READOUTS
|
| 224 |
if df.empty:
|
| 225 |
+
return _empty()
|
| 226 |
if phases:
|
| 227 |
df = df[df.phase.isin(phases)]
|
| 228 |
if modalities:
|
| 229 |
df = df[df.modality.isin(modalities)]
|
| 230 |
+
if df.empty:
|
| 231 |
+
return _empty("No trials match these filters")
|
| 232 |
d = df.copy()
|
| 233 |
+
d["month"] = d._dt.dt.to_period("M").dt.start_time
|
| 234 |
+
d["precision"] = (d.date_precision.map({"day": "exact date",
|
| 235 |
+
"month": "month only"})
|
| 236 |
+
.fillna("month only")
|
| 237 |
+
if "date_precision" in d.columns else "unknown")
|
| 238 |
+
g = d.groupby(["month", "precision"]).size().reset_index(name="trials")
|
| 239 |
+
fig = px.bar(g, x="month", y="trials", color="precision",
|
| 240 |
+
color_discrete_map={"exact date": ACCENT,
|
| 241 |
+
"month only": "#CBD5E1"},
|
| 242 |
+
title="Readouts by month β split by how precise the date is")
|
| 243 |
+
return _style(fig)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def modality_chart(phases):
|
| 247 |
+
df = READOUTS
|
| 248 |
+
if df.empty:
|
| 249 |
+
return _empty()
|
| 250 |
+
if phases:
|
| 251 |
+
df = df[df.phase.isin(phases)]
|
| 252 |
+
if df.empty:
|
| 253 |
+
return _empty("No trials match these filters")
|
| 254 |
+
g = df.modality.value_counts().reset_index()
|
| 255 |
+
g.columns = ["modality", "trials"]
|
| 256 |
+
fig = px.bar(g.head(12), x="trials", y="modality", orientation="h",
|
| 257 |
+
title="Modality mix of the forward pipeline")
|
| 258 |
+
fig.update_traces(marker_color=ACCENT)
|
| 259 |
+
fig.update_layout(yaxis=dict(autorange="reversed"))
|
| 260 |
+
return _style(fig)
|
| 261 |
|
| 262 |
|
| 263 |
+
def phase_chart():
|
| 264 |
if READOUTS.empty:
|
| 265 |
+
return _empty()
|
| 266 |
+
g = READOUTS.phase.value_counts().reset_index()
|
| 267 |
+
g.columns = ["phase", "trials"]
|
| 268 |
+
fig = px.pie(g.head(8), names="phase", values="trials", hole=0.62,
|
| 269 |
+
title="Phase mix")
|
| 270 |
+
fig.update_traces(textposition="outside", textinfo="label+percent")
|
| 271 |
+
return _style(fig)
|
|
|
|
| 272 |
|
| 273 |
|
|
|
|
|
|
|
|
|
|
| 274 |
def _choices(df, col):
|
| 275 |
return sorted(df[col].dropna().unique().tolist()) if not df.empty else []
|
| 276 |
|
| 277 |
|
| 278 |
+
# --------------------------------------------------------------------------
|
| 279 |
+
# styling
|
| 280 |
+
# --------------------------------------------------------------------------
|
| 281 |
+
CSS = """
|
| 282 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
| 283 |
+
|
| 284 |
+
.gradio-container { font-family:'Inter',ui-sans-serif,system-ui !important;
|
| 285 |
+
max-width:1460px !important; }
|
| 286 |
+
|
| 287 |
+
#bi-hero { padding:6px 0 0; }
|
| 288 |
+
#bi-hero h1 { font-size:2.1rem; font-weight:700; letter-spacing:-.028em;
|
| 289 |
+
margin:0; line-height:1.1; }
|
| 290 |
+
#bi-hero p { margin:.35rem 0 0; color:#64748B; font-size:1.02rem; }
|
| 291 |
+
|
| 292 |
+
.bi-kpis { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr));
|
| 293 |
+
gap:12px; margin:14px 0 8px; }
|
| 294 |
+
.bi-card { background:var(--block-background-fill); border:1px solid var(--border-color-primary);
|
| 295 |
+
border-radius:14px; padding:14px 16px; }
|
| 296 |
+
.bi-label { font-size:.7rem; font-weight:600; letter-spacing:.08em;
|
| 297 |
+
text-transform:uppercase; color:#64748B; }
|
| 298 |
+
.bi-value { font-size:1.9rem; font-weight:700; line-height:1.15; margin:.2rem 0;
|
| 299 |
+
font-variant-numeric:tabular-nums; letter-spacing:-.02em; }
|
| 300 |
+
.bi-sub { font-size:.75rem; color:#94A3B8; }
|
| 301 |
+
|
| 302 |
+
.bi-fresh, .bi-stale { display:inline-block; font-size:.8rem; padding:5px 12px;
|
| 303 |
+
border-radius:999px; margin:6px 0 2px; font-weight:500; }
|
| 304 |
+
.bi-fresh { background:#ECFDF5; color:#047857; border:1px solid #A7F3D0; }
|
| 305 |
+
.bi-stale { background:#FEF2F2; color:#B91C1C; border:1px solid #FECACA; }
|
| 306 |
+
.dark .bi-fresh { background:#06281F; border-color:#115E4A; color:#5EEAD4; }
|
| 307 |
+
.dark .bi-stale { background:#2A1113; border-color:#7F1D1D; color:#FCA5A5; }
|
| 308 |
+
|
| 309 |
+
.bi-note { font-size:.84rem; color:#64748B; border-left:3px solid #0D9488;
|
| 310 |
+
padding:3px 0 3px 12px; margin:6px 0 14px; line-height:1.5; }
|
| 311 |
+
|
| 312 |
+
footer, .built-with { display:none !important; }
|
| 313 |
+
.tab-nav button { font-weight:600 !important; font-size:.95rem !important; }
|
| 314 |
+
"""
|
| 315 |
|
| 316 |
ABOUT = f"""
|
| 317 |
+
## What this shows
|
| 318 |
|
| 319 |
Two public sources, joined into one view of biotech catalysts.
|
| 320 |
|
| 321 |
+
**SEC EDGAR 8-K full-text search** β *what already happened.* An 8-K is how a
|
| 322 |
US-listed company must announce a material event, so it is the closest public
|
| 323 |
thing to a ground-truth catalyst feed. Twelve signal types are matched on
|
| 324 |
+
phrase groups chosen by **measurement, not guesswork**: over a sample window
|
| 325 |
*"met its primary endpoint"* appeared in 54 filings where *"met the primary
|
| 326 |
+
endpoint"* appeared in 19, so both are searched. EDGAR accepts uppercase `OR`
|
| 327 |
+
between quoted phrases β a `|` silently returns zero results.
|
| 328 |
|
| 329 |
+
**ClinicalTrials.gov API v2** β *what is coming.* A trial whose primary
|
| 330 |
completion date falls next quarter is a dated, public, not-yet-happened
|
| 331 |
catalyst. Only industry-sponsored trials are kept.
|
| 332 |
|
| 333 |
+
## Read these caveats before trusting a number
|
| 334 |
+
|
| 335 |
+
* **40% of readout dates are month-only.** Sponsors often register just
|
| 336 |
+
`2026-12`. Converting that to a day manufactures precision: in one sample
|
| 337 |
+
46% of trials landed on day 1 purely as an artifact of that conversion, and
|
| 338 |
+
a further 28% sat on month-end placeholders. A naive chart shows a December
|
| 339 |
+
"catalyst wall" of 913 trials that is mostly rounding. The calendar
|
| 340 |
+
therefore **labels every date's precision** and can filter to exact dates.
|
| 341 |
+
* **Signals co-occur, and that is real.** One 8-K can match both *endpoint
|
| 342 |
+
met* and *endpoint missed* β a release reporting a hit on one endpoint and a
|
| 343 |
+
miss on another. Treat the columns as flags, not a verdict.
|
| 344 |
+
* **Trial dates slip.** A primary completion date is a plan, not a commitment.
|
| 345 |
+
* **Modality is inferred**, not a registry field. It reports `unknown` rather
|
| 346 |
+
than guessing, because a wrong label is worse than a missing one.
|
| 347 |
+
* **Not every catalyst is an 8-K.** Conference presentations and releases not
|
| 348 |
+
deemed material never appear.
|
| 349 |
+
* **Both APIs truncate silently.** One EDGAR call returns at most 100 hits
|
| 350 |
+
regardless of the reported total, and filtering trials client-side after a
|
| 351 |
+
truncated fetch drops most of the result set. Both are paged and filtered
|
| 352 |
+
server-side here.
|
| 353 |
+
|
| 354 |
+
## What is *not* here, and why
|
| 355 |
+
|
| 356 |
+
The thesis this was modelled on promises CRO lab occupancy, lease renewal
|
| 357 |
+
spreads and options flow. **Those are not obtainable from public data.** There
|
| 358 |
+
is no free, redistributable source of options or intraday price data β OPRA
|
| 359 |
+
licensing runs \\$650β1,500/month β so that signal is **not replicated** rather
|
| 360 |
+
than approximated from a prohibited source. Public proxies for lab demand do
|
| 361 |
+
exist and are the natural next addition. Facility-level utilisation is not
|
| 362 |
+
among them: Charles River's own 10-K says it tracks room utilisation and
|
| 363 |
+
prints no figure.
|
| 364 |
|
| 365 |
## Attribution and licensing
|
| 366 |
|
| 367 |
**ClinicalTrials.gov.** Trial data courtesy of the U.S. National Library of
|
| 368 |
Medicine, retrieved from the ClinicalTrials.gov API v2. **Processing date:
|
| 369 |
+
{PROC_DATE}.** The data has been **modified** from source: filtered to
|
| 370 |
+
industry-sponsored studies with a future primary completion date, dates
|
| 371 |
+
normalised for sorting with their original precision retained in a separate
|
| 372 |
+
column, and a `modality` label **inferred** by this project from intervention
|
| 373 |
+
names and titles. NLM does not endorse this reuse.
|
| 374 |
+
|
| 375 |
+
**SEC EDGAR.** Filings are public information and may be copied or further
|
| 376 |
+
distributed without the SEC's permission. Accessed within the published
|
| 377 |
+
10 requests/second limit with a descriptive User-Agent.
|
| 378 |
+
|
| 379 |
+
Sources whose terms forbid redistribution or automated retrieval are
|
| 380 |
+
deliberately **excluded** β PMC full text, EPO OPS, and every commercial
|
| 381 |
+
market-data free tier. The PatentsView API was retired in March 2026.
|
| 382 |
+
|
| 383 |
+
**An information tool built on public filings. Not investment advice.**
|
|
|
|
|
|
|
|
|
|
| 384 |
"""
|
| 385 |
|
| 386 |
+
with gr.Blocks(title="BioIntel", css=CSS, fill_width=True) as demo:
|
| 387 |
+
gr.HTML("<div id='bi-hero'><h1>BioIntel</h1><p>Biotech catalyst "
|
| 388 |
+
"intelligence from public filings and trial registries</p></div>")
|
| 389 |
+
gr.HTML(freshness())
|
| 390 |
+
gr.HTML(kpis())
|
|
|
|
|
|
|
| 391 |
|
| 392 |
with gr.Tab("Catalyst feed"):
|
| 393 |
+
gr.HTML("<div class='bi-note'>8-K filings matching clinical and "
|
| 394 |
+
"regulatory catalyst language. <b>Tone</b> marks signals that are "
|
| 395 |
+
"usually bad news β though a single filing can carry both.</div>")
|
| 396 |
with gr.Row():
|
| 397 |
f_sig = gr.Dropdown(_choices(CATALYSTS, "signal"), multiselect=True,
|
| 398 |
label="Signal", scale=3)
|
| 399 |
+
f_q = gr.Textbox(label="Company or ticker",
|
| 400 |
+
placeholder="e.g. BridgeBio, EYPT", scale=2)
|
| 401 |
f_neg = gr.Checkbox(label="Negative only", scale=1)
|
|
|
|
| 402 |
f_lim = gr.Slider(25, 1000, value=150, step=25, label="Rows", scale=2)
|
| 403 |
t_cat = gr.Dataframe(value=filter_catalysts([], False, "", 150),
|
| 404 |
+
wrap=True, max_height=430)
|
| 405 |
+
with gr.Row():
|
| 406 |
+
p_trend = gr.Plot(catalyst_trend([]))
|
| 407 |
+
p_mix = gr.Plot(catalyst_mix([]))
|
| 408 |
+
cins = [f_sig, f_neg, f_q, f_lim]
|
| 409 |
+
for c in cins:
|
| 410 |
+
c.change(filter_catalysts, cins, t_cat)
|
| 411 |
+
f_sig.change(catalyst_trend, f_sig, p_trend)
|
| 412 |
+
f_sig.change(catalyst_mix, f_sig, p_mix)
|
| 413 |
|
| 414 |
with gr.Tab("Readout calendar"):
|
| 415 |
+
gr.HTML("<div class='bi-note'>Industry trials with a primary completion "
|
| 416 |
+
"date ahead. <b>40% of registry dates are month-only</b> β the "
|
| 417 |
+
"precision column says which, and the chart separates them so a "
|
| 418 |
+
"rounding artifact cannot read as a catalyst cluster.</div>")
|
| 419 |
with gr.Row():
|
| 420 |
r_ph = gr.Dropdown(_choices(READOUTS, "phase"), multiselect=True,
|
| 421 |
label="Phase", scale=2)
|
| 422 |
r_mod = gr.Dropdown(_choices(READOUTS, "modality"), multiselect=True,
|
| 423 |
label="Modality", scale=2)
|
| 424 |
+
r_sp = gr.Textbox(label="Sponsor contains",
|
| 425 |
+
placeholder="e.g. Novartis", scale=2)
|
| 426 |
r_mo = gr.Slider(1, 12, value=6, step=1, label="Within months", scale=2)
|
| 427 |
+
r_ex = gr.Checkbox(label="Exact dates only", scale=1)
|
| 428 |
r_lim = gr.Slider(25, 1000, value=150, step=25, label="Rows", scale=1)
|
| 429 |
+
t_ro = gr.Dataframe(value=filter_readouts([], [], "", 6, False, 150),
|
| 430 |
+
wrap=True, max_height=430)
|
| 431 |
+
with gr.Row():
|
| 432 |
+
p_ro = gr.Plot(readout_chart([], []))
|
| 433 |
+
p_mod = gr.Plot(modality_chart([]))
|
| 434 |
+
rins = [r_ph, r_mod, r_sp, r_mo, r_ex, r_lim]
|
| 435 |
+
for c in rins:
|
| 436 |
+
c.change(filter_readouts, rins, t_ro)
|
| 437 |
for c in (r_ph, r_mod):
|
| 438 |
c.change(readout_chart, [r_ph, r_mod], p_ro)
|
| 439 |
+
r_ph.change(modality_chart, r_ph, p_mod)
|
| 440 |
|
| 441 |
+
with gr.Tab("Pipeline mix"):
|
| 442 |
+
gr.HTML("<div class='bi-note'>Modality and phase mix of the forward "
|
| 443 |
+
"pipeline β the closest public read on what kind of wet-lab and "
|
| 444 |
+
"manufacturing capacity will be needed.</div>")
|
| 445 |
+
with gr.Row():
|
| 446 |
+
gr.Plot(modality_chart([]))
|
| 447 |
+
gr.Plot(phase_chart())
|
| 448 |
|
| 449 |
+
with gr.Tab("About & caveats"):
|
| 450 |
gr.Markdown(ABOUT)
|
| 451 |
|
| 452 |
+
gr.HTML("<div style='margin-top:16px;font-size:.78rem;color:#94A3B8'>"
|
| 453 |
+
"Trial data courtesy of the U.S. National Library of Medicine "
|
| 454 |
+
"(ClinicalTrials.gov), modified β see About. SEC filings are public "
|
| 455 |
+
"domain. Not investment advice.</div>")
|
| 456 |
+
|
| 457 |
if __name__ == "__main__":
|
| 458 |
+
demo.launch(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate"),
|
|
|
|
|
|
|
| 459 |
server_name="0.0.0.0")
|