Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -253,6 +253,61 @@ def post_process_medical_summary(summary):
|
|
| 253 |
|
| 254 |
return summary
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
def post_process_medical_summary(summary):
|
| 258 |
"""Special post-processing for medical/scientific summaries"""
|
|
|
|
| 253 |
|
| 254 |
return summary
|
| 255 |
|
| 256 |
+
def post_process_medical_summary(summary):
|
| 257 |
+
"""Special post-processing for medical/scientific summaries"""
|
| 258 |
+
if not summary:
|
| 259 |
+
return summary
|
| 260 |
+
|
| 261 |
+
# Fix common medical text issues
|
| 262 |
+
summary = (summary
|
| 263 |
+
.replace(" p =", " p=") # Fix p-value spacing
|
| 264 |
+
.replace(" n =", " n=") # Fix sample size spacing
|
| 265 |
+
.replace("( ", "(") # Fix parentheses spacing
|
| 266 |
+
.replace(" )", ")")
|
| 267 |
+
.replace("vs.", "versus") # Expand abbreviations
|
| 268 |
+
.replace("..", ".") # Fix double periods
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
# Ensure statistical significance symbols are correct
|
| 272 |
+
summary = (summary
|
| 273 |
+
.replace("p < ", "p<")
|
| 274 |
+
.replace("p > ", "p>")
|
| 275 |
+
.replace("P < ", "p<")
|
| 276 |
+
.replace("P > ", "p>")
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
# Fix number formatting
|
| 280 |
+
summary = (summary
|
| 281 |
+
.replace(" +/- ", "±")
|
| 282 |
+
.replace(" ± ", "±")
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
# Split into sentences and process each
|
| 286 |
+
sentences = [s.strip() for s in summary.split('.')]
|
| 287 |
+
processed_sentences = []
|
| 288 |
+
|
| 289 |
+
for sentence in sentences:
|
| 290 |
+
if sentence:
|
| 291 |
+
# Capitalize first letter
|
| 292 |
+
sentence = sentence[0].upper() + sentence[1:] if sentence else sentence
|
| 293 |
+
|
| 294 |
+
# Fix common medical abbreviations spacing
|
| 295 |
+
sentence = (sentence
|
| 296 |
+
.replace(" et al ", " et al. ")
|
| 297 |
+
.replace("et al.", "et al.") # Fix double period
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
processed_sentences.append(sentence)
|
| 301 |
+
|
| 302 |
+
# Join sentences
|
| 303 |
+
summary = '. '.join(processed_sentences)
|
| 304 |
+
|
| 305 |
+
# Ensure proper ending
|
| 306 |
+
if summary and not summary.endswith('.'):
|
| 307 |
+
summary += '.'
|
| 308 |
+
|
| 309 |
+
return summary
|
| 310 |
+
|
| 311 |
|
| 312 |
def post_process_medical_summary(summary):
|
| 313 |
"""Special post-processing for medical/scientific summaries"""
|