Spaces:
Sleeping
Sleeping
| import typing as t | |
| from collections import OrderedDict | |
| from marimo import create_asgi_app, nav_menu | |
| from pathlib import Path | |
| from .log import logger | |
| NB_FOLDER = Path(__file__).parent.parent / "nb" | |
| logger.info(f"NB_FOLDER: {NB_FOLDER}") | |
| class MarimoApps: | |
| def __init__(self, folder: Path = NB_FOLDER): | |
| self.folder = folder | |
| self.files: t.Dict[str, Path] = {} | |
| for file in self.folder.glob("prod_*.py"): | |
| logger.debug(f"Mounting Marimo app from: {file}") | |
| endpoint = "/" + file.stem.split("_")[-1] | |
| path = file.absolute() | |
| self.files[endpoint] = path | |
| def pages(self) -> OrderedDict[str, str]: | |
| _pages = OrderedDict({"/home": "Home"}) | |
| for endpoint in self.files: | |
| page_name = endpoint[1:].capitalize() | |
| _pages[endpoint] = page_name | |
| return _pages | |
| def build(self): | |
| apps = create_asgi_app(include_code=True) | |
| for endpoint, path in self.files.items(): | |
| apps = apps.with_app(path=endpoint, root=path) | |
| return apps.build() | |
| marimo_apps = MarimoApps() | |
| # print(marimo_apps.pages) | |
| class UI: | |
| TITLE = "Marimo on FastAPI" | |
| NAV = nav_menu(marimo_apps.pages, orientation="vertical").style(font_size="20px") | |