-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse model output using pre-determined keys.
- Loading branch information
1 parent
cf9508e
commit b68912c
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
venv/ | ||
venv* | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"keys": [ | ||
"Case No.", | ||
"Patient ID", | ||
"Type", | ||
"Surgeon", | ||
"OR Date", | ||
"Age", | ||
"M/F", | ||
"Indication for Surgery/Reason for Referral", | ||
"HPI", | ||
"Meds", | ||
"Allergies", | ||
"ID", | ||
"PMHx", | ||
"Social" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
import re | ||
|
||
|
||
def load_keys(filePath): | ||
with open(filePath, 'r') as file: | ||
data = json.load(file) | ||
return data['keys'] | ||
|
||
def parse_florence_output(output, keys): | ||
if isinstance(output, dict): | ||
output = json.dumps(output) # convert to JSON-formatted string | ||
|
||
parsed_data = {} | ||
|
||
for key in keys: | ||
# Use regex to find the value for the key | ||
pattern = re.compile(f"{re.escape(key)}:(.*?)(?=(?:{'|'.join(map(re.escape, keys))}|$))", re.DOTALL) | ||
match = pattern.search(output) | ||
|
||
if match: | ||
value = match.group(1).strip() | ||
parsed_data[key] = value | ||
|
||
# Convert the parsed data to JSON format | ||
json_data = json.dumps(parsed_data, indent=4) | ||
return json_data |