Spaces:
Build error
Build error
Update Dockerfile
Browse files5 unmodified lines6789910111213141516171819201920212223242122232425262729302829323334303132363738394041424333343536373839405 unmodified lines XDG_CACHE_HOME=/cache \ OMP_NUM_THREADS=1
RUN pip install --no-cache-dir "torch==2.3.1+cpu" --index-url https://download.pytorch.org/whl/cpu \RUN pip install --no-cache-dir fastapi uvicorn[standard] sentence-transformers && pip install --no-cache-dir fastapi uvicorn[standard] sentence-transformers
WORKDIR /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\\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\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\\n\@app.get("/health")\n\@app.get(\"/health\")\n\def health():\n\ return {"ok": True, "device": device}\n\\n\@app.post("/embed")\n\ return {\"ok\": True, \"device\": device}\n\@app.post(\"/embed\")\n\def embed(inp: EmbedIn):\n\ vecs = model.encode(\n\ inp.texts,\n\ normalize_embeddings=inp.normalize,\n\ batch_size=inp.batch_size,\n\ convert_to_numpy=True,\n\ show_progress_bar=False,\n\ )\n\ return {"embeddings": vecs.tolist(), "dim": int(vecs.shape[1])}\n' > app.py 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 7860CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860","--workers","1"]Dockerfile+14-20