Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Dockerfile +15 -0
- README.md +10 -0
- app.py +62 -0
- miarbolcancer (1).pkl +3 -0
- 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"]
|
README.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Ejemplo Anibal
|
3 |
+
emoji: 馃弳
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
+
|
10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Convertir la predicci贸n a tipo nativo Python (int o float)
|
59 |
+
prediction_value = prediction[0] if isinstance(prediction[0], (int, float)) else prediction[0].item()
|
60 |
+
|
61 |
+
# Retornar la predicci贸n (ca_cervix)
|
62 |
+
return {"ca_cervix_prediction": prediction_value}
|
miarbolcancer (1).pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b7084c9be6ae3c3ed6652c7d20fc05b4eeab7930f3ec1a19f83a12f96a737d83
|
3 |
+
size 2023
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
pydantic
|
3 |
+
numpy
|
4 |
+
uvicorn
|
5 |
+
scikit-learn
|