CoolFace
Apppublic

JetLaggedByData/scifi-forge

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
Dockerfile77 linesDownload Raw Back to root
1# Dockerfile2# SciFi Forge — lite app for Hugging Face Spaces (CPU, 16GB RAM)3#4# Builds the app/main.py Streamlit app (auto-detects CPU/GPU at runtime).5# Does NOT include GPU drivers — Qwen2.5-0.5B runs fine on CPU.6#7# Local test:8#   docker build -t scifi-forge .9#   docker run -p 7860:7860 scifi-forge10#   open http://localhost:786011#12# HF Spaces auto-builds from this file (README.md sets sdk: docker).13 14FROM python:3.10-slim15 16# ── System deps ───────────────────────────────────────────────────────────17RUN apt-get update && apt-get install -y --no-install-recommends \18        git \19        curl \20        build-essential \21    && rm -rf /var/lib/apt/lists/*22 23# ── Working directory ─────────────────────────────────────────────────────24WORKDIR /app25 26# ── Python deps (layer-cached separately from app code) ──────────────────27COPY requirements-lite.txt .28 29# Install CPU-only PyTorch explicitly before everything else.30# Must come first — without the --index-url flag pip would pull the 3GB CUDA build.31RUN pip install --no-cache-dir \32    "torch==2.2.0" "torchvision==0.17.0" "torchaudio==2.2.0" \33    --index-url https://download.pytorch.org/whl/cpu34 35# Install lite app dependencies (no CUDA, no TF, no bitsandbytes)36RUN pip install --no-cache-dir -r requirements-lite.txt37 38# ── App code ──────────────────────────────────────────────────────────────39COPY . .40 41# ── HF Spaces runs as non-root user ──────────────────────────────────────42RUN useradd -m -u 1000 appuser \43    && chown -R appuser:appuser /app44USER appuser45 46# ── Pre-cache HuggingFace model weights at build time ────────────────────47# This avoids a slow first-request download on HF Spaces.48# Remove this block if you want a faster build at the cost of slower cold start.49RUN python -c "\50from transformers import AutoTokenizer, AutoModelForCausalLM; \51import torch; \52tok = AutoTokenizer.from_pretrained('Qwen/Qwen2.5-0.5B-Instruct', trust_remote_code=True); \53m = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-0.5B-Instruct', \54    device_map='cpu', torch_dtype=torch.float32, trust_remote_code=True, \55    low_cpu_mem_usage=True); \56print('Model cached successfully')"57 58# ── Runtime env ───────────────────────────────────────────────────────────59ENV PYTHONUNBUFFERED=160ENV LITE_MODE=161ENV STREAMLIT_SERVER_PORT=786062ENV STREAMLIT_SERVER_ADDRESS=0.0.0.063ENV STREAMLIT_SERVER_FILE_WATCHER_TYPE=none64ENV STREAMLIT_SERVER_ENABLE_CORS=false65ENV STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false66# Silence HuggingFace symlink warning on Spaces67ENV HF_HUB_DISABLE_SYMLINKS_WARNING=168 69EXPOSE 786070 71CMD ["streamlit", "run", "app/main.py", \72     "--server.port=7860", \73     "--server.address=0.0.0.0", \74     "--server.fileWatcherType=none", \75     "--server.enableCORS=false", \76     "--server.enableXsrfProtection=false"]77