Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mob next [ci-skip] [ci skip] [skip ci]
Browse files Browse the repository at this point in the history
lastFile:src/skore/dashboard/app.py
rouk1 committed Sep 10, 2024
1 parent 3285335 commit e97a382
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/skore/dashboard/app.py
Original file line number Diff line number Diff line change
@@ -7,10 +7,12 @@

from skore.api import create_api_app
from skore.project import Project
from skore.storage.filesystem import FileSystem


def create_dashboard_app(project: Project) -> FastAPI:
def create_dashboard_app(project: Project | None = None) -> FastAPI:
"""FastAPI factory used to create the dashboard to display stores."""
project = project or Project(FileSystem(directory=Path.cwd()))
app = create_api_app(project=project)

# Mount frontend from the static directory.
6 changes: 2 additions & 4 deletions src/skore/dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Implement the "launch" command."""

import os
import threading
import time
import webbrowser
@@ -9,6 +8,7 @@
import uvicorn

from skore import logger
from skore.dashboard.app import create_dashboard_app
from skore.project import load


@@ -40,9 +40,7 @@ def __launch(directory: str | Path, port: int, open_browser: bool):
A tuple with the dashboard and the project directory path if succeeded,
None if failed
"""
logger.info(
f"Running dashboard from '{directory}' at URL http://localhost:{port}"
)
logger.info(f"Running dashboard from '{directory}' at URL http://localhost:{port}")

if open_browser:
threading.Thread(target=lambda: __open_browser(port=port)).start()
6 changes: 3 additions & 3 deletions src/skore/project.py
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@
import base64
import json
from dataclasses import dataclass
from enum import StrEnum, auto
from io import StringIO
from pathlib import Path
from typing import Any, List
from enum import StrEnum, auto

from skore.storage import Storage
from skore.storage.filesystem import FileSystem
@@ -80,7 +80,7 @@ def serialize(o: Any) -> Item:


def deserialize(
item_type: str | ItemType,
item_type: ItemType,
media_type: str | None,
serialized: str,
) -> Item:
@@ -151,7 +151,7 @@ def delete_item(self, key: str):


def load(directory: str | Path) -> Project:
storage = FileSystem(directory=directory)
storage = FileSystem(directory=Path(directory))
project = Project(storage=storage)

return project
20 changes: 10 additions & 10 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
@@ -186,52 +186,52 @@ def savefig(*args, **kwargs):

assert project.storage.content == {
"string_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": '"Hello, World!"',
"media_type": None,
},
"int_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": "42",
"media_type": None,
},
"float_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": "3.14",
"media_type": None,
},
"bool_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": "true",
"media_type": None,
},
"list_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": "[1, 2, 3]",
"media_type": None,
},
"dict_item": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.JSON),
"serialized": '{"key": "value"}',
"media_type": None,
},
"pandas_df": {
"item_type": ItemType.JSON,
"item_type": str(ItemType.PANDAS_DATAFRAME),
"serialized": '{"columns":["A","B"],"index":[0,1,2],"data":[[1,4],[2,5],[3,6]]}',
"media_type": None,
},
"numpy_array": {
"item_type": ItemType.NUMPY_ARRAY,
"item_type": str(ItemType.NUMPY_ARRAY),
"serialized": "[1, 2, 3, 4, 5]",
"media_type": None,
},
"mpl_figure": {
"item_type": ItemType.MEDIA,
"item_type": str(ItemType.MEDIA),
"serialized": "",
"media_type": "image/svg+xml",
},
"rf_model": {
"item_type": ItemType.SKLEARN_BASE_ESTIMATOR,
"item_type": str(ItemType.SKLEARN_BASE_ESTIMATOR),
"serialized": '{"skops": "", "html": ""}',
"media_type": "text/html",
},

0 comments on commit e97a382

Please sign in to comment.