Update functions.py
Browse files- functions.py +14 -21
functions.py
CHANGED
|
@@ -6,48 +6,41 @@ from datasets import load_dataset
|
|
| 6 |
|
| 7 |
# Cargar modalidades y tareas (ahora devuelve una lista de tareas) <button class="citation-flag" data-index="1">
|
| 8 |
def cargar_modalidades_tareas():
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Funci贸n para actualizar el JSON desde HuggingFace y devolver tareas
|
| 14 |
def actualizar_modalidades_tareas_desde_huggingface():
|
| 15 |
MODALIDADES = ["text-classification", "image-classification", "speech-recognition"]
|
| 16 |
MODALIDAD_TAREAS = cargar_modalidades_tareas() # Cargar JSON existente
|
| 17 |
|
| 18 |
for task in MODALIDADES:
|
| 19 |
-
|
| 20 |
-
response = requests.get(url).json()
|
| 21 |
|
| 22 |
for dataset in response:
|
| 23 |
dataset_id = dataset["id"]
|
| 24 |
dataset_info = requests.get(f"https://huggingface.co/api/datasets/{dataset_id}").json()
|
| 25 |
|
| 26 |
-
# A帽adir
|
| 27 |
-
if task not in MODALIDAD_TAREAS
|
| 28 |
-
MODALIDAD_TAREAS[
|
| 29 |
-
"nombre": "
|
| 30 |
-
"columnas":
|
| 31 |
"datasets": {}
|
| 32 |
}
|
| 33 |
|
| 34 |
-
MODALIDAD_TAREAS[
|
| 35 |
"columnas": list(dataset_info.get("features", {}).keys()),
|
| 36 |
"licencia": dataset.get("license", "unknown")
|
| 37 |
}
|
| 38 |
|
| 39 |
-
# Guardar JSON con
|
| 40 |
with open("modalidades_tareas.json", "w") as file:
|
| 41 |
json.dump(MODALIDAD_TAREAS, file, indent=4)
|
| 42 |
|
| 43 |
-
return
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# Cargar modalidades y tareas
|
| 47 |
-
def cargar_modalidades_tareas():
|
| 48 |
-
with open("modalidades_tareas.json", "r") as file:
|
| 49 |
-
MODALIDAD_TAREAS = json.load(file)
|
| 50 |
-
return MODALIDAD_TAREAS
|
| 51 |
|
| 52 |
# Generar gr谩fica de barras
|
| 53 |
def generar_grafica_barras(tareas_seleccionadas, MODALIDAD_TAREAS):
|
|
|
|
| 6 |
|
| 7 |
# Cargar modalidades y tareas (ahora devuelve una lista de tareas) <button class="citation-flag" data-index="1">
|
| 8 |
def cargar_modalidades_tareas():
|
| 9 |
+
try:
|
| 10 |
+
with open("modalidades_tareas.json", "r") as file:
|
| 11 |
+
return json.load(file)
|
| 12 |
+
except FileNotFoundError:
|
| 13 |
+
return {} # Devolver diccionario vac铆o si no existe
|
| 14 |
|
|
|
|
| 15 |
def actualizar_modalidades_tareas_desde_huggingface():
|
| 16 |
MODALIDADES = ["text-classification", "image-classification", "speech-recognition"]
|
| 17 |
MODALIDAD_TAREAS = cargar_modalidades_tareas() # Cargar JSON existente
|
| 18 |
|
| 19 |
for task in MODALIDADES:
|
| 20 |
+
response = requests.get(f"https://huggingface.co/api/datasets?task={task}&full=true&limit=5").json()
|
|
|
|
| 21 |
|
| 22 |
for dataset in response:
|
| 23 |
dataset_id = dataset["id"]
|
| 24 |
dataset_info = requests.get(f"https://huggingface.co/api/datasets/{dataset_id}").json()
|
| 25 |
|
| 26 |
+
# A帽adir datos al JSON
|
| 27 |
+
if task not in MODALIDAD_TAREAS:
|
| 28 |
+
MODALIDAD_TAREAS[task] = {
|
| 29 |
+
"nombre": task.replace("-", " ").capitalize(),
|
| 30 |
+
"columnas": list(dataset_info.get("features", {}).keys()),
|
| 31 |
"datasets": {}
|
| 32 |
}
|
| 33 |
|
| 34 |
+
MODALIDAD_TAREAS[task]["datasets"][dataset_id] = {
|
| 35 |
"columnas": list(dataset_info.get("features", {}).keys()),
|
| 36 |
"licencia": dataset.get("license", "unknown")
|
| 37 |
}
|
| 38 |
|
| 39 |
+
# Guardar JSON con permisos expl铆citos <button class="citation-flag" data-index="2">
|
| 40 |
with open("modalidades_tareas.json", "w") as file:
|
| 41 |
json.dump(MODALIDAD_TAREAS, file, indent=4)
|
| 42 |
|
| 43 |
+
return list(MODALIDAD_TAREAS.keys()) # Devolver lista de tareas actualizadas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Generar gr谩fica de barras
|
| 46 |
def generar_grafica_barras(tareas_seleccionadas, MODALIDAD_TAREAS):
|