1 from typing
import Optional
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
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()
24 ctxProject = getProject(project, userConfig)
25 if ctxProject
is None:
28 ui.progressEcho(
"Creating the model...")
30 model = Model.createModel(name, ctxProject.id, accuracy)
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())}.")
38 @onBeforeCommandExecute(initializeUserSession)
43 model.add_command(create)