File size: 4,423 Bytes
8d5362c
ee34154
135e328
8d5362c
 
 
 
 
ee34154
 
 
 
 
 
 
8d5362c
 
ee34154
8d5362c
 
 
ee34154
 
 
 
8d5362c
 
 
 
135e328
 
 
 
 
 
 
626842d
 
50eafe9
626842d
 
 
 
ee34154
 
 
 
 
 
8d5362c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0d9624
8d5362c
 
 
a0d9624
 
 
 
 
 
ee34154
626842d
 
ee34154
626842d
 
 
 
 
ee34154
 
 
 
 
 
 
626842d
ee34154
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import os
import logging
import json


class Config:
    SECRET_KEY = os.environ.get("SECRET_KEY", "dev-secret-key-change-me")
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))
    # HF Spaces mounts its persistent volume at /data. Keep local development
    # usable when that mount is absent or not writable.
    _hf_data_dir = "/data"
    if not os.path.isdir(_hf_data_dir) or not os.access(_hf_data_dir, os.W_OK):
        _hf_data_dir = os.path.join(BASE_DIR, "data")
    DATA_DIR = os.environ.get("DATA_DIR", _hf_data_dir)
    LEGACY_DATABASE_PATH = os.path.join(BASE_DIR, "instance", "app.db")
    SQLALCHEMY_DATABASE_URI = os.environ.get(
        "DATABASE_URL",
        "sqlite:///" + os.path.join(DATA_DIR, "app.db"),
    )
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ECHO = False
    SQLALCHEMY_ENGINE_OPTIONS = (
        {"connect_args": {"timeout": 30}}
        if SQLALCHEMY_DATABASE_URI.startswith("sqlite:") else {}
    )
    MAX_CONTENT_LENGTH = 16 * 1024 * 1024
    AUTO_CREATE_MIN_PLAYERS = 5
    MAX_PLAYERS_DEFAULT = 15
    MIN_PLAYERS_DEFAULT = 5
    DEFAULT_GAME_TYPE = os.environ.get("DEFAULT_GAME_TYPE", "parlor_mystery")
    try:
        GAME_SETTINGS = json.loads(os.environ.get("GAME_SETTINGS_JSON", "{}"))
        if not isinstance(GAME_SETTINGS, dict):
            GAME_SETTINGS = {}
    except ValueError:
        GAME_SETTINGS = {}
    # The current shared Space intentionally has a small simulated guest pool.
    # Set TEST_MODE=false to disable it; account creation is hard-capped below.
    TEST_MODE = os.environ.get("TEST_MODE", "true").lower() in ("true", "1", "yes")
    TEST_BOT_MAX_ACCOUNTS = 10
    TEST_BOT_COUNT = TEST_BOT_MAX_ACCOUNTS
    TEST_BOT_CHAT_INTERVAL = max(30, int(os.environ.get("TEST_BOT_CHAT_INTERVAL", "60")))
    MATCHMAKING_MIN_WORDS = max(1, int(os.environ.get("MATCHMAKING_MIN_WORDS", "3")))
    MATCHMAKING_MIN_PLAYERS = int(os.environ.get("MATCHMAKING_MIN_PLAYERS", "5"))
    LOBBY_ROUND_SECONDS = int(os.environ.get("LOBBY_ROUND_SECONDS", "35"))
    LOBBY_CHAT_GENERATION_TOKEN = os.environ.get("LOBBY_CHAT_GENERATION_TOKEN", "")
    LOBBY_CHAT_API_URL = os.environ.get("LOBBY_CHAT_API_URL", "")
    LOBBY_CHAT_MODEL = os.environ.get("LOBBY_CHAT_MODEL", "")
    LOBBY_CHAT_API_KEY = os.environ.get("LOBBY_CHAT_API_KEY", "")
    AVATAR_STYLES_CC0 = [
        "adventurer",
        "adventurer-neutral",
        "avataaars",
        "avataaars-neutral",
        "big-ears",
        "big-ears-neutral",
        "big-smile",
        "bottts",
        "bottts-neutral",
        "croodles",
        "croodles-neutral",
        "fun-emoji",
        "icons",
        "identicon",
        "initials",
        "lorelei",
        "lorelei-neutral",
        "micah",
        "miniavs",
        "open-peeps",
        "personas",
        "pixel-art",
        "pixel-art-neutral",
        "rings",
        "shapes",
        "thumbs",
    ]
    AVATAR_BACKGROUNDS = ["transparent", "b6e3f4", "c0aede", "d1d4f9", "ffd5dc", "ffdfbf"]
    TELEMETRY_ENABLED = True
    PUBLIC_LOBBY_ENABLED = True
    INSTANCE_PATH = os.path.join(BASE_DIR, "instance")
    RESULTS_DIR = "/data/hf-inference-smoke"

    @staticmethod
    def ensure_data_dir():
        os.makedirs(Config.INSTANCE_PATH, exist_ok=True)
        os.makedirs(Config.DATA_DIR, exist_ok=True)
        target = os.path.join(Config.DATA_DIR, "app.db")
        # Never silently import a different historical dataset. If the active
        # target is absent, SQLAlchemy creates a new empty database at startup.
        if not os.environ.get("DATABASE_URL") and not os.path.exists(target):
            logging.getLogger(__name__).warning(
                "DATABASE_NEW_FILE path=%s legacy_ignored=%s",
                target,
                os.path.isfile(Config.LEGACY_DATABASE_PATH),
            )
        elif (
            not os.environ.get("DATABASE_URL")
            and os.path.isfile(target)
            and os.path.isfile(Config.LEGACY_DATABASE_PATH)
            and os.path.abspath(target) != os.path.abspath(Config.LEGACY_DATABASE_PATH)
        ):
            logging.getLogger(__name__).warning(
                "DATABASE_MULTIPLE_FILES active=%s active_bytes=%s legacy_ignored=%s legacy_bytes=%s",
                target,
                os.path.getsize(target),
                Config.LEGACY_DATABASE_PATH,
                os.path.getsize(Config.LEGACY_DATABASE_PATH),
            )