Spaces:
Running
Running
| set -e | |
| echo "π§ PostBuild starting β optimizing CT-Chat Space..." | |
| # ------------------------------------------------------- | |
| # 1οΈβ£ Fix dependency mismatches (Gradio & Websockets) | |
| # ------------------------------------------------------- | |
| pip install --force-reinstall --no-cache-dir "websockets>=12" "gradio-client>=1.3.0" | |
| # ------------------------------------------------------- | |
| # 2οΈβ£ Create and register shared NLTK data directory | |
| # ------------------------------------------------------- | |
| echo "π Preparing shared NLTK data directory..." | |
| export NLTK_DATA="/usr/local/share/nltk_data" | |
| mkdir -p $NLTK_DATA | |
| chmod -R 777 $NLTK_DATA | |
| # ------------------------------------------------------- | |
| # 3οΈβ£ Preload all required NLTK resources (including punkt_tab) | |
| # ------------------------------------------------------- | |
| echo "π¦ Downloading NLTK resources..." | |
| python -m nltk.downloader -d $NLTK_DATA \ | |
| punkt punkt_tab averaged_perceptron_tagger averaged_perceptron_tagger_eng stopwords wordnet omw-1.4 | |
| # ------------------------------------------------------- | |
| # 4οΈβ£ Verify NLTK installs and paths | |
| # ------------------------------------------------------- | |
| python - <<'PYCODE' | |
| import nltk, os | |
| print(f"NLTK data path β {nltk.data.path}") | |
| for pkg in ["punkt", "punkt_tab", "averaged_perceptron_tagger_eng", "stopwords", "wordnet"]: | |
| try: | |
| nltk.data.find(pkg) | |
| print(f"β Verified NLTK resource: {pkg}") | |
| except LookupError: | |
| print(f"β οΈ Missing NLTK resource: {pkg}") | |
| PYCODE | |
| # ------------------------------------------------------- | |
| # 5οΈβ£ Clean caches (stay <50GB) | |
| # ------------------------------------------------------- | |
| echo "π§Ή Cleaning Hugging Face + Torch caches..." | |
| rm -rf /root/.cache/* || true | |
| rm -rf /home/user/.cache/* || true | |
| rm -rf /usr/local/share/nltk_data/taggers/__pycache__ || true | |
| rm -rf /home/user/app/hf_cache/* || true | |
| rm -rf /home/user/app/logs/* || true | |
| # ------------------------------------------------------- | |
| # 6οΈβ£ Ensure writable temporary cache for runtime | |
| # ------------------------------------------------------- | |
| echo "π¦ Preparing /tmp/hf_cache..." | |
| mkdir -p /tmp/hf_cache | |
| chmod -R 777 /tmp/hf_cache | |
| # ------------------------------------------------------- | |
| # β Done | |
| # ------------------------------------------------------- | |
| echo "β PostBuild completed successfully β NLTK preloaded (punkt_tab OK), cache ready at /tmp/hf_cache." | |