Update handler.py
Browse files- handler.py +8 -26
handler.py
CHANGED
|
@@ -484,41 +484,23 @@ class EndpointHandler:
|
|
| 484 |
# Aggressive cleanup of artifacts
|
| 485 |
generated_text = generated_text.replace("</s>", "").strip()
|
| 486 |
|
| 487 |
-
#
|
| 488 |
if generated_text.startswith("(Answer:") and ")" in generated_text:
|
| 489 |
-
#
|
| 490 |
end_paren = generated_text.find(")")
|
| 491 |
answer_content = generated_text[8:end_paren].strip() # Remove "(Answer:"
|
|
|
|
|
|
|
| 492 |
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
parts = [part.strip() for part in answer_content.split(",")]
|
| 496 |
-
expanded_parts = []
|
| 497 |
-
|
| 498 |
-
for part in parts:
|
| 499 |
-
if "sinus rhythm" in part.lower():
|
| 500 |
-
expanded_parts.append("The electrocardiogram (ECG) reveals a sinus rhythm, indicating a normal heart rate and rhythm.")
|
| 501 |
-
elif "inferior infarct" in part.lower():
|
| 502 |
-
expanded_parts.append("The ECG shows signs of an inferior infarct, indicating myocardial damage in the inferior region.")
|
| 503 |
-
elif "anterior" in part.lower() and "infarct" in part.lower():
|
| 504 |
-
expanded_parts.append("There are signs of a possible acute anterior infarct.")
|
| 505 |
-
elif "fascicular block" in part.lower() or "block" in part.lower():
|
| 506 |
-
expanded_parts.append("The ECG suggests possible left anterior fascicular block, which may indicate a conduction abnormality in the heart's electrical system.")
|
| 507 |
-
elif "hypertrophy" in part.lower():
|
| 508 |
-
expanded_parts.append(f"There are signs of possible {part.lower()}.")
|
| 509 |
-
|
| 510 |
-
if expanded_parts:
|
| 511 |
-
generated_text = " ".join(expanded_parts)
|
| 512 |
-
else:
|
| 513 |
-
generated_text = f"The ECG shows {answer_content.lower()}."
|
| 514 |
else:
|
| 515 |
-
generated_text =
|
| 516 |
|
| 517 |
-
# Clean up other artifacts
|
| 518 |
elif generated_text.startswith("Answer:"):
|
| 519 |
generated_text = generated_text[7:].strip()
|
| 520 |
|
| 521 |
-
# Remove training artifacts
|
| 522 |
cleanup_patterns = [
|
| 523 |
"In this task",
|
| 524 |
"I'm asking the respondent",
|
|
|
|
| 484 |
# Aggressive cleanup of artifacts
|
| 485 |
generated_text = generated_text.replace("</s>", "").strip()
|
| 486 |
|
| 487 |
+
# Simple cleanup - just remove Answer prefix and parentheses
|
| 488 |
if generated_text.startswith("(Answer:") and ")" in generated_text:
|
| 489 |
+
# Just remove the parentheses and Answer: prefix
|
| 490 |
end_paren = generated_text.find(")")
|
| 491 |
answer_content = generated_text[8:end_paren].strip() # Remove "(Answer:"
|
| 492 |
+
# Keep the rest of the response if there is any
|
| 493 |
+
rest_of_response = generated_text[end_paren+1:].strip()
|
| 494 |
|
| 495 |
+
if rest_of_response:
|
| 496 |
+
generated_text = f"{answer_content}. {rest_of_response}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
else:
|
| 498 |
+
generated_text = answer_content
|
| 499 |
|
|
|
|
| 500 |
elif generated_text.startswith("Answer:"):
|
| 501 |
generated_text = generated_text[7:].strip()
|
| 502 |
|
| 503 |
+
# Remove only clear training artifacts
|
| 504 |
cleanup_patterns = [
|
| 505 |
"In this task",
|
| 506 |
"I'm asking the respondent",
|