Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,35 @@
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
| 7 |
@app.get("/")
|
| 8 |
-
def
|
| 9 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
+
from fastapi import FastAPI, Request
|
| 4 |
+
import csv
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
# Configuración de logging
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
+
# Ruta raíz: mensaje de bienvenida
|
| 14 |
@app.get("/")
|
| 15 |
+
async def read_root():
|
| 16 |
+
return {"message": "GreenVision API en marcha"}
|
| 17 |
+
|
| 18 |
+
# Endpoint de feedback
|
| 19 |
+
@app.post("/feedback")
|
| 20 |
+
async def feedback(request: Request):
|
| 21 |
+
try:
|
| 22 |
+
data = await request.json()
|
| 23 |
+
file_path = "feedback_log.csv"
|
| 24 |
+
file_exists = os.path.isfile(file_path)
|
| 25 |
+
# Crear el archivo con encabezados si no existe
|
| 26 |
+
with open(file_path, "a", newline="") as csvfile:
|
| 27 |
+
writer = csv.writer(csvfile)
|
| 28 |
+
if not file_exists:
|
| 29 |
+
writer.writerow(["predicted", "correct"])
|
| 30 |
+
writer.writerow([data.get("predicted"), data.get("correct")])
|
| 31 |
+
logger.info(f"Feedback recibido: {data}")
|
| 32 |
+
return {"status": "success"}
|
| 33 |
+
except Exception as e:
|
| 34 |
+
logger.error(f"Error guardando feedback: {e}")
|
| 35 |
+
return {"status": "error", "detail": str(e)}
|