File size: 1,970 Bytes
c1300fe
 
 
 
 
 
 
 
 
 
 
 
 
 
f95a1f1
 
 
720b664
f95a1f1
 
 
 
2d42370
 
eebe76e
f95a1f1
c560e99
f95a1f1
 
 
720b664
f80f41e
f95a1f1
 
 
 
 
 
f80f41e
 
f95a1f1
 
 
 
 
 
 
 
720b664
 
f95a1f1
 
6fff7cf
 
 
 
 
 
 
 
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
import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()

BASE_DIR = Path(__file__).resolve().parent

HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HF_API_TOKEN")
if HF_TOKEN is None:
    raise RuntimeError(
        "HF_TOKEN or HF_API_TOKEN is not set. "
        "Go to Space → Settings → Variables & secrets and add one."
    )

FOUR_HOURS = 4 * 60 * 60  # 4 hours * 60 minutes * 60 seconds

MAX_RAM_USAGE_PERCENT = 90

# Max history messages to keep for context
MAX_HISTORY = 20

MAX_MESSAGE_LENGTH = 2500
MAX_COMMENT_LENGTH = 2500
MAX_RESPONSE_LENGTH = 5000
MAX_ID_LENGTH = 50
MAX_FILE_NAME_LENGTH = 50

MAX_FILE_SIZE = 10 * 1024 * 1024  # 10 MB
FILE_CHUNK_SIZE = 1024 * 1024  # 1 MB
MAX_FILE_SIZES_PER_SESSION = 30 * 1024 * 1024  # 30 MB
TEXT_EXTRACTION_TIMEOUT = 10  # 10 seconds

SUPPORTED_FILE_EXTENSIONS = {".txt", ".pdf", ".docx", ".jpg", ".jpeg", ".png"}
SUPPORTED_FILE_TYPES = {
    "text/plain",  # .txt
    "application/pdf",  # .pdf
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",  # .docx
    # TODO: magic can detect docx files as zip files, but not always. Under which conditions?
    # "application/zip",
    "image/jpeg",  # .jpeg and .jpg
    "image/png",  # .png
}

STATUS_CODE_BAD_REQUEST = 400
STATUS_CODE_LENGTH_REQUIRED = 411
STATUS_CODE_CONTENT_TOO_LARGE = 413
STATUS_CODE_UNSUPPORTED_MEDIA_TYPE = 415
# Custom status code. Used when the user sends a file that would exceed the MAX_FILE_SIZES_PER_SESSION limit
STATUS_CODE_EXCEED_SIZE_LIMIT = 419
STATUS_CODE_UNPROCESSABLE_CONTENT = 422
STATUS_CODE_INTERNAL_SERVER_ERROR = 500
# The "Google" models are differentiated by their temperature.
MODEL_MAP = {
    "champ": "champ-model/placeholder",
    "qwen": "qwen-model/placeholder",
    "openai": "gpt-5-mini-2025-08-07",
    "google-conservative": "gemini-2.5-flash-lite",
    "google-creative": "gemini-2.5-flash-lite",
}