forked from crim-ca/dlm-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
45 lines (36 loc) · 1.19 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import typer
from rich.console import Console
from stac_model import __version__
from stac_model.examples import eurosat_resnet
from stac_model.schema import ItemMLModelExtension
app = typer.Typer(
name="stac-model",
help="A PydanticV2 validation and serialization library for the STAC Machine Learning Model Extension",
add_completion=False,
)
console = Console()
def version_callback(print_version: bool) -> None:
"""Print the version of the package."""
if print_version:
console.print(f"[yellow]stac-model[/] version: [bold blue]{__version__}[/]")
raise typer.Exit()
@app.command(name="")
def main(
print_version: bool = typer.Option(
None,
"-v",
"--version",
callback=version_callback,
is_eager=True,
help="Prints the version of the stac-model package.",
),
) -> ItemMLModelExtension:
"""Generate example spec."""
ml_model_meta = eurosat_resnet()
with open("example.json", "w") as json_file:
json.dump(ml_model_meta.item.to_dict(), json_file, indent=4)
print("Example model metadata written to ./example.json.")
return ml_model_meta
if __name__ == "__main__":
app()