Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from pydantic import BaseModel
|
3 |
-
import pickle
|
4 |
-
import numpy as np
|
5 |
-
from fastapi.middleware.cors import CORSMiddleware
|
6 |
-
|
7 |
-
# Cargar el modelo desde el archivo .pkl
|
8 |
-
with open("miarbolcancer.pkl", "rb") as f:
|
9 |
-
model = pickle.load(f)
|
10 |
-
|
11 |
-
# Definir el modelo de datos con Pydantic (sin ca_cervix como entrada)
|
12 |
-
class PredictionInput(BaseModel):
|
13 |
-
behavior_sexualRisk: float
|
14 |
-
behavior_eating: float
|
15 |
-
behavior_personalHygine: float
|
16 |
-
intention_aggregation: float
|
17 |
-
intention_commitment: float
|
18 |
-
attitude_consistency: float
|
19 |
-
attitude_spontaneity: float
|
20 |
-
norm_significantPerson: float
|
21 |
-
norm_fulfillment: float
|
22 |
-
perception_vulnerability: float
|
23 |
-
perception_severity: float
|
24 |
-
motivation_strength: float
|
25 |
-
motivation_willingness: float
|
26 |
-
socialSupport_emotionality: float
|
27 |
-
socialSupport_appreciation: float
|
28 |
-
socialSupport_instrumental: float
|
29 |
-
empowerment_knowledge: float
|
30 |
-
empowerment_abilities: float
|
31 |
-
empowerment_desires: float
|
32 |
-
|
33 |
-
# Crear la aplicaci贸n FastAPI
|
34 |
-
app = FastAPI()
|
35 |
-
# CORS
|
36 |
-
app.add_middleware(
|
37 |
-
CORSMiddleware,
|
38 |
-
allow_origins=["*"],
|
39 |
-
allow_credentials=True,
|
40 |
-
allow_methods=["*"],
|
41 |
-
allow_headers=["*"],
|
42 |
-
)
|
43 |
-
# Definir el endpoint de predicci贸n
|
44 |
-
@app.post("/predict/")
|
45 |
-
def predict(input_data: PredictionInput):
|
46 |
-
# Convertir los datos de entrada en un array numpy
|
47 |
-
input_array = np.array([[input_data.behavior_sexualRisk, input_data.behavior_eating, input_data.behavior_personalHygine,
|
48 |
-
input_data.intention_aggregation, input_data.intention_commitment, input_data.attitude_consistency,
|
49 |
-
input_data.attitude_spontaneity, input_data.norm_significantPerson, input_data.norm_fulfillment,
|
50 |
-
input_data.perception_vulnerability, input_data.perception_severity, input_data.motivation_strength,
|
51 |
-
input_data.motivation_willingness, input_data.socialSupport_emotionality, input_data.socialSupport_appreciation,
|
52 |
-
input_data.socialSupport_instrumental, input_data.empowerment_knowledge, input_data.empowerment_abilities,
|
53 |
-
input_data.empowerment_desires]])
|
54 |
-
|
55 |
-
# Realizar la predicci贸n (el modelo debe predecir ca_cervix)
|
56 |
-
prediction = model.predict(input_array)
|
57 |
-
|
58 |
-
# Retornar la predicci贸n (ca_cervix)
|
59 |
-
return {"ca_cervix_prediction": prediction[0]}
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|