Spaces:
Running on Zero
Running on Zero
| """Shared configuration for the initial mock MVP.""" | |
| import os | |
| from collections.abc import Mapping | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| APP_TITLE = "Objectverse Diary" | |
| APP_SUBTITLE = "Every object has a secret life. / 每个物品都有秘密人生。" | |
| APP_VERSION = "0.1.0-mock" | |
| PERSONALITY_MODES = [ | |
| "Cynical", | |
| "Dramatic", | |
| "Lonely", | |
| "Philosopher", | |
| "Romantic", | |
| ] | |
| DEFAULT_MODE = "Cynical" | |
| class RuntimeSettings: | |
| vision_backend: str | |
| text_backend: str | |
| text_model_path: str | |
| text_model_repo_id: str | |
| text_model_filename: str | |
| text_model_revision: str | |
| vision_model_id: str | |
| trace_output_dir: Path | |
| def get_runtime_settings(environ: Mapping[str, str] | None = None) -> RuntimeSettings: | |
| env = os.environ if environ is None else environ | |
| return RuntimeSettings( | |
| vision_backend=env.get("OBJECTVERSE_VISION_BACKEND", "mock"), | |
| text_backend=env.get("OBJECTVERSE_TEXT_BACKEND", "mock"), | |
| text_model_path=env.get("TEXT_MODEL_PATH", ""), | |
| text_model_repo_id=env.get("TEXT_MODEL_REPO_ID", ""), | |
| text_model_filename=env.get("TEXT_MODEL_FILENAME", ""), | |
| text_model_revision=env.get("TEXT_MODEL_REVISION", ""), | |
| vision_model_id=env.get("VISION_MODEL_ID", ""), | |
| trace_output_dir=Path(env.get("TRACE_OUTPUT_DIR", "data/traces")), | |
| ) | |
| def runtime_status(settings: RuntimeSettings | None = None) -> dict[str, str]: | |
| current = settings or get_runtime_settings() | |
| vision_backend = current.vision_backend.strip().lower() | |
| text_backend = current.text_backend.strip().lower() | |
| vision = ( | |
| "mock object understanding" | |
| if vision_backend == "mock" | |
| else f"{vision_backend} object understanding" | |
| ) | |
| text = "mock persona and diary generation" | |
| if text_backend in {"llama-cpp", "llama_cpp", "llamacpp"}: | |
| text = "llama-cpp text generation" | |
| elif text_backend != "mock": | |
| text = f"{text_backend} text generation" | |
| runtime_parts: list[str] = [] | |
| if vision_backend != "mock": | |
| runtime_parts.append(f"vision model id: {current.vision_model_id or '[not configured]'}") | |
| if text_backend == "mock": | |
| runtime_parts.append("no llama.cpp model connected yet") | |
| else: | |
| runtime_parts.append(f"text model source: {_text_model_source_status(current)}") | |
| runtime = "; ".join(runtime_parts) | |
| return {"vision": vision, "text": text, "runtime": runtime} | |
| def _text_model_source_status(settings: RuntimeSettings) -> str: | |
| if settings.text_model_path.strip(): | |
| return "[configured external GGUF]" | |
| repo_id = settings.text_model_repo_id.strip() | |
| filename = settings.text_model_filename.strip() | |
| if repo_id and filename: | |
| revision = settings.text_model_revision.strip() | |
| suffix = f"@{revision}" if revision else "" | |
| return f"Hub GGUF: {repo_id}/{filename}{suffix}" | |
| return "[not configured]" | |
| SETTINGS = get_runtime_settings() | |
| TRACE_DIR = SETTINGS.trace_output_dir | |
| MODEL_RUNTIME_STATUS = runtime_status(SETTINGS) | |