Update functions.py
Browse files- functions.py +23 -27
functions.py
CHANGED
|
@@ -12,39 +12,35 @@ def cargar_modalidades_tareas():
|
|
| 12 |
|
| 13 |
# Funci贸n para actualizar el JSON desde HuggingFace y devolver tareas
|
| 14 |
def actualizar_modalidades_tareas_desde_huggingface():
|
| 15 |
-
MODALIDADES = ["text-classification", "
|
| 16 |
-
|
| 17 |
-
"image-classification", "object-detection", "image-segmentation",
|
| 18 |
-
"question-answering", "information-retrieval"]
|
| 19 |
|
| 20 |
-
modalidades_tareas = {}
|
| 21 |
for task in MODALIDADES:
|
| 22 |
-
url = f"https://huggingface.co/api/datasets?task={task}&limit=
|
| 23 |
-
response = requests.get(url)
|
| 24 |
-
datasets = response.json()
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
|
|
|
| 43 |
with open("modalidades_tareas.json", "w") as file:
|
| 44 |
-
json.dump(
|
| 45 |
|
| 46 |
-
|
| 47 |
-
return [t for datos in modalidades_tareas.values() for t in datos["tareas"].keys()]
|
| 48 |
|
| 49 |
|
| 50 |
# Cargar modalidades y tareas
|
|
|
|
| 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 |
+
url = f"https://huggingface.co/api/datasets?task={task}&full=true&limit=10"
|
| 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 datasets y columnas al JSON
|
| 27 |
+
if task not in MODALIDAD_TAREAS["NLP"]["tareas"]:
|
| 28 |
+
MODALIDAD_TAREAS["NLP"]["tareas"][task] = {
|
| 29 |
+
"nombre": "Clasificaci贸n de texto",
|
| 30 |
+
"columnas": ["text", "label"],
|
| 31 |
+
"datasets": {}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
MODALIDAD_TAREAS["NLP"]["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 indentaci贸n para evitar errores <button class="citation-flag" data-index="1">
|
| 40 |
with open("modalidades_tareas.json", "w") as file:
|
| 41 |
+
json.dump(MODALIDAD_TAREAS, file, indent=4)
|
| 42 |
|
| 43 |
+
return "Metadatos actualizados: columnas y datasets almacenados."
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
# Cargar modalidades y tareas
|