Skip to content

Commit

Permalink
move module constants to config; mark fields as private, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reyammer committed Feb 14, 2024
1 parent 39feee0 commit 4534f8e
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 115 deletions.
15 changes: 8 additions & 7 deletions python/magika/cli/magika.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

HELP_EPILOG = f"""
Magika version: "{VERSION}"\f
Model name: "{Magika.DEFAULT_MODEL_NAME}"
Default model: "{Magika.get_default_model_name()}"
Send any feedback to {CONTACT_EMAIL} or via GitHub issues.
"""
Expand Down Expand Up @@ -178,7 +178,7 @@ def main(

if output_version:
_l.raw_print_to_stdout(f"Magika version: {VERSION}")
_l.raw_print_to_stdout(f"Default model name: {Magika.DEFAULT_MODEL_NAME}")
_l.raw_print_to_stdout(f"Default model: {Magika.get_default_model_name()}")
sys.exit(0)

# check CLI arguments and options
Expand Down Expand Up @@ -219,8 +219,9 @@ def main(
_l.info(f"Considering {len(files_paths)} files")
_l.debug(f"Files: {files_paths}")

# Select the model using the following priority: CLI option, env variable,
# default.
# Select an alternative model checking: 1) CLI option, 2) env variable.
# If none of these is set, model_dir is left to None, and the Magika module
# will use the default model.
if model_dir is None:
model_dir_str = os.environ.get("MAGIKA_MODEL_DIR")
if model_dir_str is not None and model_dir_str.strip() != "":
Expand Down Expand Up @@ -314,7 +315,7 @@ def main(
_l.raw_print_to_stdout(json.dumps(all_predictions, indent=4))

if generate_report_flag:
print_feedback_report(model_name=model_dir.name, report_entries=report_entries)
print_feedback_report(magika=magika, report_entries=report_entries)


def should_read_from_stdin(files_paths: List[Path]) -> bool:
Expand Down Expand Up @@ -347,13 +348,13 @@ def generate_feedback_report_entry(


def print_feedback_report(
model_name: str, report_entries: List[FeedbackReportEntry]
magika: Magika, report_entries: List[FeedbackReportEntry]
) -> None:
_l = get_logger()

report = {
"version": VERSION,
"model_dir_name": model_name,
"model_dir_name": magika.get_model_name(),
"python_version": sys.version,
"entries": base64.b64encode(json.dumps(report_entries).encode("utf-8")).decode(
"utf-8"
Expand Down
6 changes: 6 additions & 0 deletions python/magika/config/magika_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"default_model_name": "standard_v1",
"medium_confidence_threshold": 0.5,
"min_file_size_for_dl": 16,
"padding_token": 256
}
Loading

0 comments on commit 4534f8e

Please sign in to comment.