-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add requirements * implement serving * tests for fast api * update readme
- Loading branch information
1 parent
2ffe427
commit 9e483c9
Showing
6 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ scikit-learn==1.3.2 | |
accelerate==0.25.0 | ||
datasets==2.16.1 | ||
wandb==0.16.1 | ||
httpx==0.26.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ flask==3.0.0 | |
gunicorn==21.2.0 | ||
transformers==4.36.2 | ||
streamlit==1.29.0 | ||
|
||
fastapi==0.108.0 | ||
uvicorn==0.25.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import List | ||
|
||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
from src.serving.model import BertPredictor | ||
|
||
|
||
class Payload(BaseModel): | ||
text: List[str] | ||
|
||
|
||
app = FastAPI() | ||
predictor = BertPredictor.from_model_registry() | ||
|
||
|
||
@app.post("/predict") | ||
def predict(payload: Payload): | ||
prediction = predictor.predict(text=payload.text) | ||
return prediction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from unittest.mock import Mock | ||
from src.serving.model import BertPredictor | ||
|
||
def mock_predict(text): | ||
return ['positive' for _ in text] | ||
|
||
BertPredictor.from_model_registry = Mock(return_value=Mock(predict=mock_predict)) | ||
|
||
|
||
|
||
def test_predict(): | ||
from src.serving.fastapi import app | ||
client = TestClient(app) | ||
|
||
payload = { | ||
"text": ["This is a test sentence.", "Here's another one!"] | ||
} | ||
|
||
response = client.post("/predict", json=payload) | ||
|
||
assert response.status_code == 200 | ||
|
||
data = response.json() | ||
assert isinstance(data, list) | ||
assert len(data) == len(payload['text']) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.