Skip to content

Commit

Permalink
enforce loading models locally, so no time is wasted downloading them (
Browse files Browse the repository at this point in the history
  • Loading branch information
dcferreira authored May 20, 2023
1 parent 6165eba commit 116a749
Show file tree
Hide file tree
Showing 7 changed files with 1,652 additions and 1,470 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ RUN python -c 'from optimum.onnxruntime import ORTModelForSequenceClassification
model = ORTModelForSequenceClassification.from_pretrained("dcferreira/detoxify-optimized")'
RUN python -c 'from transformers import pipeline;\
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment";\
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path);\
print(sentiment_task("love you!"))'
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)'

# copy the serving code and our database
COPY app.py /code
Expand Down
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from dotenv import load_dotenv
from fastapi import FastAPI
from huggingface_hub import scan_cache_dir
from loguru import logger
from pydantic import HttpUrl
from pymongo import MongoClient
Expand All @@ -21,6 +22,9 @@
)
db: Database = client[os.environ["DATABASE_NAME"]]

if os.environ.get("DEBUG", False) == "1":
print(scan_cache_dir())


@app.post("/fetch")
async def fetch(url: HttpUrl) -> int:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ services:
environment:
- MONGODB_URL=mongodb://mongo:27017
- DATABASE_NAME=test_database
- DEBUG=1
ports:
- "5000:8080"
deploy:
resources:
limits:
memory: 2G
Loading

0 comments on commit 116a749

Please sign in to comment.