Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +24 -0
- app.py +21 -0
- requirements.txt +5 -0
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Python runtime as a parent image
|
2 |
+
FROM python:3.11
|
3 |
+
|
4 |
+
# Set the working directory in the container
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Copy the requirements file into the container at /app
|
8 |
+
COPY requirements.txt /app/requirements.txt
|
9 |
+
|
10 |
+
# Install any dependencies specified in requirements.txt
|
11 |
+
RUN pip install --upgrade pip
|
12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
13 |
+
|
14 |
+
# Copy the rest of the working directory contents into the container at /app
|
15 |
+
COPY app.py /app
|
16 |
+
|
17 |
+
# Make port 8000 available to the world outside this container
|
18 |
+
EXPOSE 2000
|
19 |
+
|
20 |
+
# Health check to ensure the container is running
|
21 |
+
HEALTHCHECK CMD curl --fail http://localhost:2000 || exit 1
|
22 |
+
|
23 |
+
# Run uvicorn server
|
24 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "2000"]
|
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from typing import List
|
4 |
+
from sentence_transformers import SentenceTransformer
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
model = SentenceTransformer('sentence-transformers/gtr-t5-base')
|
9 |
+
|
10 |
+
class TextBatch(BaseModel):
|
11 |
+
texts: List[str]
|
12 |
+
|
13 |
+
@app.post("/embed")
|
14 |
+
async def get_embeddings(batch: TextBatch):
|
15 |
+
embeddings = model.encode(batch.texts)
|
16 |
+
return {"embeddings": embeddings.tolist()}
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
import uvicorn
|
20 |
+
uvicorn.run(app, host="0.0.0.0", port=2000)
|
21 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
RUN pip install --no-cache-dir torch==2.3.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
2 |
+
uvicorn==0.30.1
|
3 |
+
fastapi==0.111.0
|
4 |
+
pydantic==2.7.3
|
5 |
+
sentence-transformers==3.0.0
|