Spaces:
Build error
Build error
Update Dockerfile
Browse files11 unmodified lines1213141516171819202122232425262728293031323334353637383911 unmodified linesWORKDIR /appRUN mkdir -p /cache && chmod -R 777 /cache# write the appRUN echo 'from fastapi import FastAPI\n\from pydantic import BaseModel\n\from typing import List\n\from sentence_transformers import SentenceTransformer\n\import torch\n\app = FastAPI(title=\"gte-large-embed\")\n\device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\model = SentenceTransformer(\"thenlper/gte-large\", device=device)\n\class EmbedIn(BaseModel):\n\texts: List[str]\n\normalize: bool = True\n\batch_size: int = 32\n\@app.get(\"/health\")\n\def health():\n\return {\"ok\": True, \"device\": device}\n\@app.post(\"/embed\")\n\def embed(inp: EmbedIn):\n\vecs = model.encode(inp.texts, normalize_embeddings=inp.normalize, batch_size=inp.batch_size, convert_to_numpy=True, show_progress_bar=False)\n\return {\"embeddings\": vecs.tolist(), \"dim\": int(vecs.shape[1])}\n' > app.py# pre-download at build time to avoid /.cache permission issuesRUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('thenlper/gte-large').save('/cache/preload')"EXPOSE 786011 unmodified lines12131415161718192021222324252627282930313233343536373839404142434411 unmodified linesWORKDIR /appRUN mkdir -p /cache && chmod -R 777 /cache# write app.py cleanly (no escaping issues)RUN printf 'from fastapi import FastAPI\n\from pydantic import BaseModel\n\from typing import List\n\from sentence_transformers import SentenceTransformer\n\import torch\n\\n\app = FastAPI(title="gte-large-embed")\n\\n\device = "cuda" if torch.cuda.is_available() else "cpu"\n\model = SentenceTransformer("thenlper/gte-large", device=device)\n\\n\class EmbedIn(BaseModel):\n\texts: List[str]\n\normalize: bool = True\n\batch_size: int = 32\n\\n\@app.get("/health")\n\def health():\n\return {"ok": True, "device": device}\n\\n\@app.post("/embed")\n\def embed(inp: EmbedIn):\n\vecs = model.encode(inp.texts, normalize_embeddings=inp.normalize, batch_size=inp.batch_size, convert_to_numpy=True, show_progress_bar=False)\n\return {"embeddings": vecs.tolist(), "dim": int(vecs.shape[1])}\n' > app.py# preload model at build (avoids permission issues)RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('thenlper/gte-large').save('/cache/preload')"EXPOSE 7860
Dockerfile+15-10