Update functions.py
Browse files- functions.py +8 -7
functions.py
CHANGED
|
@@ -3,6 +3,7 @@ import json
|
|
| 3 |
import requests
|
| 4 |
from datasets import load_dataset
|
| 5 |
import matplotlib.pyplot as plt
|
|
|
|
| 6 |
|
| 7 |
# Funci贸n para cargar modalidades y tareas
|
| 8 |
def cargar_modalidades_tareas():
|
|
@@ -93,8 +94,8 @@ def generar_dataset(encabezado, datasets_seleccionados, pagina_actual=1, filas_p
|
|
| 93 |
|
| 94 |
# Funci贸n inteligente para generar el encabezado usando IA de HuggingFace
|
| 95 |
def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
| 96 |
-
max_reintentos = 3
|
| 97 |
-
espera_entre_reintentos = 2
|
| 98 |
|
| 99 |
for intento in range(max_reintentos + 1):
|
| 100 |
try:
|
|
@@ -117,8 +118,8 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 117 |
- Separa las columnas con comas.
|
| 118 |
"""
|
| 119 |
|
| 120 |
-
# Usar un modelo
|
| 121 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 122 |
headers = {
|
| 123 |
"Authorization": f"Bearer {api_key}",
|
| 124 |
"Content-Type": "application/json"
|
|
@@ -130,7 +131,7 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 130 |
headers=headers,
|
| 131 |
json={
|
| 132 |
"inputs": prompt,
|
| 133 |
-
"parameters": {"max_length": 128, "temperature": 0.1}
|
| 134 |
}
|
| 135 |
)
|
| 136 |
response.raise_for_status()
|
|
@@ -149,7 +150,7 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 149 |
|
| 150 |
except requests.exceptions.HTTPError as e:
|
| 151 |
if e.response.status_code == 503 and intento < max_reintentos:
|
| 152 |
-
time.sleep(espera_entre_reintentos)
|
| 153 |
continue
|
| 154 |
elif e.response.status_code == 401:
|
| 155 |
raise ValueError("API Key inv谩lida o sin permisos.")
|
|
@@ -159,7 +160,7 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 159 |
except Exception as e:
|
| 160 |
raise ValueError(f"Error inesperado: {str(e)}")
|
| 161 |
|
| 162 |
-
#
|
| 163 |
return generar_encabezado_local(tareas_seleccionadas)
|
| 164 |
|
| 165 |
# Fallback local en caso de fallo de la API
|
|
|
|
| 3 |
import requests
|
| 4 |
from datasets import load_dataset
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
# Funci贸n para cargar modalidades y tareas
|
| 9 |
def cargar_modalidades_tareas():
|
|
|
|
| 94 |
|
| 95 |
# Funci贸n inteligente para generar el encabezado usando IA de HuggingFace
|
| 96 |
def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
| 97 |
+
max_reintentos = 3
|
| 98 |
+
espera_entre_reintentos = 2
|
| 99 |
|
| 100 |
for intento in range(max_reintentos + 1):
|
| 101 |
try:
|
|
|
|
| 118 |
- Separa las columnas con comas.
|
| 119 |
"""
|
| 120 |
|
| 121 |
+
# Usar un modelo alternativo (distilgpt2) <button class="citation-flag" data-index="2">
|
| 122 |
+
API_URL = "https://api-inference.huggingface.co/models/distilgpt2"
|
| 123 |
headers = {
|
| 124 |
"Authorization": f"Bearer {api_key}",
|
| 125 |
"Content-Type": "application/json"
|
|
|
|
| 131 |
headers=headers,
|
| 132 |
json={
|
| 133 |
"inputs": prompt,
|
| 134 |
+
"parameters": {"max_length": 128, "temperature": 0.1}
|
| 135 |
}
|
| 136 |
)
|
| 137 |
response.raise_for_status()
|
|
|
|
| 150 |
|
| 151 |
except requests.exceptions.HTTPError as e:
|
| 152 |
if e.response.status_code == 503 and intento < max_reintentos:
|
| 153 |
+
time.sleep(espera_entre_reintentos)
|
| 154 |
continue
|
| 155 |
elif e.response.status_code == 401:
|
| 156 |
raise ValueError("API Key inv谩lida o sin permisos.")
|
|
|
|
| 160 |
except Exception as e:
|
| 161 |
raise ValueError(f"Error inesperado: {str(e)}")
|
| 162 |
|
| 163 |
+
# Fallback local si fallan todos los reintentos
|
| 164 |
return generar_encabezado_local(tareas_seleccionadas)
|
| 165 |
|
| 166 |
# Fallback local en caso de fallo de la API
|