Last active
August 25, 2021 19:04
-
-
Save edoakes/90731fdc168ea2b54c7eb28bbd79b522 to your computer and use it in GitHub Desktop.
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
import joblib | |
import s3fs | |
import sklearn | |
@serve.deployment(route_prefix="/sentiment", name="sentiment-deployment") | |
class SentimentDeployment: | |
def __init__(self): | |
fs = s3fs.S3FileSystem(anon=True) | |
with fs.open('ray-serve-blog/unigram_vectorizer.joblib', 'rb') as f: | |
self.vectorizer = joblib.load(f) | |
with fs.open('ray-serve-blog/unigram_tf_idf_transformer.joblib', 'rb') as f: | |
self.preprocessor = joblib.load(f) | |
with fs.open('ray-serve-blog/unigram_tf_idf_classifier.joblib', 'rb') as f: | |
self.classifier = joblib.load(f) | |
async def __call__(self, request): | |
data = await request.body() | |
vectorized = self.vectorizer.transform([str(data)]) | |
transformed = self.preprocessor.transform(vectorized) | |
[result] = self.classifier.predict(transformed) | |
if result == 1: | |
return 'POSITIVE' | |
else: | |
return 'NEGATIVE' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment