Ali2206 commited on
Commit
96347cc
·
verified ·
1 Parent(s): ffd15e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -47,7 +47,7 @@ def file_hash(path: str) -> str:
47
  with open(path, "rb") as f:
48
  return hashlib.md5(f.read()).hexdigest()
49
 
50
- def extract_priority_pages(file_path: str, max_pages: int = 20) -> str:
51
  try:
52
  text_chunks = []
53
  with pdfplumber.open(file_path) as pdf:
@@ -128,7 +128,7 @@ def init_agent():
128
  tool_files_dict={"new_tool": target_tool_path},
129
  force_finish=True,
130
  enable_checker=True,
131
- step_rag_num=8,
132
  seed=100,
133
  additional_default_tools=[],
134
  )
@@ -154,44 +154,36 @@ def create_ui(agent):
154
  extracted = ""
155
  file_hash_value = ""
156
  if files:
157
- with ThreadPoolExecutor(max_workers=4) as executor:
158
  futures = [executor.submit(convert_file_to_json, f.name, f.name.split(".")[-1].lower()) for f in files]
159
  results = [sanitize_utf8(f.result()) for f in as_completed(futures)]
160
  extracted = "\n".join(results)
161
  file_hash_value = file_hash(files[0].name) if files else ""
162
 
163
  prompt = f"""
164
- You are a clinical reasoning assistant. Analyze the following medical records with a focus on identifying potential clinical oversights. Your task is to provide a comprehensive and structured summary addressing the following:
165
 
166
- 1. **Potential Missed Diagnoses**:
167
- - Consider any contradictory or missing evidence regarding the patient’s history, symptoms, or test results.
168
- - Take into account psychiatric, neurological, infectious, autoimmune, and genetic conditions.
169
- - Consider family history, trauma history, and childhood developmental information.
170
 
171
- 2. **Flagged Medication Conflicts**:
172
- - Cross-check all prescribed medications for contraindications, interactions, or off-label use without justification.
173
- - Verify if any medications may worsen known diagnoses or contribute to adverse effects.
174
 
175
- 3. **Incomplete or Missing Assessments**:
176
- - Identify any domains of assessment that are completely missing or only superficially addressed (e.g., cognitive, psychiatric, social, family).
177
- - Point out gaps in documentation of prior medical history, substance use, or lab/imaging results.
178
 
179
- 4. **Abnormal Results Needing Urgent Follow-up**:
180
- - Extract and highlight lab results, imaging, behavioral observations, or legal history that warrant immediate reassessment or specialist referral.
181
 
182
- Make the answer precise, evidence-based, and structured clearly under each heading. Avoid repeating input and remove tool-call formatting.
 
183
 
184
- ---
185
-
186
- Medical Records Input (Truncated to 12k chars):
187
-
188
- {extracted[:12000]}
189
-
190
- ---
191
- Begin your analysis below:
192
  """
193
 
194
-
195
  try:
196
  if history and history[-1]["content"].startswith("⏳"):
197
  history.pop()
@@ -200,7 +192,7 @@ Begin your analysis below:
200
  message=prompt,
201
  history=[],
202
  temperature=0.2,
203
- max_new_tokens=2048,
204
  max_token=4096,
205
  call_agent=False,
206
  conversation=[],
@@ -246,4 +238,4 @@ if __name__ == "__main__":
246
  show_error=True,
247
  allowed_paths=[report_dir],
248
  share=False
249
- )
 
47
  with open(path, "rb") as f:
48
  return hashlib.md5(f.read()).hexdigest()
49
 
50
+ def extract_priority_pages(file_path: str, max_pages: int = 10) -> str:
51
  try:
52
  text_chunks = []
53
  with pdfplumber.open(file_path) as pdf:
 
128
  tool_files_dict={"new_tool": target_tool_path},
129
  force_finish=True,
130
  enable_checker=True,
131
+ step_rag_num=4,
132
  seed=100,
133
  additional_default_tools=[],
134
  )
 
154
  extracted = ""
155
  file_hash_value = ""
156
  if files:
157
+ with ThreadPoolExecutor(max_workers=6) as executor:
158
  futures = [executor.submit(convert_file_to_json, f.name, f.name.split(".")[-1].lower()) for f in files]
159
  results = [sanitize_utf8(f.result()) for f in as_completed(futures)]
160
  extracted = "\n".join(results)
161
  file_hash_value = file_hash(files[0].name) if files else ""
162
 
163
  prompt = f"""
164
+ Analyze the medical records for clinical oversights. Provide a concise, evidence-based summary under these headings:
165
 
166
+ 1. **Missed Diagnoses**:
167
+ - Identify inconsistencies in history, symptoms, or tests.
168
+ - Consider psychiatric, neurological, infectious, autoimmune, genetic conditions, family history, trauma, and developmental factors.
 
169
 
170
+ 2. **Medication Conflicts**:
171
+ - Check for contraindications, interactions, or unjustified off-label use.
172
+ - Assess if medications worsen diagnoses or cause adverse effects.
173
 
174
+ 3. **Incomplete Assessments**:
175
+ - Note missing or superficial cognitive, psychiatric, social, or family assessments.
176
+ - Highlight gaps in medical history, substance use, or lab/imaging documentation.
177
 
178
+ 4. **Urgent Follow-up**:
179
+ - Flag abnormal lab results, imaging, behaviors, or legal history needing immediate reassessment or referral.
180
 
181
+ Medical Records (Truncated to 8k chars):
182
+ {extracted[:8000]}
183
 
184
+ Begin analysis:
 
 
 
 
 
 
 
185
  """
186
 
 
187
  try:
188
  if history and history[-1]["content"].startswith("⏳"):
189
  history.pop()
 
192
  message=prompt,
193
  history=[],
194
  temperature=0.2,
195
+ max_new_tokens=1024,
196
  max_token=4096,
197
  call_agent=False,
198
  conversation=[],
 
238
  show_error=True,
239
  allowed_paths=[report_dir],
240
  share=False
241
+ )