Coretex
model.py
1 from typing import Optional
2 
3 import click
4 
5 from ..modules import ui
6 from ..modules.project_utils import getProject
7 from ..modules.user import initializeUserSession
8 from ..modules.utils import onBeforeCommandExecute
9 from ...entities import Model
10 from ...configuration import UserConfiguration
11 
12 
13 @click.command()
14 @click.argument("path", type = click.Path(exists = True, file_okay = False, dir_okay = True))
15 @click.option("-n", "--name", type = str, required = True)
16 @click.option("-p", "--project", type = str, required = False, default = None)
17 @click.option("-a", "--accuracy", type = click.FloatRange(0, 1), required = False, default = 1)
18 def create(name: str, path: str, project: Optional[str], accuracy: float) -> None:
19  userConfig = UserConfiguration.load()
20 
21  # If project was provided used that, otherwise get the one from config
22  # If project that was provided does not exist prompt user to create a new
23  # one with that name
24  ctxProject = getProject(project, userConfig)
25  if ctxProject is None:
26  return
27 
28  ui.progressEcho("Creating the model...")
29 
30  model = Model.createModel(name, ctxProject.id, accuracy)
31  model.upload(path)
32 
33  ui.successEcho(f"Model \"{model.name}\" created successfully")
34  ui.stdEcho(f"A new model has been created. You can open it by clicking on this URL {ui.outputUrl(userConfig.frontendUrl, model.entityUrl())}.")
35 
36 
37 @click.group()
38 @onBeforeCommandExecute(initializeUserSession)
39 def model() -> None:
40  pass
41 
42 
43 model.add_command(create)