Update functions.py
Browse files- functions.py +12 -7
functions.py
CHANGED
|
@@ -99,11 +99,14 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 99 |
|
| 100 |
# Validar API Key
|
| 101 |
if not api_key:
|
| 102 |
-
raise ValueError("
|
| 103 |
|
| 104 |
-
# Usar un modelo compatible
|
| 105 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 106 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# Construir el prompt
|
| 109 |
prompt = (
|
|
@@ -114,7 +117,7 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 114 |
|
| 115 |
# Enviar solicitud a la API
|
| 116 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 117 |
-
response.raise_for_status() #
|
| 118 |
|
| 119 |
# Procesar respuesta
|
| 120 |
if response.status_code == 200:
|
|
@@ -125,9 +128,11 @@ def generar_encabezado_inteligente(tareas_seleccionadas, api_key):
|
|
| 125 |
|
| 126 |
except requests.exceptions.HTTPError as e:
|
| 127 |
if e.response.status_code == 401:
|
| 128 |
-
raise ValueError("API Key inválida o sin permisos. Verifica tu clave en HuggingFace.")
|
|
|
|
|
|
|
| 129 |
elif e.response.status_code == 404:
|
| 130 |
-
raise ValueError("El modelo no existe en HuggingFace.
|
| 131 |
else:
|
| 132 |
raise ValueError(f"Error HTTP: {str(e)}")
|
| 133 |
except Exception as e:
|
|
|
|
| 99 |
|
| 100 |
# Validar API Key
|
| 101 |
if not api_key:
|
| 102 |
+
raise ValueError("API Key no proporcionada. Ingresa una clave válida.")
|
| 103 |
|
| 104 |
+
# Usar un modelo público compatible (ej. gpt2 o flan-t5-base)
|
| 105 |
+
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base" # Modelo alternativo <button class="citation-flag" data-index="2">
|
| 106 |
+
headers = {
|
| 107 |
+
"Authorization": f"Bearer {api_key}",
|
| 108 |
+
"Content-Type": "application/json"
|
| 109 |
+
}
|
| 110 |
|
| 111 |
# Construir el prompt
|
| 112 |
prompt = (
|
|
|
|
| 117 |
|
| 118 |
# Enviar solicitud a la API
|
| 119 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 120 |
+
response.raise_for_status() # Lanza error si hay un problema HTTP
|
| 121 |
|
| 122 |
# Procesar respuesta
|
| 123 |
if response.status_code == 200:
|
|
|
|
| 128 |
|
| 129 |
except requests.exceptions.HTTPError as e:
|
| 130 |
if e.response.status_code == 401:
|
| 131 |
+
raise ValueError("API Key inválida o sin permisos. Verifica tu clave en HuggingFace.") <button class="citation-flag" data-index="1">
|
| 132 |
+
elif e.response.status_code == 403:
|
| 133 |
+
raise ValueError("Acceso denegado al modelo. Prueba con otro modelo público como 'google/flan-t5-base'.") <button class="citation-flag" data-index="2">
|
| 134 |
elif e.response.status_code == 404:
|
| 135 |
+
raise ValueError("El modelo no existe en HuggingFace. Asegúrate de usar un modelo válido.")
|
| 136 |
else:
|
| 137 |
raise ValueError(f"Error HTTP: {str(e)}")
|
| 138 |
except Exception as e:
|