demo_project.py
1 import os 2 import sys 3 from typing import Optional 4 from typing import cast 5 6 from typer import Option 7 from typer import echo 8 9 from evidently.cli.main import app 10 from evidently.cli.ui import setup_deterministic_generation_uuid 11 from evidently.ui.service.demo_projects import DEMO_PROJECTS 12 from evidently.ui.service.demo_projects import DemoProjectsNames 13 from evidently.ui.workspace import RemoteWorkspace 14 from evidently.ui.workspace import WorkspaceBase 15 16 17 @app.command("demo_project") 18 def generate_demo_project( 19 project: str = Option("all", help="Project to generate"), 20 path: str = Option("workspace", help="Workspace path or URL (if starts with http)"), 21 secret: Optional[str] = Option(None, help="Secret for remote workspace authentication"), 22 ): 23 if os.environ.get("EXPERIMENTAL_DETERMINISTIC_UUID"): 24 setup_deterministic_generation_uuid() 25 # TODO: better type safety 26 _project = DEMO_PROJECTS.get(cast(DemoProjectsNames, project)) 27 if _project is None: 28 echo(f"Demo project {project} not found.") 29 sys.exit(1) 30 31 # If path starts with http, use RemoteWorkspace; otherwise use local Workspace 32 if path.startswith("http"): 33 secret = secret or os.environ.get("EVIDENTLY_SECRET") 34 ws: WorkspaceBase = RemoteWorkspace(path, secret=secret) 35 _project.create(ws) 36 else: 37 _project.create(path)