Spaces:
Runtime error
Runtime error
Maicol2001
commited on
Commit
•
d1472d7
1
Parent(s):
7a1a4cc
Upload 3 files
Browse files- Dockerfile +16 -0
- app.py +28 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Usa una imagen base de Python
|
2 |
+
FROM python:3.11.6
|
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 |
+
RUN pip install fastapi uvicorn
|
10 |
+
|
11 |
+
COPY . .
|
12 |
+
|
13 |
+
RUN chmod -R 777 /code
|
14 |
+
|
15 |
+
# Comando para ejecutar la aplicación
|
16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
class InputData(BaseModel):
|
6 |
+
data: List[float] # Lista de características numéricas (flotantes)
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
def sumar(a,b):
|
11 |
+
return a+b
|
12 |
+
|
13 |
+
# Ruta de predicción
|
14 |
+
@app.post("/predict/")
|
15 |
+
async def predict(data: InputData):
|
16 |
+
print(f"Data: {data}")
|
17 |
+
try:
|
18 |
+
# Convertir la lista de entrada a un array de NumPy para la predicción
|
19 |
+
input_data = data.data
|
20 |
+
print(input_data)
|
21 |
+
a = input_data[0]
|
22 |
+
b = input_data[1]
|
23 |
+
c = sumar(a,b)
|
24 |
+
prediction = c
|
25 |
+
#return {"prediction": prediction.tolist()}
|
26 |
+
return {"prediction": prediction}
|
27 |
+
except Exception as e:
|
28 |
+
raise HTTPException(status_code=500, detail=str(e))
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
numpy
|
3 |
+
pydantic
|