Ali2206 commited on
Commit
dc00a02
·
verified ·
1 Parent(s): f000d8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -16
app.py CHANGED
@@ -60,7 +60,7 @@ def extract_priority_pages(file_path: str, max_pages: int = 20) -> str:
60
  text_chunks.append(f"=== Page {i+1} ===\n{(page.extract_text() or '').strip()}")
61
  for i, page in enumerate(pdf.pages[3:max_pages], start=4):
62
  page_text = page.extract_text() or ""
63
- if any(re.search(rf'\\b{kw}\\b', page_text.lower()) for kw in MEDICAL_KEYWORDS):
64
  text_chunks.append(f"=== Page {i} ===\n{page_text.strip()}")
65
  return "\n\n".join(text_chunks)
66
  except Exception as e:
@@ -155,7 +155,6 @@ def create_ui(agent: TxAgent):
155
  start_time = time.time()
156
  try:
157
  history.append({"role": "user", "content": message})
158
- history.append({"role": "assistant", "content": "Analyzing records for potential oversights..."})
159
  yield history, None
160
 
161
  extracted_data = ""
@@ -177,7 +176,7 @@ Medical Records:\n{extracted_data[:15000]}
177
 
178
  ### Potential Oversights:\n"""
179
 
180
- response = []
181
  for chunk in agent.run_gradio_chat(
182
  message=analysis_prompt,
183
  history=[],
@@ -187,21 +186,14 @@ Medical Records:\n{extracted_data[:15000]}
187
  call_agent=False,
188
  conversation=conversation
189
  ):
 
190
  if isinstance(chunk, str):
191
- response.append(chunk)
192
  elif isinstance(chunk, list):
193
- response.extend([c.content for c in chunk if hasattr(c, 'content')])
194
-
195
- if len(response) % 3 == 0:
196
- history[-1] = {"role": "assistant", "content": "".join(response).strip()}
197
- yield history, None
198
-
199
- final_output = "".join(response).strip()
200
- if not final_output:
201
- final_output = "No clear oversights identified. Recommend comprehensive review."
202
- if not final_output.startswith(("1.", "-", "*", "#")):
203
- final_output = "• " + final_output.replace("\n", "\n• ")
204
- history[-1] = {"role": "assistant", "content": final_output}
205
 
206
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt")
207
  return history, report_path if os.path.exists(report_path) else None
 
60
  text_chunks.append(f"=== Page {i+1} ===\n{(page.extract_text() or '').strip()}")
61
  for i, page in enumerate(pdf.pages[3:max_pages], start=4):
62
  page_text = page.extract_text() or ""
63
+ if any(re.search(rf'\b{kw}\b', page_text.lower()) for kw in MEDICAL_KEYWORDS):
64
  text_chunks.append(f"=== Page {i} ===\n{page_text.strip()}")
65
  return "\n\n".join(text_chunks)
66
  except Exception as e:
 
155
  start_time = time.time()
156
  try:
157
  history.append({"role": "user", "content": message})
 
158
  yield history, None
159
 
160
  extracted_data = ""
 
176
 
177
  ### Potential Oversights:\n"""
178
 
179
+ response = ""
180
  for chunk in agent.run_gradio_chat(
181
  message=analysis_prompt,
182
  history=[],
 
186
  call_agent=False,
187
  conversation=conversation
188
  ):
189
+ partial = ""
190
  if isinstance(chunk, str):
191
+ partial = chunk
192
  elif isinstance(chunk, list):
193
+ partial = "".join([c.content for c in chunk if hasattr(c, 'content')])
194
+ response += partial
195
+ history[-1] = {"role": "assistant", "content": response.strip()}
196
+ yield history, None
 
 
 
 
 
 
 
 
197
 
198
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt")
199
  return history, report_path if os.path.exists(report_path) else None