Spaces:
Sleeping
Sleeping
Adzacam commited on
Commit ·
181549f
1
Parent(s): d923814
Release: Frontend operativo con SheetJS y Axios hacia Hugging Face
Browse files
.env
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Direct PostgreSQL Database Connection String for SQLAlchemy
|
| 3 |
+
DATABASE_URL=postgresql://postgres:Daza20Gira26TecnologiasEmergentesII@db.rxfsdhgxcmtoyinjekok.supabase.co:5432/postgres
|
main.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
import datetime
|
| 2 |
-
import logging
|
| 3 |
-
from typing import List
|
| 4 |
-
from fastapi import FastAPI, Depends, HTTPException, status
|
| 5 |
-
from pydantic import BaseModel
|
| 6 |
-
from sqlalchemy.orm import Session
|
| 7 |
-
from database import get_db, DimEstudiante, FactRendimientoAcademico, engine
|
| 8 |
-
from ner_engine import ner_engine
|
| 9 |
-
|
| 10 |
-
logging.basicConfig(level=logging.INFO)
|
| 11 |
-
logger = logging.getLogger(__name__)
|
| 12 |
-
|
| 13 |
-
app = FastAPI(
|
| 14 |
-
title="GiraGroup BI Backend Cloud",
|
| 15 |
-
description="API para Tecnologías Emergentes II con BETO y Supabase",
|
| 16 |
-
version="1.0.0"
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
class ProcessSheetPayload(BaseModel):
|
| 20 |
-
texto_celda: str
|
| 21 |
-
nota_detectada: float
|
| 22 |
-
asistencia: float
|
| 23 |
-
incumplimiento_tareas: float
|
| 24 |
-
id_docente: int
|
| 25 |
-
id_modulo: int
|
| 26 |
-
id_tiempo: int
|
| 27 |
-
id_documento: int
|
| 28 |
-
id_usuario: int
|
| 29 |
-
|
| 30 |
-
@app.get("/")
|
| 31 |
-
def read_root():
|
| 32 |
-
return {
|
| 33 |
-
"status": "healthy",
|
| 34 |
-
"service": "GiraGroup BI Backend API Cloud",
|
| 35 |
-
"ner_initialized": ner_engine._initialized or ner_engine.pipeline is not None
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
@app.post("/api/v1/ingesta/tabular", status_code=status.HTTP_201_CREATED)
|
| 39 |
-
def procesar_registro_tabular(payload: ProcessSheetPayload, db: Session = Depends(get_db)):
|
| 40 |
-
entidades = ner_engine.extract_entities(payload.texto_celda)
|
| 41 |
-
confianza_ia = sum([e["score"] for e in entidades]) / len(entidades) if entidades else 1.0
|
| 42 |
-
|
| 43 |
-
forzar_revision = False
|
| 44 |
-
if confianza_ia < 0.60:
|
| 45 |
-
forzar_revision = True
|
| 46 |
-
|
| 47 |
-
nombre_resuelto = payload.texto_celda.strip()
|
| 48 |
-
estudiante = db.query(DimEstudiante).filter(DimEstudiante.nombre_completo == nombre_resuelto).first()
|
| 49 |
-
|
| 50 |
-
if not estudiante:
|
| 51 |
-
estudiante = DimEstudiante(nombre_completo=nombre_resuelto)
|
| 52 |
-
db.add(estudiante)
|
| 53 |
-
db.commit()
|
| 54 |
-
db.refresh(estudiante)
|
| 55 |
-
|
| 56 |
-
alertas_disparadas = []
|
| 57 |
-
if payload.nota_detectada <= 70.0:
|
| 58 |
-
alertas_disparadas.append("RIESGO_ACADEMICO_CRITICO")
|
| 59 |
-
if payload.asistencia < 70.0 or payload.incumplimiento_tareas > 30.0:
|
| 60 |
-
alertas_disparadas.append("RIESGO_DESERCION_ALTA")
|
| 61 |
-
|
| 62 |
-
try:
|
| 63 |
-
nuevo_hecho = FactRendimientoAcademico(
|
| 64 |
-
id_estudiante=estudiante.id_estudiante,
|
| 65 |
-
id_docente=payload.id_docente,
|
| 66 |
-
id_modulo=payload.id_modulo,
|
| 67 |
-
id_tiempo=payload.id_tiempo,
|
| 68 |
-
id_documento=payload.id_documento,
|
| 69 |
-
id_usuario_carga=payload.id_usuario,
|
| 70 |
-
nota_final=payload.nota_detectada,
|
| 71 |
-
asistencia_pct=payload.asistencia,
|
| 72 |
-
incumplimiento_actividades_pct=payload.incumplimiento_tareas,
|
| 73 |
-
nivel_confianza_ia=confianza_ia,
|
| 74 |
-
requiere_revision=forzar_revision
|
| 75 |
-
)
|
| 76 |
-
db.add(nuevo_hecho)
|
| 77 |
-
db.commit()
|
| 78 |
-
|
| 79 |
-
return {
|
| 80 |
-
"status": "processed",
|
| 81 |
-
"id_estudiante_asignado": estudiante.id_estudiante,
|
| 82 |
-
"confianza_modelo_beto": round(confianza_ia, 4),
|
| 83 |
-
"requiere_auditoria_humana": forzar_revision,
|
| 84 |
-
"alertas_estrategicas": alertas_disparadas
|
| 85 |
-
}
|
| 86 |
-
except Exception as err:
|
| 87 |
-
db.rollback()
|
| 88 |
-
logger.error(f"Fallo en persistencia: {err}")
|
| 89 |
-
raise HTTPException(status_code=500, detail="Error al escribir en Supabase.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|