ShadowHunter222 commited on
Commit
436cde2
Β·
verified Β·
1 Parent(s): b1b6774

Delete config.py

Browse files
Files changed (1) hide show
  1. config.py +0 -102
config.py DELETED
@@ -1,102 +0,0 @@
1
- """
2
- Chatterbox Turbo TTS β€” Centralized Configuration
3
- ═══════════════════════════════════════════════════
4
- Optimised for HF Space free tier (2 vCPU).
5
- Adjust MODEL_DTYPE to switch quantization (q8/q4/fp16/fp32).
6
- All settings overridable via environment variables prefixed CB_.
7
- """
8
- import os
9
-
10
- _HERE = os.path.dirname(os.path.abspath(__file__))
11
-
12
-
13
- def _get_bool(name: str, default: bool) -> bool:
14
- raw = os.getenv(name)
15
- if raw is None:
16
- return default
17
- return raw.strip().lower() in {"1", "true", "yes", "on"}
18
-
19
-
20
- class Config:
21
- # ── Model ────────────────────────────────────────────────────
22
- MODEL_ID: str = os.getenv("CB_MODEL_ID", "ResembleAI/chatterbox-turbo-ONNX")
23
-
24
- # fp32 β†’ highest quality, ~1.4 GB, slowest
25
- # fp16 β†’ good quality, ~0.7 GB
26
- # q8 β†’ β˜… recommended, ~0.35 GB, best balance
27
- # q4 β†’ smallest, ~0.17 GB, fastest, slight loss
28
- # q4f16 β†’ q4 weights + fp16 activations
29
- MODEL_DTYPE: str = os.getenv("CB_MODEL_DTYPE", "q4")
30
-
31
- MODELS_DIR: str = os.getenv("CB_MODELS_DIR", os.path.join(_HERE, "models"))
32
-
33
- # ── ONNX Runtime CPU tuning (optimised for 2 vCPU) ───────────
34
- #
35
- # KEY RULE: intra_op threads MUST match physical cores.
36
- # β†’ 4 threads on 2 cores = oversubscription = SLOWER.
37
- # β†’ 2 threads on 2 cores = each op uses both cores perfectly.
38
- #
39
- # MAX_WORKERS = 1 ensures ONE inference gets both cores.
40
- # β†’ 2 workers would split 2 cores = both requests slow.
41
- #
42
- CPU_THREADS: int = int(os.getenv("CB_CPU_THREADS", "2"))
43
- MAX_WORKERS: int = int(os.getenv("CB_MAX_WORKERS", "1"))
44
-
45
- # ── Generation defaults ──────────────────────────────────────
46
- SAMPLE_RATE: int = 24000
47
- MAX_NEW_TOKENS: int = int(os.getenv("CB_MAX_NEW_TOKENS", "768"))
48
- REPETITION_PENALTY: float = float(os.getenv("CB_REPETITION_PENALTY", "1.2"))
49
- MAX_TEXT_LENGTH: int = int(os.getenv("CB_MAX_TEXT_LENGTH", "50000"))
50
-
51
- # ── Model constants (official card β€” do not change) ──────────
52
- START_SPEECH_TOKEN: int = 6561
53
- STOP_SPEECH_TOKEN: int = 6562
54
- SILENCE_TOKEN: int = 4299
55
- NUM_KV_HEADS: int = 16
56
- HEAD_DIM: int = 64
57
-
58
- # ── Paralinguistic tags (Turbo native) ───────────────────────
59
- PARALINGUISTIC_TAGS: tuple = (
60
- "laugh", "chuckle", "cough", "sigh", "gasp",
61
- "shush", "groan", "sniff", "clear throat",
62
- )
63
-
64
- # ── Voice / reference audio ──────────────────────────────────
65
- # NOTE: Official ResembleAI/chatterbox-turbo-ONNX has no bundled voice.
66
- # The default_voice.wav is a plain audio sample from community repo
67
- # (not a model β€” just a reference WAV, safe to use from any source).
68
- DEFAULT_VOICE_REPO: str = "onnx-community/chatterbox-ONNX"
69
- DEFAULT_VOICE_FILE: str = "default_voice.wav"
70
- MAX_VOICE_UPLOAD_BYTES: int = 10 * 1024 * 1024 # 10 MB
71
- MIN_REF_DURATION_SEC: float = 1.5
72
- MAX_REF_DURATION_SEC: float = 30.0
73
- VOICE_CACHE_SIZE: int = int(os.getenv("CB_VOICE_CACHE_SIZE", "20"))
74
- VOICE_CACHE_TTL_SEC: int = int(os.getenv("CB_VOICE_CACHE_TTL", "3600")) # 1 hour
75
-
76
- # ── Streaming ────────────────────────────────────────────────
77
- # Smaller chunks = faster TTFB (first audio arrives sooner)
78
- # ~200 chars β‰ˆ 1–2 sentences β‰ˆ fastest first-chunk on 2 vCPU
79
- MAX_CHUNK_CHARS: int = int(os.getenv("CB_MAX_CHUNK_CHARS", "100"))
80
- # Additive parallel mode (odd/even split across primary/helper).
81
- ENABLE_PARALLEL_MODE: bool = _get_bool("CB_ENABLE_PARALLEL_MODE", True)
82
- HELPER_BASE_URL: str = os.getenv("CB_HELPER_BASE_URL", "https://shadowhunter222-chab2.hf.space").strip()
83
- HELPER_TIMEOUT_SEC: float = float(os.getenv("CB_HELPER_TIMEOUT_SEC", "45"))
84
- HELPER_RETRY_ONCE: bool = _get_bool("CB_HELPER_RETRY_ONCE", True)
85
- # Optional shared secret for internal chunk endpoints.
86
- INTERNAL_SHARED_SECRET: str = os.getenv("CB_INTERNAL_SHARED_SECRET", "").strip()
87
-
88
- # ── Server ───────────────────────────────────────────────────
89
- HOST: str = os.getenv("CB_HOST", "0.0.0.0")
90
- PORT: int = int(os.getenv("CB_PORT", "7860"))
91
-
92
- ALLOWED_ORIGINS: list = [
93
- "https://www.toolboxesai.com",
94
- "www.toolboxesai.com",
95
- "https://toolboxesai.com",
96
- "http://localhost:8788", "http://127.0.0.1:8788",
97
- "http://localhost:5502", "http://127.0.0.1:5502",
98
- "http://localhost:5501", "http://127.0.0.1:5501",
99
- "http://localhost:5500", "http://127.0.0.1:5500",
100
- "http://localhost:5173", "http://127.0.0.1:5173",
101
- "http://localhost:7860", "http://127.0.0.1:7860",
102
- ]