Spaces:
Sleeping
Sleeping
RaulHuarote
commited on
Commit
•
0e923cd
1
Parent(s):
034c215
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
from keras.api.models import Sequential
|
3 |
from keras.api.layers import InputLayer, Dense
|
4 |
from fastapi import FastAPI, HTTPException
|
@@ -6,30 +5,20 @@ from pydantic import BaseModel
|
|
6 |
import numpy as np
|
7 |
from typing import List
|
8 |
|
9 |
-
from keras.models import Sequential, Model, load_model
|
10 |
-
from keras.layers import Dropout, Flatten, Dense
|
11 |
-
from keras import optimizers
|
12 |
-
from keras.models import model_from_json
|
13 |
|
14 |
class InputData(BaseModel):
|
15 |
data: List[float] # Lista de características numéricas (flotantes)
|
16 |
|
|
|
17 |
app = FastAPI()
|
18 |
|
|
|
19 |
# Función para construir el modelo manualmente
|
20 |
def build_model():
|
21 |
-
"""
|
22 |
-
with open('model.json','r') as f:
|
23 |
-
json = f.read()
|
24 |
-
model = model_from_json(json)
|
25 |
-
|
26 |
-
|
27 |
-
"""
|
28 |
-
|
29 |
model = Sequential(
|
30 |
[
|
31 |
InputLayer(
|
32 |
-
|
33 |
), # Ajusta el tamaño de entrada según tu modelo
|
34 |
Dense(16, activation="relu", name="dense_2"),
|
35 |
Dense(1, activation="sigmoid", name="dense_3"),
|
@@ -54,12 +43,10 @@ async def predict(data: InputData):
|
|
54 |
global model
|
55 |
try:
|
56 |
# Convertir la lista de entrada a un array de NumPy para la predicción
|
57 |
-
input_data = np.array(data.data).reshape(
|
58 |
-
|
|
|
59 |
prediction = model.predict(input_data).round()
|
60 |
-
|
61 |
-
#prediction = 9
|
62 |
-
#print(prediction)
|
63 |
-
return {"prediction": prediction}
|
64 |
except Exception as e:
|
65 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
1 |
from keras.api.models import Sequential
|
2 |
from keras.api.layers import InputLayer, Dense
|
3 |
from fastapi import FastAPI, HTTPException
|
|
|
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"),
|
|
|
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))
|