praevius 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- praevius/__init__.py +56 -0
- praevius/_launch.py +90 -0
- praevius/app.py +776 -0
- praevius/assets/__init__.py +12 -0
- praevius/assets/favicon.png +0 -0
- praevius/assets/make_favicon.py +85 -0
- praevius/models/model_card.json +117 -0
- praevius/models/pipeline_gradient_boosting_1year.pkl +0 -0
- praevius/models/pipeline_gradient_boosting_3years.pkl +0 -0
- praevius/models/pipeline_gradient_boosting_tuned_1year.pkl +0 -0
- praevius/models/pipeline_gradient_boosting_tuned_3years.pkl +0 -0
- praevius/models/pipeline_logistic_regression_1year.pkl +0 -0
- praevius/models/pipeline_logistic_regression_3years.pkl +0 -0
- praevius/models/pipeline_random_forest_1year.pkl +0 -0
- praevius/models/pipeline_random_forest_3years.pkl +0 -0
- praevius/predict.py +603 -0
- praevius/predictive_model.py +1922 -0
- praevius/preprocessing.py +378 -0
- praevius/report.py +337 -0
- praevius/scoring.py +410 -0
- praevius-0.1.0.dist-info/METADATA +479 -0
- praevius-0.1.0.dist-info/RECORD +26 -0
- praevius-0.1.0.dist-info/WHEEL +5 -0
- praevius-0.1.0.dist-info/entry_points.txt +3 -0
- praevius-0.1.0.dist-info/licenses/LICENSE +674 -0
- praevius-0.1.0.dist-info/top_level.txt +1 -0
praevius/__init__.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
praevius — Hospitalisation-risk predictor for elderly patients
|
|
3
|
+
==============================================================
|
|
4
|
+
|
|
5
|
+
Installable Python package for the Praevius project. It exposes, at the
|
|
6
|
+
package level, the scoring engine's core functions so programmatic use is
|
|
7
|
+
simple:
|
|
8
|
+
|
|
9
|
+
import praevius
|
|
10
|
+
models = praevius.load_pipelines() # load the bundled pipelines
|
|
11
|
+
df = praevius.patient_to_dataframe({...}) # one patient's raw data
|
|
12
|
+
scores = praevius.score_patient(models, df) # scores per horizon/model
|
|
13
|
+
|
|
14
|
+
Submodules:
|
|
15
|
+
- praevius.preprocessing ClinicalPreprocessor (preprocessing)
|
|
16
|
+
- praevius.scoring scoring engine (single source)
|
|
17
|
+
- praevius.predict single-patient prediction CLI
|
|
18
|
+
- praevius.report PDF report (in memory)
|
|
19
|
+
- praevius.app Streamlit clinical interface
|
|
20
|
+
- praevius.predictive_model training pipeline
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# Package version — first installable distribution (Phase 4). Semantic
|
|
24
|
+
# versioning; pre-1.0 because it's a research prototype.
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
|
|
27
|
+
# Re-export the scoring engine's public API at the package level. Importing
|
|
28
|
+
# scoring pulls numpy/pandas/sklearn; that is the project's core, so the cost
|
|
29
|
+
# is acceptable and the ergonomics pay off.
|
|
30
|
+
from praevius.scoring import ( # noqa: E402
|
|
31
|
+
SHAP_AVAILABLE,
|
|
32
|
+
build_example_patient,
|
|
33
|
+
load_model_card,
|
|
34
|
+
load_pipelines,
|
|
35
|
+
model_agreement,
|
|
36
|
+
patient_to_dataframe,
|
|
37
|
+
probability_display,
|
|
38
|
+
risk_band,
|
|
39
|
+
score_patient,
|
|
40
|
+
shap_explanation,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Explicit list of what `from praevius import *` exports.
|
|
44
|
+
__all__ = [
|
|
45
|
+
"__version__",
|
|
46
|
+
"SHAP_AVAILABLE",
|
|
47
|
+
"build_example_patient",
|
|
48
|
+
"load_model_card",
|
|
49
|
+
"load_pipelines",
|
|
50
|
+
"model_agreement",
|
|
51
|
+
"patient_to_dataframe",
|
|
52
|
+
"probability_display",
|
|
53
|
+
"risk_band",
|
|
54
|
+
"score_patient",
|
|
55
|
+
"shap_explanation",
|
|
56
|
+
]
|
praevius/_launch.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
praevius._launch — Clinical-interface launcher (the `praevius-app` command)
|
|
3
|
+
===========================================================================
|
|
4
|
+
|
|
5
|
+
A Streamlit app runs via `streamlit run app.py`, but an installed command
|
|
6
|
+
(console script) is just a Python function — not a `streamlit run`. This
|
|
7
|
+
module bridges that: it locates the app.py BUNDLED in the package and invokes
|
|
8
|
+
`streamlit run` programmatically.
|
|
9
|
+
|
|
10
|
+
Two details it handles:
|
|
11
|
+
1. PATH — app.py is found via importlib.resources, so the command works
|
|
12
|
+
from ANY directory.
|
|
13
|
+
2. THEME — the NodNex visual theme lives in `.streamlit/config.toml`, which
|
|
14
|
+
Streamlit only reads from the working directory. Since the command runs
|
|
15
|
+
from anywhere, we apply the theme via ENVIRONMENT VARIABLES
|
|
16
|
+
(STREAMLIT_THEME_*), mirroring config.toml.
|
|
17
|
+
|
|
18
|
+
Streamlit is an OPTIONAL dependency (the [app] extra); hence it is imported
|
|
19
|
+
lazily, with a clear message if missing.
|
|
20
|
+
|
|
21
|
+
Author: Rafael Zanarino
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
import sys
|
|
26
|
+
from importlib import resources
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# NodNex theme as Streamlit environment variables. The keys mirror `[theme]`
|
|
30
|
+
# in .streamlit/config.toml (primaryColor → STREAMLIT_THEME_PRIMARY_COLOR,
|
|
31
|
+
# etc.). It is the ONLY way to load the theme when the app runs outside the
|
|
32
|
+
# project directory.
|
|
33
|
+
_THEME_ENV = {
|
|
34
|
+
"STREAMLIT_THEME_PRIMARY_COLOR": "#7C3AED", # brand violet
|
|
35
|
+
"STREAMLIT_THEME_BACKGROUND_COLOR": "#F5F5F4", # stone-100
|
|
36
|
+
"STREAMLIT_THEME_SECONDARY_BACKGROUND_COLOR": "#FFFFFF",
|
|
37
|
+
"STREAMLIT_THEME_TEXT_COLOR": "#1C1917", # stone-900
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _app_path():
|
|
42
|
+
"""
|
|
43
|
+
Absolute path to the app.py bundled in the package.
|
|
44
|
+
|
|
45
|
+
Resolved via importlib.resources — works in editable installs and from
|
|
46
|
+
the wheel.
|
|
47
|
+
"""
|
|
48
|
+
return str(resources.files("praevius") / "app.py")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _theme_env():
|
|
52
|
+
"""
|
|
53
|
+
Returns the NodNex theme dict (Streamlit environment variables).
|
|
54
|
+
|
|
55
|
+
Separate function so it is testable without booting the server.
|
|
56
|
+
"""
|
|
57
|
+
return dict(_THEME_ENV)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def run(argv=None):
|
|
61
|
+
"""
|
|
62
|
+
Starts the clinical interface: `streamlit run <bundled app.py>`.
|
|
63
|
+
|
|
64
|
+
Extra command-line arguments are forwarded to Streamlit, so
|
|
65
|
+
`praevius-app --server.port 8600` works.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
argv (list[str] | None): Arguments to forward to Streamlit. None =
|
|
69
|
+
use the command-line arguments.
|
|
70
|
+
"""
|
|
71
|
+
# User arguments (e.g. --server.port) forwarded to Streamlit.
|
|
72
|
+
extra = list(sys.argv[1:] if argv is None else argv)
|
|
73
|
+
|
|
74
|
+
# Apply the brand theme WITHOUT overriding what the user may have already
|
|
75
|
+
# set in the environment (setdefault).
|
|
76
|
+
for key, value in _THEME_ENV.items():
|
|
77
|
+
os.environ.setdefault(key, value)
|
|
78
|
+
|
|
79
|
+
# Lazy import of Streamlit (optional dependency).
|
|
80
|
+
try:
|
|
81
|
+
from streamlit.web import cli as stcli
|
|
82
|
+
except ModuleNotFoundError:
|
|
83
|
+
sys.exit(
|
|
84
|
+
"Streamlit não está instalado. Instale com: pip install 'praevius[app]'\n"
|
|
85
|
+
"Streamlit is not installed. Install with: pip install 'praevius[app]'"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Build the `streamlit run <app.py> [args...]` command and run it.
|
|
89
|
+
sys.argv = ["streamlit", "run", _app_path(), *extra]
|
|
90
|
+
sys.exit(stcli.main())
|