File size: 836 Bytes
e316253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from fastapi import FastAPI
from type.request.predict import PredictRequest
from type.response.predict import PredictResponse
from hugging_face import model, dataset
from transformer import transformer

import sys

hate_speech_model = model.load_hugging_face_model('model_svm.pkl')
hate_speech_dataset = dataset.load_dataset('data_clean.csv')
tfidf = transformer.create_tfidf(hate_speech_dataset, 'Tweet', 'U')

app = FastAPI()

@app.get("/healthz")
def healthz():
  return {"message": "All system running well :)"}

@app.post("/predict")
def predict(request: PredictRequest):
  predict_text = [request.predict_text]

  predict_text = tfidf.transform(predict_text)
  prediction = hate_speech_model.predict(predict_text)
  
  return PredictResponse(
    predict_text = request.predict_text, 
    is_hate_speech = prediction[0] == 1
    )