RubenRicapa commited on
Commit
ea88043
1 Parent(s): 2410588

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. app.py +52 -0
  3. model.h5 +3 -0
  4. model.json +1 -0
  5. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+ COPY . .
11
+
12
+ RUN chmod -R 777 /code
13
+
14
+ # Comando para ejecutar la aplicación
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from keras.api.models import Sequential
2
+ from keras.api.layers import InputLayer, Dense
3
+ from fastapi import FastAPI, HTTPException
4
+ from pydantic import BaseModel
5
+ import numpy as np
6
+ from typing import List
7
+
8
+
9
+ class InputData(BaseModel):
10
+ data: List[float] # Lista de características numéricas (flotantes)
11
+
12
+
13
+ app = FastAPI()
14
+
15
+
16
+ # Función para construir el modelo manualmente
17
+ def build_model():
18
+ model = Sequential(
19
+ [
20
+ InputLayer(
21
+ input_shape=(2,), name="dense_2_input"
22
+ ), # Ajusta el tamaño de entrada según tu modelo
23
+ Dense(16, activation="relu", name="dense_2"),
24
+ Dense(1, activation="sigmoid", name="dense_3"),
25
+ ]
26
+ )
27
+ model.load_weights(
28
+ "model.h5"
29
+ ) # Asegúrate de que los nombres de las capas coincidan para que los pesos se carguen correctamente
30
+ model.compile(
31
+ loss="mean_squared_error", optimizer="adam", metrics=["binary_accuracy"]
32
+ )
33
+ return model
34
+
35
+
36
+ model = build_model() # Construir el modelo al iniciar la aplicación
37
+
38
+
39
+ # Ruta de predicción
40
+ @app.post("/predict/")
41
+ async def predict(data: InputData):
42
+ print(f"Data: {data}")
43
+ global model
44
+ try:
45
+ # Convertir la lista de entrada a un array de NumPy para la predicción
46
+ input_data = np.array(data.data).reshape(
47
+ 1, -1
48
+ ) # Asumiendo que la entrada debe ser de forma (1, num_features)
49
+ prediction = model.predict(input_data).round()
50
+ return {"prediction": prediction.tolist()}
51
+ except Exception as e:
52
+ raise HTTPException(status_code=500, detail=str(e))
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c77ee4f3b494b48b05355ea63692c68a94499890f2f8044406b6c45ea785599f
3
+ size 13864
model.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"module": "keras.layers", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 2], "dtype": "float32", "sparse": false, "ragged": false, "name": "dense_2_input"}, "registered_name": null}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "batch_input_shape": [null, 2], "units": 16, "activation": "relu", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 2]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_3", "trainable": true, "dtype": "float32", "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 16]}}]}, "keras_version": "2.15.0", "backend": "tensorflow"}
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow
2
+ keras
3
+ fastapi
4
+ numpy
5
+ pydantic