Update functions.py
Browse files- functions.py +15 -15
functions.py
CHANGED
|
@@ -1,7 +1,14 @@
|
|
| 1 |
-
# functions.py
|
| 2 |
import json
|
| 3 |
import requests
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def actualizar_modalidades_tareas_desde_huggingface():
|
| 6 |
MODALIDADES = ["text-classification", "token-classification", "translation", "summarization",
|
| 7 |
"speech-recognition", "audio-classification", "music-classification",
|
|
@@ -10,11 +17,10 @@ def actualizar_modalidades_tareas_desde_huggingface():
|
|
| 10 |
|
| 11 |
modalidades_tareas = {}
|
| 12 |
for task in MODALIDADES:
|
| 13 |
-
url = f"https://huggingface.co/api/datasets?task={task}&limit=5"
|
| 14 |
response = requests.get(url)
|
| 15 |
datasets = response.json()
|
| 16 |
|
| 17 |
-
# Extraer columnas comunes de los datasets
|
| 18 |
columnas = set()
|
| 19 |
for dataset in datasets:
|
| 20 |
try:
|
|
@@ -23,26 +29,20 @@ def actualizar_modalidades_tareas_desde_huggingface():
|
|
| 23 |
except:
|
| 24 |
continue
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
modalidad = "Audio"
|
| 31 |
-
elif task in ["image-classification", "object-detection", "image-segmentation"]:
|
| 32 |
-
modalidad = "Vision"
|
| 33 |
-
elif task in ["question-answering", "information-retrieval"]:
|
| 34 |
-
modalidad = "RAG"
|
| 35 |
|
| 36 |
-
# A帽adir al diccionario
|
| 37 |
if modalidad not in modalidades_tareas:
|
| 38 |
modalidades_tareas[modalidad] = {"tareas": {}, "columnas_generales": []}
|
| 39 |
modalidades_tareas[modalidad]["tareas"][task] = list(columnas)
|
| 40 |
|
| 41 |
-
# Guardar JSON
|
| 42 |
with open("modalidades_tareas.json", "w") as file:
|
| 43 |
json.dump(modalidades_tareas, file, indent=4)
|
| 44 |
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
# Cargar modalidades y tareas
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import requests
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
|
| 5 |
+
# Cargar modalidades y tareas (ahora devuelve una lista de tareas) <button class="citation-flag" data-index="1">
|
| 6 |
+
def cargar_modalidades_tareas():
|
| 7 |
+
with open("modalidades_tareas.json", "r") as file:
|
| 8 |
+
MODALIDAD_TAREAS = json.load(file)
|
| 9 |
+
return MODALIDAD_TAREAS
|
| 10 |
+
|
| 11 |
+
# Funci贸n para actualizar el JSON desde HuggingFace y devolver tareas
|
| 12 |
def actualizar_modalidades_tareas_desde_huggingface():
|
| 13 |
MODALIDADES = ["text-classification", "token-classification", "translation", "summarization",
|
| 14 |
"speech-recognition", "audio-classification", "music-classification",
|
|
|
|
| 17 |
|
| 18 |
modalidades_tareas = {}
|
| 19 |
for task in MODALIDADES:
|
| 20 |
+
url = f"https://huggingface.co/api/datasets?task={task}&limit=5"
|
| 21 |
response = requests.get(url)
|
| 22 |
datasets = response.json()
|
| 23 |
|
|
|
|
| 24 |
columnas = set()
|
| 25 |
for dataset in datasets:
|
| 26 |
try:
|
|
|
|
| 29 |
except:
|
| 30 |
continue
|
| 31 |
|
| 32 |
+
modalidad = "NLP" if task in ["text-classification", "token-classification", "translation", "summarization"] else \
|
| 33 |
+
"Audio" if task in ["speech-recognition", "audio-classification", "music-classification"] else \
|
| 34 |
+
"Vision" if task in ["image-classification", "object-detection", "image-segmentation"] else \
|
| 35 |
+
"RAG"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
| 37 |
if modalidad not in modalidades_tareas:
|
| 38 |
modalidades_tareas[modalidad] = {"tareas": {}, "columnas_generales": []}
|
| 39 |
modalidades_tareas[modalidad]["tareas"][task] = list(columnas)
|
| 40 |
|
|
|
|
| 41 |
with open("modalidades_tareas.json", "w") as file:
|
| 42 |
json.dump(modalidades_tareas, file, indent=4)
|
| 43 |
|
| 44 |
+
# Devolver lista de tareas actualizada
|
| 45 |
+
return [t for datos in modalidades_tareas.values() for t in datos["tareas"].keys()]
|
| 46 |
|
| 47 |
|
| 48 |
# Cargar modalidades y tareas
|