/ src / evidently / cli / legacy_ui.py
legacy_ui.py
 1  import os
 2  from typing import Optional
 3  
 4  import uuid6
 5  from typer import BadParameter
 6  from typer import Option
 7  from typer import echo
 8  
 9  from evidently.cli.main import app
10  from evidently.legacy.ui.demo_projects import DEMO_PROJECTS_NAMES
11  
12  
13  def setup_deterministic_generation_uuid(seed: int = 8754):
14      import uuid
15  
16      from faker import Faker
17  
18      Faker.seed(seed)
19      fake = Faker()
20  
21      def deterministic_uuid() -> uuid.UUID:
22          return fake.uuid4(cast_to=None)
23  
24      def deterministic_uuid6() -> uuid6.UUID:
25          return uuid6.UUID(int=deterministic_uuid().int)
26  
27      uuid.uuid4 = deterministic_uuid
28      uuid6.uuid7 = deterministic_uuid6
29  
30  
31  @app.command("legacy_ui")
32  def legacy_ui(
33      host: str = Option("127.0.0.1", help="Service host"),
34      port: int = Option(8000, help="Service port"),
35      workspace: str = Option("workspace", help="Path to workspace"),
36      demo_projects: str = Option(
37          "",
38          "--demo-projects",
39          help=f"Comma-separated list of demo projects to generate. Possible values: [{'|'.join(['all'] + DEMO_PROJECTS_NAMES)}]",
40      ),
41      secret: Optional[str] = Option(None, help="Secret for writing operations"),
42  ):
43      """Start Evidently UI service (legacy version)"""
44      if os.environ.get("EXPERIMENTAL_DETERMINISTIC_UUID"):
45          setup_deterministic_generation_uuid()
46  
47      from evidently.legacy.ui.app import run_local
48      from evidently.legacy.ui.demo_projects import DEMO_PROJECTS
49      from evidently.legacy.ui.workspace import Workspace
50  
51      demos = demo_projects.split(",") if demo_projects else []
52      if "all" in demos:
53          demos = DEMO_PROJECTS_NAMES
54      missing = [dp for dp in demos if dp not in DEMO_PROJECTS]
55      if missing:
56          raise BadParameter(f"Unknown demo project name '{missing[0]}'")
57  
58      if demos:
59          ws = Workspace.create(workspace)
60          for demo_project in demos:
61              dp = DEMO_PROJECTS[demo_project]
62  
63              has_demo_project = any(p.name == dp.name for p in ws.list_projects())
64              if not has_demo_project:
65                  echo(f"Generating demo project '{dp.name}'...")
66                  dp.create(workspace)
67      run_local(host, port, workspace, secret)