Commit
·
232a012
1
Parent(s):
e8ab2d2
Update for FastAPI integration
Browse files- Dockerfile +18 -0
- app.py +24 -0
- requirements.txt +5 -1
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user requirements.txt .
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user handler.py .
|
| 13 |
+
COPY --chown=user test_handler.py .
|
| 14 |
+
|
| 15 |
+
# Add FastAPI implementation
|
| 16 |
+
COPY --chown=user app.py .
|
| 17 |
+
|
| 18 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from handler import EndpointHandler
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
|
| 5 |
+
class Input(BaseModel):
|
| 6 |
+
inputs: str
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
handler = EndpointHandler()
|
| 10 |
+
|
| 11 |
+
@app.post("/generate")
|
| 12 |
+
async def generate(input_data: Input):
|
| 13 |
+
try:
|
| 14 |
+
result = handler({"inputs": input_data.inputs})
|
| 15 |
+
return result
|
| 16 |
+
except Exception as e:
|
| 17 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 18 |
+
|
| 19 |
+
@app.get("/")
|
| 20 |
+
async def root():
|
| 21 |
+
return {
|
| 22 |
+
"message": "FLAN-T5 Custom Handler API",
|
| 23 |
+
"usage": "POST /generate with {'inputs': 'your text here'}"
|
| 24 |
+
}
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
torch>=2.0.0
|
| 2 |
transformers>=4.30.0
|
| 3 |
-
huggingface-hub>=0.19.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
torch>=2.0.0
|
| 2 |
transformers>=4.30.0
|
| 3 |
+
huggingface-hub>=0.19.0
|
| 4 |
+
accelerate>=0.20.0
|
| 5 |
+
fastapi>=0.68.0
|
| 6 |
+
uvicorn[standard]>=0.15.0
|
| 7 |
+
pydantic>=1.8.0
|