Spaces:
Sleeping
Sleeping
Download app.py from LuisTo97/GreenVisionFeedback: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/LuisTo97/GreenVisionFeedback/resolve/main/app.py
- Command line
-
hf download hf://spaces/LuisTo97/GreenVisionFeedback/app.py
-
curl -L -o app.py https://huggingface.co/spaces/LuisTo97/GreenVisionFeedback/resolve/main/app.py
1.26 kB
| # app.py | |
| from fastapi import FastAPI, Request | |
| import csv | |
| import logging | |
| import os | |
| # Configuración de logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI() | |
| if __name__ == "__main__": | |
| import uvicorn, os | |
| port = int(os.environ.get("PORT", 7860)) | |
| uvicorn.run("app:app", host="0.0.0.0", port=port, log_level="info") | |
| # Ruta raíz: mensaje de bienvenida | |
| async def read_root(): | |
| return {"message": "GreenVision API en marcha"} | |
| # Endpoint de feedback | |
| async def feedback(request: Request): | |
| try: | |
| data = await request.json() | |
| file_path = "feedback_log.csv" | |
| file_exists = os.path.isfile(file_path) | |
| # Crear el archivo con encabezados si no existe | |
| with open(file_path, "a", newline="") as csvfile: | |
| writer = csv.writer(csvfile) | |
| if not file_exists: | |
| writer.writerow(["predicted", "correct"]) | |
| writer.writerow([data.get("predicted"), data.get("correct")]) | |
| logger.info(f"Feedback recibido: {data}") | |
| return {"status": "success"} | |
| except Exception as e: | |
| logger.error(f"Error guardando feedback: {e}") | |
| return {"status": "error", "detail": str(e)} | |