Spaces:
Runtime error
Runtime error
Remove GitHub and HF links
Browse files- src/report_assistant.py +93 -94
src/report_assistant.py
CHANGED
|
@@ -1,94 +1,93 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Tri-Netra — Report Assistant
|
| 3 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
-
Generates a structured prompt template for a medical LLM to draft a brief,
|
| 5 |
-
3-sentence professional diagnostic note based on MRI analysis findings.
|
| 6 |
-
|
| 7 |
-
Author : Anannya Vyas
|
| 8 |
-
Email : vyasanannya@gmail.com
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
"
|
| 46 |
-
else "
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
f" -
|
| 52 |
-
f" -
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
"\n"
|
| 62 |
-
"
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"
|
| 68 |
-
"
|
| 69 |
-
"
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
-
"\n"
|
| 73 |
-
"
|
| 74 |
-
|
| 75 |
-
"
|
| 76 |
-
"
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
)
|
| 90 |
-
print("
|
| 91 |
-
print("
|
| 92 |
-
print(
|
| 93 |
-
print(
|
| 94 |
-
print("=" * 60)
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tri-Netra — Report Assistant
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
Generates a structured prompt template for a medical LLM to draft a brief,
|
| 5 |
+
3-sentence professional diagnostic note based on MRI analysis findings.
|
| 6 |
+
|
| 7 |
+
Author : Anannya Vyas
|
| 8 |
+
Email : vyasanannya@gmail.com
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def generate_diagnostic_prompt(
|
| 15 |
+
prediction_pct: float,
|
| 16 |
+
tumor_type: str | None = None,
|
| 17 |
+
timestamp: str | None = None,
|
| 18 |
+
) -> str:
|
| 19 |
+
"""Build an LLM prompt that requests a concise radiology-style diagnostic note.
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
----------
|
| 23 |
+
prediction_pct : float
|
| 24 |
+
Classification confidence as a percentage (0–100).
|
| 25 |
+
tumor_type : str or None
|
| 26 |
+
Tumor subtype identified by segmentation (e.g. "glioma",
|
| 27 |
+
"meningioma", "pituitary"). Pass ``None`` or an empty string
|
| 28 |
+
when segmentation was not performed or no tumor was detected.
|
| 29 |
+
tumor_type : str or None
|
| 30 |
+
Timestamp of the inference run (ISO-8601 or any human-readable
|
| 31 |
+
format). Included in the findings block so the note is traceable.
|
| 32 |
+
|
| 33 |
+
Returns
|
| 34 |
+
-------
|
| 35 |
+
str
|
| 36 |
+
A ready-to-send prompt string for any medical-capable LLM.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
# ── Build the structured findings block ──────────────────────────
|
| 40 |
+
tumor_label = tumor_type.strip() if tumor_type else "Not segmented / No tumor detected"
|
| 41 |
+
ts_label = timestamp.strip() if timestamp else "N/A"
|
| 42 |
+
|
| 43 |
+
confidence_descriptor = (
|
| 44 |
+
"high" if prediction_pct >= 85
|
| 45 |
+
else "moderate" if prediction_pct >= 50
|
| 46 |
+
else "low"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
findings_block = (
|
| 50 |
+
f" - Classification confidence : {prediction_pct:.1f}% ({confidence_descriptor})\n"
|
| 51 |
+
f" - Tumor type (segmentation) : {tumor_label}\n"
|
| 52 |
+
f" - Analysis timestamp : {ts_label}"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# -- Assemble the full prompt -------------------------------------
|
| 56 |
+
prompt = (
|
| 57 |
+
"You are a board-certified neuroradiologist assistant AI.\n"
|
| 58 |
+
"Based on the automated MRI analysis findings below, draft a\n"
|
| 59 |
+
"professional diagnostic note for a radiologist's review.\n"
|
| 60 |
+
"\n"
|
| 61 |
+
"RULES:\n"
|
| 62 |
+
" 1. Write exactly THREE concise sentences.\n"
|
| 63 |
+
" 2. Sentence 1: State the primary finding (tumor presence/absence\n"
|
| 64 |
+
" and type, if available).\n"
|
| 65 |
+
" 3. Sentence 2: Note the model's confidence level and any\n"
|
| 66 |
+
" clinical implication that warrants attention.\n"
|
| 67 |
+
" 4. Sentence 3: Recommend a follow-up action (e.g. biopsy,\n"
|
| 68 |
+
" additional imaging, clinical correlation).\n"
|
| 69 |
+
" 5. Use formal medical language appropriate for a radiology report.\n"
|
| 70 |
+
" 6. Do NOT fabricate patient demographics or history.\n"
|
| 71 |
+
"\n"
|
| 72 |
+
"--- AUTOMATED FINDINGS ---------------------------\n"
|
| 73 |
+
f"{findings_block}\n"
|
| 74 |
+
"--------------------------------------------------\n"
|
| 75 |
+
"\n"
|
| 76 |
+
"Diagnostic Note:"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
return prompt
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# ── CLI demo ─────────────────────────────────────────────────────────
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
sample_prompt = generate_diagnostic_prompt(
|
| 85 |
+
prediction_pct=92.4,
|
| 86 |
+
tumor_type="Glioma (High-Grade)",
|
| 87 |
+
timestamp="2026-06-26T23:30:00+05:30",
|
| 88 |
+
)
|
| 89 |
+
print("=" * 60)
|
| 90 |
+
print("SAMPLE LLM PROMPT")
|
| 91 |
+
print("=" * 60)
|
| 92 |
+
print(sample_prompt)
|
| 93 |
+
print("=" * 60)
|
|
|