Upload 4 files
Browse files- Dockerfile +16 -0
- app.py +45 -0
- miarbol.pkl +3 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Usa una imagen base de Python
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
# Establece el directorio de trabajo
|
| 4 |
+
WORKDIR /code
|
| 5 |
+
|
| 6 |
+
# Copia los archivos necesarios al contenedor
|
| 7 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 8 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
| 9 |
+
RUN pip install fastapi uvicorn
|
| 10 |
+
|
| 11 |
+
COPY . .
|
| 12 |
+
|
| 13 |
+
RUN chmod -R 777 /code
|
| 14 |
+
|
| 15 |
+
# Comando para ejecutar la aplicaci贸n
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
np.random.seed(0)
|
| 3 |
+
import pickle
|
| 4 |
+
from sklearn.compose import ColumnTransformer
|
| 5 |
+
from sklearn.datasets import fetch_openml
|
| 6 |
+
from sklearn.pipeline import Pipeline
|
| 7 |
+
from sklearn.impute import SimpleImputer
|
| 8 |
+
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
| 9 |
+
from sklearn.linear_model import LogisticRegression
|
| 10 |
+
from sklearn.model_selection import train_test_split
|
| 11 |
+
|
| 12 |
+
from sklearn import tree
|
| 13 |
+
|
| 14 |
+
from fastapi import FastAPI, HTTPException
|
| 15 |
+
from fastapi.responses import HTMLResponse
|
| 16 |
+
from pydantic import BaseModel
|
| 17 |
+
from typing import List
|
| 18 |
+
|
| 19 |
+
class InputData(BaseModel):
|
| 20 |
+
data: List[float]
|
| 21 |
+
|
| 22 |
+
# Inicializar la aplicaci贸n FastAPI
|
| 23 |
+
app = FastAPI()
|
| 24 |
+
|
| 25 |
+
def build_model():
|
| 26 |
+
with open('miarbol.pkl', 'rb') as fid:
|
| 27 |
+
miarbol = pickle.load(fid)
|
| 28 |
+
return miarbol
|
| 29 |
+
|
| 30 |
+
miarbol = build_model()
|
| 31 |
+
|
| 32 |
+
# Ruta de predicci贸n
|
| 33 |
+
@app.post("/predict/")
|
| 34 |
+
async def predict(data: InputData):
|
| 35 |
+
print(f"Data: {data}")
|
| 36 |
+
global miarbol
|
| 37 |
+
try:
|
| 38 |
+
# Convertir la lista de entrada a un array de NumPy para la predicci贸n
|
| 39 |
+
input_data = np.array(data.data).reshape(
|
| 40 |
+
1, -1
|
| 41 |
+
) # Asumiendo que la entrada debe ser de forma (1, num_features)
|
| 42 |
+
prediction = miarbol.predict(input_data).round()
|
| 43 |
+
return {"prediction": prediction.tolist()}
|
| 44 |
+
except Exception as e:
|
| 45 |
+
raise HTTPException(status_code=500, detail=str(e))
|
miarbol.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc36198b3af3b35a271818578495bda8162b334cfcb265d1af797265d3b257ac
|
| 3 |
+
size 17226
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
numpy
|
| 3 |
+
setuptools
|
| 4 |
+
scikit-learn
|
| 5 |
+
pydantic
|
| 6 |
+
uvicorn
|