Update app.py
Browse files
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 =
|
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=
|
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=
|
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 |
-
|
165 |
|
166 |
-
1. **
|
167 |
-
-
|
168 |
-
-
|
169 |
-
- Consider family history, trauma history, and childhood developmental information.
|
170 |
|
171 |
-
2. **
|
172 |
-
-
|
173 |
-
-
|
174 |
|
175 |
-
3. **Incomplete
|
176 |
-
-
|
177 |
-
-
|
178 |
|
179 |
-
4. **
|
180 |
-
-
|
181 |
|
182 |
-
|
|
|
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=
|
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 |
+
)
|