-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (26 loc) · 920 Bytes
/
app.py
File metadata and controls
33 lines (26 loc) · 920 Bytes
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
30
31
32
33
from fastapi import FastAPI , Query
from pydantic import BaseModel
import joblib
import uvicorn
model = joblib.load(open('stacking_rf_xgb_model.pkl', 'rb'))
vectorizer = joblib.load(open('tfidf_vectorizer.pkl', 'rb'))
app = FastAPI()
class Textinput(BaseModel):
message : str
@app.post("/classify")
async def classy_text(user_input : Textinput):
text_input = user_input.message
text_vector = vectorizer.transform([text_input])
prediction = model.predict(text_vector)
return {
'message' : text_input,
'prediction' : str(prediction)
}
@app.get("/to_get_classify")
async def classify_get(message: str = Query(..., description="Describe your problem here")):
text_vector = vectorizer.transform([message])
prediction = model.predict(text_vector)
return {
"message": message,
"prediction": str(prediction[0])
}