Spaces:
Sleeping
Sleeping
Deploy FastAPI app with Docker
Browse files- DockerFile +10 -0
- app.py +17 -0
- requirements.txt +3 -0
DockerFile
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY requirements.txt .
|
6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
7 |
+
|
8 |
+
COPY app.py .
|
9 |
+
|
10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
import uvicorn
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
model = SentenceTransformer('intfloat/multilingual-e5-base')
|
8 |
+
|
9 |
+
@app.post("/embed")
|
10 |
+
async def embed(request: Request):
|
11 |
+
body = await request.json()
|
12 |
+
text = body.get("text", "")
|
13 |
+
embedding = model.encode(text).tolist()
|
14 |
+
return {"embedding": embedding}
|
15 |
+
|
16 |
+
if __name__ == "__main__":
|
17 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
sentence_transformers
|
3 |
+
uvicorn
|