Spaces:
Sleeping
Sleeping
yoel commited on
Commit ·
f1d86e3
1
Parent(s): fce580f
feat(utils): validar y normalizar datos estudiante
Browse files- app.py +7 -2
- evaluation.py +6 -3
- utils.py +29 -1
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
from utils import cargar_etiquetas
|
| 3 |
from dataset import cargar_datasets
|
| 4 |
from evaluation import evaluate_interface, obtener_tablas_leaderboard
|
| 5 |
|
|
@@ -11,6 +11,11 @@ test_dataloader, sr_dataloader = cargar_datasets(codigo)
|
|
| 11 |
|
| 12 |
|
| 13 |
def interface_wrapper(nombre, matricula, model_file, model_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return evaluate_interface(
|
| 15 |
nombre,
|
| 16 |
matricula,
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from utils import cargar_etiquetas, normalizar_nombre, validar_datos_estudiante
|
| 3 |
from dataset import cargar_datasets
|
| 4 |
from evaluation import evaluate_interface, obtener_tablas_leaderboard
|
| 5 |
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def interface_wrapper(nombre, matricula, model_file, model_type):
|
| 14 |
+
nombre = normalizar_nombre(nombre)
|
| 15 |
+
matricula = (matricula or "").strip()
|
| 16 |
+
error_validacion = validar_datos_estudiante(nombre, matricula)
|
| 17 |
+
if error_validacion:
|
| 18 |
+
raise gr.Error(error_validacion)
|
| 19 |
return evaluate_interface(
|
| 20 |
nombre,
|
| 21 |
matricula,
|
evaluation.py
CHANGED
|
@@ -12,8 +12,10 @@ from utils import (
|
|
| 12 |
cargar_leaderboard,
|
| 13 |
filtrar_leaderboard_por_tipo,
|
| 14 |
guardar_registro_leaderboard,
|
|
|
|
| 15 |
normalizar_tipo_modelo,
|
| 16 |
obtener_sha256,
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
|
|
@@ -134,14 +136,15 @@ def evaluate_interface(
|
|
| 134 |
test_dataloader,
|
| 135 |
sr_dataloader,
|
| 136 |
):
|
| 137 |
-
nombre = (nombre
|
| 138 |
matricula = (matricula or "").strip()
|
| 139 |
model_type = normalizar_tipo_modelo(model_type)
|
| 140 |
tabla_clasificacion, tabla_sr = obtener_tablas_leaderboard()
|
| 141 |
|
| 142 |
-
|
|
|
|
| 143 |
return (
|
| 144 |
-
|
| 145 |
"",
|
| 146 |
"",
|
| 147 |
tabla_clasificacion,
|
|
|
|
| 12 |
cargar_leaderboard,
|
| 13 |
filtrar_leaderboard_por_tipo,
|
| 14 |
guardar_registro_leaderboard,
|
| 15 |
+
normalizar_nombre,
|
| 16 |
normalizar_tipo_modelo,
|
| 17 |
obtener_sha256,
|
| 18 |
+
validar_datos_estudiante,
|
| 19 |
)
|
| 20 |
|
| 21 |
|
|
|
|
| 136 |
test_dataloader,
|
| 137 |
sr_dataloader,
|
| 138 |
):
|
| 139 |
+
nombre = normalizar_nombre(nombre)
|
| 140 |
matricula = (matricula or "").strip()
|
| 141 |
model_type = normalizar_tipo_modelo(model_type)
|
| 142 |
tabla_clasificacion, tabla_sr = obtener_tablas_leaderboard()
|
| 143 |
|
| 144 |
+
error_validacion = validar_datos_estudiante(nombre, matricula)
|
| 145 |
+
if error_validacion:
|
| 146 |
return (
|
| 147 |
+
error_validacion,
|
| 148 |
"",
|
| 149 |
"",
|
| 150 |
tabla_clasificacion,
|
utils.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
|
| 2 |
import json
|
| 3 |
import os
|
|
|
|
| 4 |
from collections import Counter
|
| 5 |
import torch
|
| 6 |
from huggingface_hub import HfApi, hf_hub_download
|
|
@@ -10,6 +11,8 @@ LEADERBOARD_DATASET_REPO = "minoruskore/top"
|
|
| 10 |
LEADERBOARD_FILENAME = "leaderboard.json"
|
| 11 |
MODEL_TYPE_CLASIFICACION = "clasificacion"
|
| 12 |
MODEL_TYPE_SR = "sr"
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def cargar_etiquetas():
|
|
@@ -57,6 +60,31 @@ def normalizar_tipo_modelo(model_type):
|
|
| 57 |
return MODEL_TYPE_CLASIFICACION
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def obtener_sha256(ruta_archivo):
|
| 61 |
sha256 = hashlib.sha256()
|
| 62 |
with open(ruta_archivo, "rb") as archivo:
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
+
import re
|
| 5 |
from collections import Counter
|
| 6 |
import torch
|
| 7 |
from huggingface_hub import HfApi, hf_hub_download
|
|
|
|
| 11 |
LEADERBOARD_FILENAME = "leaderboard.json"
|
| 12 |
MODEL_TYPE_CLASIFICACION = "clasificacion"
|
| 13 |
MODEL_TYPE_SR = "sr"
|
| 14 |
+
PATRON_MATRICULA = re.compile(r"^\d{2}-[A-Z]{4,5}-\d-\d{3}$")
|
| 15 |
+
MENSAJE_ERROR_DATOS_ESTUDIANTE = "Error: rokugogosango"
|
| 16 |
|
| 17 |
|
| 18 |
def cargar_etiquetas():
|
|
|
|
| 60 |
return MODEL_TYPE_CLASIFICACION
|
| 61 |
|
| 62 |
|
| 63 |
+
def normalizar_nombre(nombre):
|
| 64 |
+
return " ".join((nombre or "").strip().split())
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def validar_nombre_completo(nombre):
|
| 68 |
+
nombre = normalizar_nombre(nombre)
|
| 69 |
+
if len(nombre.split()) < 2:
|
| 70 |
+
return MENSAJE_ERROR_DATOS_ESTUDIANTE
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def validar_matricula(matricula):
|
| 75 |
+
matricula = (matricula or "").strip()
|
| 76 |
+
if not PATRON_MATRICULA.fullmatch(matricula):
|
| 77 |
+
return MENSAJE_ERROR_DATOS_ESTUDIANTE
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def validar_datos_estudiante(nombre, matricula):
|
| 82 |
+
error_nombre = validar_nombre_completo(nombre)
|
| 83 |
+
if error_nombre:
|
| 84 |
+
return error_nombre
|
| 85 |
+
return validar_matricula(matricula)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
def obtener_sha256(ruta_archivo):
|
| 89 |
sha256 = hashlib.sha256()
|
| 90 |
with open(ruta_archivo, "rb") as archivo:
|