Spaces:
Sleeping
Sleeping
MarceloLZR
commited on
Upload 4 files
Browse files- app.py +40 -0
- matrizMM.txt +10 -0
- requirements.txt +5 -0
- somecoli.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
from minisom import MiniSom
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
from fastapi import FastAPI, HTTPException
|
6 |
+
from pydantic import BaseModel
|
7 |
+
from typing import List
|
8 |
+
|
9 |
+
class InputData(BaseModel):
|
10 |
+
data: List[float] # Lista de caracter铆sticas num茅ricas (flotantes)
|
11 |
+
|
12 |
+
app = FastAPI()
|
13 |
+
|
14 |
+
# Funci贸n para construir el modelo manualmente
|
15 |
+
def build_model():
|
16 |
+
with open('somecoli.pkl', 'rb') as fid:
|
17 |
+
somecoli = pickle.load(fid)
|
18 |
+
MM = np.loadtxt('matrizMM.txt', delimiter=" ")
|
19 |
+
return somecoli,MM
|
20 |
+
|
21 |
+
som,MM = build_model() # Construir el modelo al iniciar la aplicaci贸n
|
22 |
+
|
23 |
+
# Ruta de predicci贸n
|
24 |
+
@app.post("/predict/")
|
25 |
+
async def predict(data: InputData):
|
26 |
+
print(f"Data: {data}")
|
27 |
+
global som
|
28 |
+
global MM
|
29 |
+
try:
|
30 |
+
# Convertir la lista de entrada a un array de NumPy para la predicci贸n
|
31 |
+
input_data = np.array(data.data).reshape(
|
32 |
+
1, -1
|
33 |
+
) # Asumiendo que la entrada debe ser de forma (1, num_features)
|
34 |
+
#input_data = [float(f) for f in input_data]
|
35 |
+
w = som.winner(input_data)
|
36 |
+
prediction = MM[w]
|
37 |
+
|
38 |
+
return {"prediction": prediction.tolist()}
|
39 |
+
except Exception as e:
|
40 |
+
raise HTTPException(status_code=500, detail=str(e))
|
matrizMM.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 7.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00
|
2 |
+
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 7.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00
|
3 |
+
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00
|
4 |
+
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00
|
5 |
+
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 4.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 4.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00
|
6 |
+
5.000000000000000000e+00 0.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 0.000000000000000000e+00 7.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000000e+00 7.000000000000000000e+00
|
7 |
+
5.000000000000000000e+00 5.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 1.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00
|
8 |
+
5.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00
|
9 |
+
5.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 1.000000000000000000e+00
|
10 |
+
4.000000000000000000e+00 6.000000000000000000e+00 3.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 7.000000000000000000e+00 1.000000000000000000e+00 4.000000000000000000e+00 4.000000000000000000e+00 1.000000000000000000e+00
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
minisom
|
3 |
+
fastapi
|
4 |
+
numpy
|
5 |
+
pydantic
|
somecoli.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6fef630a7f5255a12c23eb9bc352990011bc0e2b82e0c0c602e1f4700ee270b
|
3 |
+
size 11594
|