sachinchandrankallar commited on
Commit
bb194c0
·
1 Parent(s): a138cba

summary markdown

Browse files
ai_med_extract/api/__pycache__/routes.cpython-311.pyc CHANGED
Binary files a/ai_med_extract/api/__pycache__/routes.cpython-311.pyc and b/ai_med_extract/api/__pycache__/routes.cpython-311.pyc differ
 
ai_med_extract/api/routes.py CHANGED
@@ -1202,7 +1202,8 @@ def register_routes(app, agents):
1202
  from ai_med_extract.utils.model_loader_gguf import create_fallback_pipeline
1203
  fallback_pipeline = create_fallback_pipeline()
1204
  fallback_summary = fallback_pipeline.generate_full_summary(prompt)
1205
- markdown_summary = summary_to_markdown(fallback_summary)
 
1206
  return jsonify({
1207
  "summary": markdown_summary,
1208
  "baseline": baseline,
@@ -1236,7 +1237,8 @@ def register_routes(app, agents):
1236
  text = pipeline.tokenizer.decode(outputs[0], skip_special_tokens=True)
1237
  new_summary = text.split("Now generate the complete, updated clinical summary with all four sections in a markdown format:")[-1].strip()
1238
  # For other models, after extracting new_summary:
1239
- markdown_summary = summary_to_markdown(new_summary)
 
1240
  # Remove undefined timing variables and only log steps that are actually measured
1241
  total_time = time.time() - start_total
1242
  print(f"[TIMING] API call: {t_api_end-t_api_start:.2f}s, TOTAL: {total_time:.2f}s")
 
1202
  from ai_med_extract.utils.model_loader_gguf import create_fallback_pipeline
1203
  fallback_pipeline = create_fallback_pipeline()
1204
  fallback_summary = fallback_pipeline.generate_full_summary(prompt)
1205
+ markdown_summary =fallback_summary
1206
+ # summary_to_markdown(fallback_summary)
1207
  return jsonify({
1208
  "summary": markdown_summary,
1209
  "baseline": baseline,
 
1237
  text = pipeline.tokenizer.decode(outputs[0], skip_special_tokens=True)
1238
  new_summary = text.split("Now generate the complete, updated clinical summary with all four sections in a markdown format:")[-1].strip()
1239
  # For other models, after extracting new_summary:
1240
+ markdown_summary = new_summary
1241
+ # summary_to_markdown(new_summary)
1242
  # Remove undefined timing variables and only log steps that are actually measured
1243
  total_time = time.time() - start_total
1244
  print(f"[TIMING] API call: {t_api_end-t_api_start:.2f}s, TOTAL: {total_time:.2f}s")
ai_med_extract/utils/openvino_summarizer_utils.py CHANGED
@@ -143,7 +143,7 @@ def build_main_prompt(baseline, delta_text):
143
  "4) Direct Guidance for Physician - Specific recommendations for the treating physician\n\n"
144
  f"STRUCTURED BASELINE (current status):\n{baseline}\n\n"
145
  f"STRUCTURED DELTAS (changes from previous visits):\n{delta_text}\n\n"
146
- "Now generate the complete clinical summary with all four sections in markdown format, paying special attention to detailed trend analysis in the Key Trends & Changes section:"
147
  )
148
  def validate_and_compare_summaries(old_summary, new_summary, update_name=""):
149
  report = f"### Validation Report for {update_name}\n"
 
143
  "4) Direct Guidance for Physician - Specific recommendations for the treating physician\n\n"
144
  f"STRUCTURED BASELINE (current status):\n{baseline}\n\n"
145
  f"STRUCTURED DELTAS (changes from previous visits):\n{delta_text}\n\n"
146
+ "Now generate the complete clinical summary with all four sections in markdown format:"
147
  )
148
  def validate_and_compare_summaries(old_summary, new_summary, update_name=""):
149
  report = f"### Validation Report for {update_name}\n"
test_summary_function.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to verify the summary_to_markdown function works correctly
4
+ with the 4-section structure validation.
5
+ """
6
+
7
+ import sys
8
+ import os
9
+
10
+ # Add the current directory to Python path
11
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
12
+
13
+ from ai_med_extract.api.routes import summary_to_markdown
14
+
15
+ def test_summary_to_markdown():
16
+ """Test the summary_to_markdown function with various inputs"""
17
+
18
+ # Test case 1: Summary with proper 4-section structure
19
+ test_summary_1 = """1. Clinical Assessment
20
+ Patient presents with hypertension and diabetes. Blood pressure is elevated at 150/95 mmHg.
21
+
22
+ 2. Key Trends and Changes
23
+ Blood pressure has increased from previous reading of 140/90 mmHg. Blood sugar levels remain stable.
24
+
25
+ 3. Plan and Suggested Actions
26
+ Increase dosage of antihypertensive medication. Monitor blood pressure daily.
27
+
28
+ 4. Direct Guidance for Physician
29
+ Consider adding ACE inhibitor if current regimen is insufficient."""
30
+
31
+ print("Test 1: Proper 4-section structure")
32
+ result_1 = summary_to_markdown(test_summary_1)
33
+ print("Input:")
34
+ print(test_summary_1)
35
+ print("\nOutput:")
36
+ print(result_1)
37
+ print("-" * 80)
38
+
39
+ # Test case 2: Summary with numbered sections but different content
40
+ test_summary_2 = """1. Patient Information
41
+ John Doe, 45 years old, male
42
+
43
+ 2. Vital Signs
44
+ BP: 150/95, HR: 78, Temp: 98.6°F
45
+
46
+ 3. Laboratory Results
47
+ HbA1c: 6.8%, Cholesterol: 210 mg/dL
48
+
49
+ 4. Medications
50
+ Lisinopril 10mg daily, Metformin 500mg twice daily"""
51
+
52
+ print("Test 2: Different section content")
53
+ result_2 = summary_to_markdown(test_summary_2)
54
+ print("Input:")
55
+ print(test_summary_2)
56
+ print("\nOutput:")
57
+ print(result_2)
58
+ print("-" * 80)
59
+
60
+ # Test case 3: Summary with markdown headers already
61
+ test_summary_3 = """# Clinical Assessment
62
+ Patient presents with hypertension
63
+
64
+ ## Key Trends and Changes
65
+ BP increased from previous visit
66
+
67
+ ## Plan and Suggested Actions
68
+ Adjust medication dosage
69
+
70
+ ## Direct Guidance for Physician
71
+ Monitor patient closely"""
72
+
73
+ print("Test 3: Already in markdown format")
74
+ result_3 = summary_to_markdown(test_summary_3)
75
+ print("Input:")
76
+ print(test_summary_3)
77
+ print("\nOutput:")
78
+ print(result_3)
79
+ print("-" * 80)
80
+
81
+ # Test case 4: Summary with answer artifacts
82
+ test_summary_4 = """1. Clinical Assessment
83
+ - answer: Patient presents with hypertension
84
+
85
+ 2. Key Trends and Changes
86
+ - answer: BP increased from previous visit
87
+
88
+ 3. Plan and Suggested Actions
89
+ - answer: Adjust medication dosage
90
+
91
+ 4. Direct Guidance for Physician
92
+ - answer: Monitor patient closely"""
93
+
94
+ print("Test 4: Summary with answer artifacts")
95
+ result_4 = summary_to_markdown(test_summary_4)
96
+ print("Input:")
97
+ print(test_summary_4)
98
+ print("\nOutput:")
99
+ print(result_4)
100
+ print("-" * 80)
101
+
102
+ # Test case 5: Incomplete summary (only 2 sections)
103
+ test_summary_5 = """1. Clinical Assessment
104
+ Patient presents with hypertension
105
+
106
+ 2. Key Trends and Changes
107
+ BP increased from previous visit"""
108
+
109
+ print("Test 5: Incomplete summary (2 sections)")
110
+ result_5 = summary_to_markdown(test_summary_5)
111
+ print("Input:")
112
+ print(test_summary_5)
113
+ print("\nOutput:")
114
+ print(result_5)
115
+ print("-" * 80)
116
+
117
+ if __name__ == "__main__":
118
+ test_summary_to_markdown()