Update app.py
Browse files
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 |
-
|
62 |
-
|
63 |
-
|
|
|
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"),
|