Ali2206 commited on
Commit
6c1d81c
·
verified ·
1 Parent(s): 8de21c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -58,13 +58,15 @@ def clean_text_response(text: str) -> str:
58
 
59
  def extract_section(text: str, heading: str) -> str:
60
  try:
61
- pattern = rf"{heading}:\n(.*?)(?=\n\w|\Z)"
62
- match = re.search(pattern, text, re.DOTALL)
63
- return clean_text_response(match.group(1)) if match else ""
 
64
  except Exception as e:
65
- logger.error(f"Section extraction failed: {e}")
66
  return ""
67
 
 
68
  def structure_medical_response(text: str) -> Dict:
69
  return {
70
  "summary": extract_section(text, "Summary"),
 
58
 
59
  def extract_section(text: str, heading: str) -> str:
60
  try:
61
+ # Accept formats like "Heading:" or "**Heading:**"
62
+ pattern = rf"(\*\*)?{re.escape(heading)}(\*\*)?:\s*\n(.*?)(?=\n\s*\*?\*?\w|$)"
63
+ match = re.search(pattern, text, re.DOTALL | re.IGNORECASE)
64
+ return clean_text_response(match.group(3)) if match else ""
65
  except Exception as e:
66
+ logger.error(f"Section extraction failed for heading '{heading}': {e}")
67
  return ""
68
 
69
+
70
  def structure_medical_response(text: str) -> Dict:
71
  return {
72
  "summary": extract_section(text, "Summary"),