Skip to content

Commit

Permalink
⚡ changing output CSV to hespi-results.csv and appending subsequent r…
Browse files Browse the repository at this point in the history
…esults to this file
  • Loading branch information
rbturnbull committed Feb 28, 2024
1 parent 6d3e570 commit be92264
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion hespi/hespi.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def detect(
output_dir=output_dir / stub,
)

df = ocr_data_df(ocr_data, output_path=output_dir/"ocr_results.csv")
df = ocr_data_df(ocr_data, output_path=output_dir/"hespi-results.csv")

# Write report
if report:
Expand Down
1 change: 1 addition & 0 deletions hespi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def detect(
),
institutional_label_classifier_weights: str = typer.Option(
DEFAULT_INSTITUTIONAL_LABEL_CLASSIFIER_WEIGHTS,
envvar="HESPI_INSTITUTIONAL_LABEL_CLASSIFIER_WEIGHTS",
help="The path to the institutional label classifier weights.",
),
force_download:bool = typer.Option(False, help="Whether or not to force download model weights even if a weights file is present."),
Expand Down
9 changes: 9 additions & 0 deletions hespi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def ocr_data_df(data: dict, output_path: Path=None) -> pd.DataFrame:
if output_path:
output_path = Path(output_path)
output_path.parent.mkdir(exist_ok=True, parents=True)

# If the file already exists, then concatenate it
if output_path.exists():
old_df = pd.read_csv(output_path)
df = pd.concat([old_df, df])
console.print(f"Appending Hespi results to: '{output_path}'")
else:
console.print(f"Writing Hespi results to: '{output_path}'")

df.to_csv(output_path, index=False)

return df
Expand Down
23 changes: 12 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be92264

Please sign in to comment.