Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def expand_abbreviations(medical_report: str) -> str:
|
|
| 28 |
# Based on the Hugging Face model card example:
|
| 29 |
# "Complication: NKDA \n\n Patient SOB & RNA." + " <|expand|>"
|
| 30 |
#prompt = "Medical Report: " + medical_report + "\n. <|expand|>"
|
| 31 |
-
prompt = "
|
| 32 |
|
| 33 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 34 |
|
|
@@ -63,7 +63,7 @@ def expand_abbreviations(medical_report: str) -> str:
|
|
| 63 |
#return prompt + "HHHH" + "Complication: " + repr(medical_report) + "\n. <|expand|>"
|
| 64 |
#return decoded_output
|
| 65 |
|
| 66 |
-
if decoded_output.startswith("
|
| 67 |
# If the output starts with the original report, try to find the expansion marker
|
| 68 |
# and return everything after it.
|
| 69 |
# The model card example shows the output starting with the original text
|
|
@@ -77,11 +77,11 @@ def expand_abbreviations(medical_report: str) -> str:
|
|
| 77 |
|
| 78 |
# Let's try to find the exact prompt with the expansion token in the output
|
| 79 |
# and then take everything after it.
|
| 80 |
-
full_prompt_in_output = "
|
| 81 |
#full_prompt_in_output = "Medical report: "+ medical_report + " <|expand|>"
|
| 82 |
if full_prompt_in_output in decoded_output:
|
| 83 |
#return decoded_output.replace(full_prompt_in_output, "", 1)
|
| 84 |
-
return "".join(decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("
|
| 85 |
#return "".join(decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("Medical report: ", "", 1))
|
| 86 |
#return decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("Complication: ", "", 1)
|
| 87 |
else:
|
|
|
|
| 28 |
# Based on the Hugging Face model card example:
|
| 29 |
# "Complication: NKDA \n\n Patient SOB & RNA." + " <|expand|>"
|
| 30 |
#prompt = "Medical Report: " + medical_report + "\n. <|expand|>"
|
| 31 |
+
prompt = "Medical note: \n" + medical_report + "\n. <|expand|>"
|
| 32 |
|
| 33 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 34 |
|
|
|
|
| 63 |
#return prompt + "HHHH" + "Complication: " + repr(medical_report) + "\n. <|expand|>"
|
| 64 |
#return decoded_output
|
| 65 |
|
| 66 |
+
if decoded_output.startswith("Medical note: \n" + medical_report):
|
| 67 |
# If the output starts with the original report, try to find the expansion marker
|
| 68 |
# and return everything after it.
|
| 69 |
# The model card example shows the output starting with the original text
|
|
|
|
| 77 |
|
| 78 |
# Let's try to find the exact prompt with the expansion token in the output
|
| 79 |
# and then take everything after it.
|
| 80 |
+
full_prompt_in_output = "Medical note: \n"+ medical_report + "\n. <|expand|>"
|
| 81 |
#full_prompt_in_output = "Medical report: "+ medical_report + " <|expand|>"
|
| 82 |
if full_prompt_in_output in decoded_output:
|
| 83 |
#return decoded_output.replace(full_prompt_in_output, "", 1)
|
| 84 |
+
return "".join(decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("Medical note: \n", "", 1).rsplit("\n.", 1))
|
| 85 |
#return "".join(decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("Medical report: ", "", 1))
|
| 86 |
#return decoded_output.split(full_prompt_in_output, 1)[1].strip().replace("Complication: ", "", 1)
|
| 87 |
else:
|