Skip to content

Commit e1d8887

Browse files
committedApr 25, 2023
API inicio
1 parent 18aa717 commit e1d8887

8 files changed

+46
-0
lines changed
 

‎DataModel.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pydantic import BaseModel
2+
3+
class DataModel(BaseModel):
4+
review_es : str
5+
sentimiento : str
6+
7+
def columns(self):
8+
return ['review_es', 'sentimiento']

‎PredictionModel.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from joblib import load
2+
3+
class Model:
4+
5+
def __init__(self,columns):
6+
self.model = load("assets/pipelineNaiveBayes.joblib")
7+
8+
def make_predictions(self, data):
9+
result = self.model.predict(data)
10+
return result

‎__pycache__/DataModel.cpython-310.pyc

548 Bytes
Binary file not shown.

‎__pycache__/main.cpython-310.pyc

1001 Bytes
Binary file not shown.

‎assets/pipelineKNN.joblib

1.83 MB
Binary file not shown.

‎assets/pipelineNaiveBayes.joblib

645 KB
Binary file not shown.

‎assets/pipelineRandomForest.joblib

17.3 MB
Binary file not shown.

‎main.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Optional
2+
3+
from fastapi import FastAPI
4+
5+
from DataModel import DataModel
6+
7+
from joblib import load
8+
9+
import pandas as pd
10+
11+
app = FastAPI()
12+
13+
14+
@app.get("/")
15+
def read_root():
16+
return {"Hello": "World"}
17+
18+
@app.get("/items/{item_id}")
19+
def read_item(item_id: int, q: Optional[str] = None):
20+
return {"item_id": item_id, "q": q}
21+
22+
@app.post("/predict")
23+
def make_predictions(dataModel: DataModel):
24+
df = pd.DataFrame(dataModel.dict(), columns=dataModel.dict().keys(), index=[0])
25+
df.columns = dataModel.columns()
26+
model = load("assets/pipelineNaiveBayes.joblib")
27+
result = model.predict(df)
28+
return result

0 commit comments

Comments
 (0)
Please sign in to comment.