Initial Gradio demo for epibarrett
Browse files- README.md +6 -0
- app.py +62 -0
- requirements.txt +7 -0
README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# epibarrett demo
|
| 2 |
+
|
| 3 |
+
A Gradio interface for the epibarrett BE/EAC methylation classifier.
|
| 4 |
+
|
| 5 |
+
Upload a CSV of HM450-style beta values (samples × probes) and get calibrated
|
| 6 |
+
BE/EAC probabilities from the genome-wide LASSO panel.
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Gradio demo for epibarrett BE/EAC methylation classifier."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import tempfile
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import joblib
|
| 10 |
+
import pandas as pd
|
| 11 |
+
from huggingface_hub import hf_hub_download
|
| 12 |
+
|
| 13 |
+
REPO_ID = "kmlyyll/epibarrett-model"
|
| 14 |
+
BUNDLE_PATH = Path("epibarrett_model.joblib")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _load_bundle():
|
| 18 |
+
if not BUNDLE_PATH.exists():
|
| 19 |
+
hf_hub_download(REPO_ID, filename="epibarrett_model.joblib", local_dir=".")
|
| 20 |
+
return joblib.load(BUNDLE_PATH)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
BUNDLE = _load_bundle()
|
| 24 |
+
LASSO = BUNDLE["lasso"]
|
| 25 |
+
PREPROCESSOR = BUNDLE["preprocessor"]
|
| 26 |
+
PROBE_NAMES = BUNDLE["probe_names"]
|
| 27 |
+
CLINICAL_FEATURES = BUNDLE["clinical_features"]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def predict(csv_file):
|
| 31 |
+
X = pd.read_csv(csv_file.name, index_col=0)
|
| 32 |
+
missing = [p for p in PROBE_NAMES if p not in X.columns]
|
| 33 |
+
if missing:
|
| 34 |
+
raise gr.Error(
|
| 35 |
+
f"Missing {len(missing)} expected probe columns (e.g. {missing[:5]})."
|
| 36 |
+
)
|
| 37 |
+
M = PREPROCESSOR.transform(X[PROBE_NAMES])
|
| 38 |
+
proba = LASSO.predict_proba(M.to_numpy())[:, 1]
|
| 39 |
+
out = pd.DataFrame(
|
| 40 |
+
{"sample_id": X.index, "BE_EAC_probability": proba, "risk_call": (proba >= 0.5).astype(int)}
|
| 41 |
+
)
|
| 42 |
+
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|
| 43 |
+
out.to_csv(tmp.name, index=False)
|
| 44 |
+
return out, tmp.name
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
with gr.Blocks(title="epibarrett BE/EAC classifier") as demo:
|
| 48 |
+
gr.Markdown(
|
| 49 |
+
"""
|
| 50 |
+
# epibarrett demo
|
| 51 |
+
Upload a CSV of HM450-style beta values (rows = samples, columns = CpG probes).
|
| 52 |
+
The model returns a calibrated probability of Barrett's esophagus / EAC for each sample.
|
| 53 |
+
"""
|
| 54 |
+
)
|
| 55 |
+
file_in = gr.File(label="Upload beta-value CSV", file_types=[".csv"])
|
| 56 |
+
btn = gr.Button("Predict")
|
| 57 |
+
table_out = gr.Dataframe(label="Predictions")
|
| 58 |
+
file_out = gr.File(label="Download predictions CSV")
|
| 59 |
+
btn.click(fn=predict, inputs=file_in, outputs=[table_out, file_out])
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
epibarrett @ git+https://github.com/lynchaos/epibarrett.git@main
|
| 2 |
+
gradio>=4.0
|
| 3 |
+
huggingface-hub>=0.20
|
| 4 |
+
joblib>=1.3
|
| 5 |
+
numpy>=1.24
|
| 6 |
+
pandas>=2.0
|
| 7 |
+
scikit-learn>=1.3,<1.7
|