anannyavyas1 commited on
Commit
faedc88
·
verified ·
1 Parent(s): 427e92d

Remove GitHub and HF links

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