Mahynlo
commited on
Commit
·
82c91df
1
Parent(s):
c3633a1
Final Version
Browse files- CLEANUP_OBSOLETE_FILES.md +0 -66
- CORRECCIONES_APLICADAS.md +0 -243
- DEPLOY.md +0 -179
- DEPLOY_QUICKSTART.md +205 -89
- DIAGNOSTIC_REPORT.md +0 -210
- RATE_LIMIT_FIX.md +0 -74
- READY_TO_DEPLOY.md +0 -52
- RESUMEN_FINAL.md +0 -229
- RESUMEN_IMPLEMENTACION.md +255 -188
CLEANUP_OBSOLETE_FILES.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
# 🧹 Script de Limpieza de Archivos Obsoletos
|
| 2 |
-
|
| 3 |
-
Este script PowerShell elimina archivos obsoletos del proyecto que usan OpenAI en vez de Gemini.
|
| 4 |
-
|
| 5 |
-
## ⚠️ Archivos a eliminar
|
| 6 |
-
|
| 7 |
-
1. **agent.py** (raíz del proyecto)
|
| 8 |
-
- Usa `from openai import OpenAI`
|
| 9 |
-
- Reemplazado por `agents.py` que usa Gemini
|
| 10 |
-
|
| 11 |
-
2. **tools/describe_image_tool.py**
|
| 12 |
-
- Usa OpenAI GPT-4 Vision
|
| 13 |
-
- Reemplazado por `vision_tool` en `tools/tools.py` que usa Gemini
|
| 14 |
-
|
| 15 |
-
3. **tools/openai_speech_to_text_tool.py**
|
| 16 |
-
- Nombre sugiere uso de OpenAI
|
| 17 |
-
- Reemplazado por `audio_to_text` en `tools/tools.py` que usa Whisper local
|
| 18 |
-
|
| 19 |
-
4. **tools/youtube_transcription_tool.py** (OPCIONAL)
|
| 20 |
-
- Implementación class-based redundante
|
| 21 |
-
- Reemplazado por `transcribe_youtube` en `tools/tools.py`
|
| 22 |
-
|
| 23 |
-
## 🔧 Comandos PowerShell
|
| 24 |
-
|
| 25 |
-
```powershell
|
| 26 |
-
# Navegar al directorio del proyecto
|
| 27 |
-
cd "d:\Documentos\Topicos_avanzados_de_IA\Agents_Curse\hf-gaia-agents-course-MN"
|
| 28 |
-
|
| 29 |
-
# Eliminar archivos obsoletos
|
| 30 |
-
Remove-Item -Path "agent.py" -Force
|
| 31 |
-
Remove-Item -Path "tools\describe_image_tool.py" -Force
|
| 32 |
-
Remove-Item -Path "tools\openai_speech_to_text_tool.py" -Force
|
| 33 |
-
|
| 34 |
-
# OPCIONAL: Eliminar tool redundante de YouTube
|
| 35 |
-
# Remove-Item -Path "tools\youtube_transcription_tool.py" -Force
|
| 36 |
-
|
| 37 |
-
# Verificar que se eliminaron
|
| 38 |
-
Write-Host "✅ Archivos obsoletos eliminados" -ForegroundColor Green
|
| 39 |
-
```
|
| 40 |
-
|
| 41 |
-
## 📝 Verificación
|
| 42 |
-
|
| 43 |
-
Después de ejecutar, verificar que no haya referencias a estos archivos:
|
| 44 |
-
|
| 45 |
-
```powershell
|
| 46 |
-
# Buscar referencias a 'agent.py' (singular)
|
| 47 |
-
Select-String -Path "*.py" -Pattern "from agent import|import agent" -Exclude "test_*.py","agent.py","agents.py"
|
| 48 |
-
|
| 49 |
-
# Buscar referencias a OpenAI
|
| 50 |
-
Select-String -Path "*.py" -Pattern "from openai import|import openai" -CaseSensitive
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
Si encuentra referencias, eliminarlas manualmente.
|
| 54 |
-
|
| 55 |
-
## ✅ Resultado esperado
|
| 56 |
-
|
| 57 |
-
Después de la limpieza, el proyecto solo debe tener:
|
| 58 |
-
- ✅ `agents.py` (usa Gemini via LiteLLM)
|
| 59 |
-
- ✅ `tools/tools.py` (todas las tools con Gemini/Whisper)
|
| 60 |
-
- ✅ `tool.py` (registro de tools)
|
| 61 |
-
- ❌ NO `agent.py`
|
| 62 |
-
- ❌ NO tools que usen OpenAI
|
| 63 |
-
|
| 64 |
-
---
|
| 65 |
-
|
| 66 |
-
**Generado automáticamente - Revisa antes de ejecutar**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRECCIONES_APLICADAS.md
DELETED
|
@@ -1,243 +0,0 @@
|
|
| 1 |
-
# ✅ RESUMEN DE CORRECCIONES APLICADAS
|
| 2 |
-
|
| 3 |
-
**Fecha**: 19 de Octubre, 2025
|
| 4 |
-
**Proyecto**: GAIA Agent - Curso HuggingFace Unit 4
|
| 5 |
-
**Estado**: ✅ LISTO PARA DEPLOY (con 1 acción pendiente del usuario)
|
| 6 |
-
|
| 7 |
-
---
|
| 8 |
-
|
| 9 |
-
## 🎯 CORRECCIONES APLICADAS AUTOMÁTICAMENTE
|
| 10 |
-
|
| 11 |
-
### 1. ✅ Variable de Entorno Unificada
|
| 12 |
-
**Archivos modificados**:
|
| 13 |
-
- `model.py` - Cambiado `GEMINI_API` → `GEMINI_API_KEY`
|
| 14 |
-
- `tools/tools.py` - Cambiado `GEMINI_API` → `GEMINI_API_KEY` (2 ocurrencias)
|
| 15 |
-
|
| 16 |
-
**Resultado**: Consistencia total en el nombre del secret
|
| 17 |
-
|
| 18 |
-
---
|
| 19 |
-
|
| 20 |
-
### 2. ✅ Dependencies Agregadas a requirements.txt
|
| 21 |
-
**Nuevas dependencias**:
|
| 22 |
-
```
|
| 23 |
-
smolagents>=0.1.0
|
| 24 |
-
yt-dlp>=2023.12.12
|
| 25 |
-
openai-whisper>=20230314
|
| 26 |
-
imageio>=2.31.1
|
| 27 |
-
imageio-ffmpeg>=0.4.8
|
| 28 |
-
ffmpeg-python>=0.2.0
|
| 29 |
-
numpy>=1.24.0
|
| 30 |
-
youtube-transcript-api>=3.0.0
|
| 31 |
-
```
|
| 32 |
-
|
| 33 |
-
**Resultado**: Todas las librerías necesarias están declaradas
|
| 34 |
-
|
| 35 |
-
---
|
| 36 |
-
|
| 37 |
-
### 3. ✅ app.py Corregido
|
| 38 |
-
|
| 39 |
-
#### 3.1 Pasaje de archivos al agent
|
| 40 |
-
**Antes**:
|
| 41 |
-
```python
|
| 42 |
-
answer = agent(question) # ❌ No pasa archivos
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
**Después**:
|
| 46 |
-
```python
|
| 47 |
-
files = [file_name] if file_name else None
|
| 48 |
-
answer = agent(question, files=files) # ✅ Pasa archivos
|
| 49 |
-
```
|
| 50 |
-
|
| 51 |
-
#### 3.2 Límite de 2 preguntas eliminado
|
| 52 |
-
**Antes**:
|
| 53 |
-
```python
|
| 54 |
-
questions_data = questions_data[:2] # ❌ Solo evalúa 2
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
**Después**:
|
| 58 |
-
```python
|
| 59 |
-
# Process ALL questions (removed [:2] limit) # ✅ Evalúa todas
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
**Resultado**: App procesa correctamente preguntas con archivos y sin límites artificiales
|
| 63 |
-
|
| 64 |
-
---
|
| 65 |
-
|
| 66 |
-
### 4. ✅ test_agent.py Recreado
|
| 67 |
-
|
| 68 |
-
**Contenido**: Suite completa de tests con 5 validaciones:
|
| 69 |
-
1. ✅ Imports (smolagents, litellm, google-generativeai, etc.)
|
| 70 |
-
2. ✅ Tools (carga y lista todas las herramientas)
|
| 71 |
-
3. ✅ Environment (verifica GEMINI_API_KEY)
|
| 72 |
-
4. ✅ Model (instancia y prueba inferencia)
|
| 73 |
-
5. ✅ Agent (crea agent y responde pregunta simple)
|
| 74 |
-
|
| 75 |
-
**Resultado**: Herramienta completa de validación pre-deploy
|
| 76 |
-
|
| 77 |
-
---
|
| 78 |
-
|
| 79 |
-
### 5. ✅ tools/__init__.py Creado
|
| 80 |
-
|
| 81 |
-
**Contenido**: Exports de todos los tools para facilitar imports
|
| 82 |
-
|
| 83 |
-
**Resultado**: Mejor estructura de paquete Python
|
| 84 |
-
|
| 85 |
-
---
|
| 86 |
-
|
| 87 |
-
### 6. ✅ Documentación Creada
|
| 88 |
-
|
| 89 |
-
**Nuevos archivos**:
|
| 90 |
-
1. `DIAGNOSTIC_REPORT.md` - Reporte completo de diagnóstico (12 issues identificados)
|
| 91 |
-
2. `CLEANUP_OBSOLETE_FILES.md` - Guía para eliminar archivos obsoletos
|
| 92 |
-
3. `DEPLOY_QUICKSTART.md` - Guía rápida de deploy a HF Spaces
|
| 93 |
-
|
| 94 |
-
**Resultado**: Documentación completa para próximos pasos
|
| 95 |
-
|
| 96 |
-
---
|
| 97 |
-
|
| 98 |
-
## ⚠️ ACCIONES PENDIENTES (USUARIO)
|
| 99 |
-
|
| 100 |
-
### 1. 🔴 CRÍTICO: Configurar GEMINI_API_KEY en HF Spaces
|
| 101 |
-
|
| 102 |
-
**Pasos**:
|
| 103 |
-
1. Ir a: https://huggingface.co/spaces/[TU_SPACE]/settings
|
| 104 |
-
2. Scroll a "Repository secrets"
|
| 105 |
-
3. Click "Add a secret"
|
| 106 |
-
4. Name: `GEMINI_API_KEY` (exacto)
|
| 107 |
-
5. Value: Tu API key de Gemini
|
| 108 |
-
6. Click "Add"
|
| 109 |
-
|
| 110 |
-
**Sin esto, el agent NO funcionará**
|
| 111 |
-
|
| 112 |
-
---
|
| 113 |
-
|
| 114 |
-
### 2. 🟡 IMPORTANTE: Eliminar Archivos Obsoletos
|
| 115 |
-
|
| 116 |
-
**Archivos a eliminar**:
|
| 117 |
-
- `agent.py` (raíz) - Usa OpenAI
|
| 118 |
-
- `tools/describe_image_tool.py` - Usa OpenAI GPT-4 Vision
|
| 119 |
-
- `tools/openai_speech_to_text_tool.py` - Nombre sugiere OpenAI
|
| 120 |
-
|
| 121 |
-
**Comando PowerShell**:
|
| 122 |
-
```powershell
|
| 123 |
-
Remove-Item "agent.py", "tools\describe_image_tool.py", "tools\openai_speech_to_text_tool.py" -Force
|
| 124 |
-
```
|
| 125 |
-
|
| 126 |
-
**Ver detalles en**: `CLEANUP_OBSOLETE_FILES.md`
|
| 127 |
-
|
| 128 |
-
---
|
| 129 |
-
|
| 130 |
-
### 3. 🟢 OPCIONAL: Instalar y Probar Localmente
|
| 131 |
-
|
| 132 |
-
```powershell
|
| 133 |
-
# Instalar dependencias
|
| 134 |
-
pip install -r requirements.txt
|
| 135 |
-
|
| 136 |
-
# Configurar API key
|
| 137 |
-
$env:GEMINI_API_KEY = "tu_key_aqui"
|
| 138 |
-
|
| 139 |
-
# Ejecutar tests
|
| 140 |
-
python test_agent.py
|
| 141 |
-
```
|
| 142 |
-
|
| 143 |
-
---
|
| 144 |
-
|
| 145 |
-
## 📊 ESTADO ACTUAL
|
| 146 |
-
|
| 147 |
-
| Categoría | Total | Resueltos | Pendientes |
|
| 148 |
-
|-----------|-------|-----------|------------|
|
| 149 |
-
| 🔴 Críticos | 3 | 2 | 1 |
|
| 150 |
-
| 🟡 Importantes | 6 | 4 | 2 |
|
| 151 |
-
| 🟢 Menores | 3 | 2 | 1 |
|
| 152 |
-
| **TOTAL** | **12** | **8** | **4** |
|
| 153 |
-
|
| 154 |
-
**Progreso**: 66.7% completado ✅
|
| 155 |
-
|
| 156 |
-
---
|
| 157 |
-
|
| 158 |
-
## 🚀 PRÓXIMOS PASOS
|
| 159 |
-
|
| 160 |
-
### Opción A: Deploy Rápido (5 minutos)
|
| 161 |
-
1. Configurar `GEMINI_API_KEY` en HF Spaces
|
| 162 |
-
2. Push cambios: `git add . && git commit -m "Fix" && git push`
|
| 163 |
-
3. Monitorear logs del build
|
| 164 |
-
4. Ejecutar evaluación
|
| 165 |
-
|
| 166 |
-
### Opción B: Deploy Seguro (15 minutos)
|
| 167 |
-
1. Eliminar archivos obsoletos (ver `CLEANUP_OBSOLETE_FILES.md`)
|
| 168 |
-
2. Instalar deps localmente: `pip install -r requirements.txt`
|
| 169 |
-
3. Probar localmente: `python test_agent.py`
|
| 170 |
-
4. Si tests pasan → seguir Opción A
|
| 171 |
-
|
| 172 |
-
**Recomendado**: Opción B para máxima confianza
|
| 173 |
-
|
| 174 |
-
---
|
| 175 |
-
|
| 176 |
-
## 🎓 META DEL CURSO
|
| 177 |
-
|
| 178 |
-
- **Mínimo requerido**: 30% accuracy en GAIA benchmark
|
| 179 |
-
- **Estado actual**: Listo para evaluar
|
| 180 |
-
- **Próximo paso**: Deploy y medir score
|
| 181 |
-
|
| 182 |
-
---
|
| 183 |
-
|
| 184 |
-
## 📁 ARCHIVOS MODIFICADOS EN ESTA SESIÓN
|
| 185 |
-
|
| 186 |
-
### Editados:
|
| 187 |
-
- ✅ `model.py` - Variable env unificada
|
| 188 |
-
- ✅ `tools/tools.py` - Variable env unificada
|
| 189 |
-
- ✅ `requirements.txt` - Dependencies agregadas
|
| 190 |
-
- ✅ `app.py` - 3 correcciones (archivos, límite, logs)
|
| 191 |
-
|
| 192 |
-
### Creados:
|
| 193 |
-
- ✅ `test_agent.py` - Suite de tests
|
| 194 |
-
- ✅ `tools/__init__.py` - Package init
|
| 195 |
-
- ✅ `DIAGNOSTIC_REPORT.md` - Diagnóstico completo
|
| 196 |
-
- ✅ `CLEANUP_OBSOLETE_FILES.md` - Guía de limpieza
|
| 197 |
-
- ✅ `DEPLOY_QUICKSTART.md` - Guía de deploy
|
| 198 |
-
- ✅ `CORRECCIONES_APLICADAS.md` - Este archivo
|
| 199 |
-
|
| 200 |
-
---
|
| 201 |
-
|
| 202 |
-
## 🔍 VERIFICACIÓN FINAL
|
| 203 |
-
|
| 204 |
-
Antes de deploy, verificar:
|
| 205 |
-
|
| 206 |
-
- [x] ✅ `requirements.txt` tiene todas las deps
|
| 207 |
-
- [x] ✅ Código usa `GEMINI_API_KEY` consistentemente
|
| 208 |
-
- [x] ✅ `app.py` pasa archivos al agent
|
| 209 |
-
- [x] ✅ `app.py` procesa todas las preguntas
|
| 210 |
-
- [x] ✅ `test_agent.py` existe y es funcional
|
| 211 |
-
- [x] ✅ `tools/__init__.py` existe
|
| 212 |
-
- [ ] ⚠️ Archivos obsoletos eliminados
|
| 213 |
-
- [ ] ⚠️ `GEMINI_API_KEY` configurado en HF Spaces
|
| 214 |
-
- [ ] ⚠️ Tests ejecutados localmente (opcional pero recomendado)
|
| 215 |
-
|
| 216 |
-
---
|
| 217 |
-
|
| 218 |
-
## 📞 SOPORTE
|
| 219 |
-
|
| 220 |
-
Si encuentras errores después del deploy:
|
| 221 |
-
|
| 222 |
-
1. **Revisar logs en HF Spaces** (pestaña Logs)
|
| 223 |
-
2. **Buscar primer error** (ignorar warnings)
|
| 224 |
-
3. **Consultar documentación creada**:
|
| 225 |
-
- `DIAGNOSTIC_REPORT.md` - Problemas conocidos
|
| 226 |
-
- `DEPLOY_QUICKSTART.md` - Troubleshooting
|
| 227 |
-
4. **Ajustar y volver a intentar**
|
| 228 |
-
|
| 229 |
-
---
|
| 230 |
-
|
| 231 |
-
## 🎉 CONCLUSIÓN
|
| 232 |
-
|
| 233 |
-
El proyecto está **94% listo** para deployment. Solo falta:
|
| 234 |
-
1. Configurar secret en HF Spaces (1 minuto)
|
| 235 |
-
2. Eliminar archivos obsoletos (1 minuto)
|
| 236 |
-
3. Push y deploy (3 minutos)
|
| 237 |
-
|
| 238 |
-
**Tiempo total estimado para deployment**: 5 minutos
|
| 239 |
-
|
| 240 |
-
---
|
| 241 |
-
|
| 242 |
-
**Generado por GitHub Copilot el 19 de Octubre, 2025**
|
| 243 |
-
**Revisión humana recomendada antes de ejecutar acciones**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEPLOY.md
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
# 🚀 Guía de Despliegue en HuggingFace Spaces
|
| 2 |
-
|
| 3 |
-
Esta guía te ayudará a desplegar tu agente GAIA con Gemini en HuggingFace Spaces.
|
| 4 |
-
|
| 5 |
-
## 📋 Pre-requisitos
|
| 6 |
-
|
| 7 |
-
1. **Cuenta de HuggingFace**
|
| 8 |
-
- Crea una gratis en: https://huggingface.co/join
|
| 9 |
-
|
| 10 |
-
2. **API Key de Google Gemini**
|
| 11 |
-
- Obtén una gratis en: https://aistudio.google.com/apikey
|
| 12 |
-
- No requiere tarjeta de crédito
|
| 13 |
-
- Límite generoso de requests gratuitos
|
| 14 |
-
|
| 15 |
-
## 🎯 Pasos de Despliegue
|
| 16 |
-
|
| 17 |
-
### 1. Crear el Space
|
| 18 |
-
|
| 19 |
-
1. Ve a: https://huggingface.co/new-space
|
| 20 |
-
2. Configura:
|
| 21 |
-
- **Owner**: Tu usuario
|
| 22 |
-
- **Space name**: `gaia-agent-gemini` (o el nombre que prefieras)
|
| 23 |
-
- **License**: MIT
|
| 24 |
-
- **SDK**: Gradio
|
| 25 |
-
- **Hardware**: CPU (gratuito) - suficiente para este proyecto
|
| 26 |
-
- **Visibility**: Public (para el curso)
|
| 27 |
-
|
| 28 |
-
3. Clic en **Create Space**
|
| 29 |
-
|
| 30 |
-
### 2. Subir el Código
|
| 31 |
-
|
| 32 |
-
**Opción A: Git (Recomendado)**
|
| 33 |
-
|
| 34 |
-
```bash
|
| 35 |
-
# Clona tu nuevo Space
|
| 36 |
-
git clone https://huggingface.co/spaces/TU-USUARIO/gaia-agent-gemini
|
| 37 |
-
cd gaia-agent-gemini
|
| 38 |
-
|
| 39 |
-
# Copia todos los archivos del proyecto
|
| 40 |
-
cp -r /ruta/a/tu/proyecto/* .
|
| 41 |
-
|
| 42 |
-
# Sube a HuggingFace
|
| 43 |
-
git add .
|
| 44 |
-
git commit -m "Initial commit - GAIA agent with Gemini"
|
| 45 |
-
git push
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
**Opción B: Web UI**
|
| 49 |
-
|
| 50 |
-
1. Abre tu Space en HuggingFace
|
| 51 |
-
2. Clic en **Files** → **Add file** → **Upload files**
|
| 52 |
-
3. Arrastra y suelta todos los archivos:
|
| 53 |
-
- `app.py`
|
| 54 |
-
- `agents.py`
|
| 55 |
-
- `model.py`
|
| 56 |
-
- `tools.py`
|
| 57 |
-
- `tool.py`
|
| 58 |
-
- `final_answer.py`
|
| 59 |
-
- `api.py`
|
| 60 |
-
- `requirements.txt`
|
| 61 |
-
- `README.md`
|
| 62 |
-
|
| 63 |
-
### 3. Configurar la API Key
|
| 64 |
-
|
| 65 |
-
1. Ve a **Settings** (arriba a la derecha)
|
| 66 |
-
2. Scroll hasta **Repository secrets**
|
| 67 |
-
3. Clic en **New secret**
|
| 68 |
-
4. Agrega:
|
| 69 |
-
- **Name**: `GEMINI_API_KEY`
|
| 70 |
-
- **Value**: Tu API key de Google (ej: `AIzaSy...`)
|
| 71 |
-
5. Clic en **Add**
|
| 72 |
-
|
| 73 |
-
### 4. Verificar el Despliegue
|
| 74 |
-
|
| 75 |
-
El Space se construirá automáticamente. Espera 2-3 minutos.
|
| 76 |
-
|
| 77 |
-
Verás:
|
| 78 |
-
- ⚙️ **Building** → Instalando dependencias
|
| 79 |
-
- 🟢 **Running** → ¡Listo para usar!
|
| 80 |
-
|
| 81 |
-
Si hay errores, revisa los **Logs** en la pestaña **Logs**.
|
| 82 |
-
|
| 83 |
-
### 5. Probar el Agente
|
| 84 |
-
|
| 85 |
-
1. Abre tu Space (URL: `https://huggingface.co/spaces/TU-USUARIO/gaia-agent-gemini`)
|
| 86 |
-
2. Clic en **Sign in with Hugging Face**
|
| 87 |
-
3. Autoriza el acceso
|
| 88 |
-
4. Clic en **▶️ Ejecutar Evaluación**
|
| 89 |
-
5. Observa los resultados en la tabla
|
| 90 |
-
|
| 91 |
-
## 🔧 Configuración Avanzada
|
| 92 |
-
|
| 93 |
-
### Cambiar el Modelo Gemini
|
| 94 |
-
|
| 95 |
-
Edita `app.py` línea 15:
|
| 96 |
-
|
| 97 |
-
```python
|
| 98 |
-
# Opciones disponibles:
|
| 99 |
-
MODEL_ID = "gemini/gemini-2.0-flash-exp" # Rápido (recomendado)
|
| 100 |
-
MODEL_ID = "gemini/gemini-1.5-flash" # Estable
|
| 101 |
-
MODEL_ID = "gemini/gemini-1.5-pro" # Más potente (más lento)
|
| 102 |
-
```
|
| 103 |
-
|
| 104 |
-
### Limitar Número de Preguntas (Testing)
|
| 105 |
-
|
| 106 |
-
Edita `app.py`, descomenta la línea ~71:
|
| 107 |
-
|
| 108 |
-
```python
|
| 109 |
-
# questions_data = questions_data[:5] # Solo 5 preguntas para testing
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
### Habilitar Debug Verbose
|
| 113 |
-
|
| 114 |
-
Edita `agents.py`, cambia línea ~83:
|
| 115 |
-
|
| 116 |
-
```python
|
| 117 |
-
agent = create_agent(model_id=MODEL_ID, verbose=True) # Ya está activado
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
## 🐛 Solución de Problemas
|
| 121 |
-
|
| 122 |
-
### Error: "GEMINI_API_KEY no configurada"
|
| 123 |
-
|
| 124 |
-
**Solución**: Verifica que agregaste el secret correctamente en Settings → Repository secrets.
|
| 125 |
-
|
| 126 |
-
### Error: "Import gradio could not be resolved"
|
| 127 |
-
|
| 128 |
-
**Solución**: El Space se está construyendo. Espera hasta que termine (estado "Running").
|
| 129 |
-
|
| 130 |
-
### Error: "Rate limit exceeded"
|
| 131 |
-
|
| 132 |
-
**Solución**: Gemini tiene límites gratuitos (60 requests/min). El código ya incluye retry logic. Si falla, espera 1 minuto y vuelve a intentar.
|
| 133 |
-
|
| 134 |
-
### Error: "SPACE_ID no configurado"
|
| 135 |
-
|
| 136 |
-
**Solución**: Este error solo ocurre en ejecución local. En HuggingFace Spaces, esta variable se configura automáticamente.
|
| 137 |
-
|
| 138 |
-
## 📊 Evaluar Resultados
|
| 139 |
-
|
| 140 |
-
Después de ejecutar, verás:
|
| 141 |
-
|
| 142 |
-
- **Puntuación**: % de respuestas correctas
|
| 143 |
-
- **Correctas**: N de M preguntas
|
| 144 |
-
- **Tabla**: Todas las preguntas y respuestas
|
| 145 |
-
|
| 146 |
-
Compara tu puntuación en el [leaderboard del curso](https://huggingface.co/spaces/agents-course-unit4-scoring).
|
| 147 |
-
|
| 148 |
-
## 🔄 Actualizar el Código
|
| 149 |
-
|
| 150 |
-
Si haces cambios localmente:
|
| 151 |
-
|
| 152 |
-
```bash
|
| 153 |
-
cd gaia-agent-gemini
|
| 154 |
-
# Edita archivos...
|
| 155 |
-
git add .
|
| 156 |
-
git commit -m "Descripción del cambio"
|
| 157 |
-
git push
|
| 158 |
-
```
|
| 159 |
-
|
| 160 |
-
El Space se reconstruirá automáticamente.
|
| 161 |
-
|
| 162 |
-
## 🎓 Recursos
|
| 163 |
-
|
| 164 |
-
- [Documentación de Spaces](https://huggingface.co/docs/hub/spaces)
|
| 165 |
-
- [Gradio OAuth Docs](https://www.gradio.app/guides/sharing-your-app#o-auth-login-via-hugging-face)
|
| 166 |
-
- [Google Gemini Docs](https://ai.google.dev/gemini-api/docs)
|
| 167 |
-
- [LiteLLM Gemini Guide](https://docs.litellm.ai/docs/providers/gemini)
|
| 168 |
-
|
| 169 |
-
## 💬 Soporte
|
| 170 |
-
|
| 171 |
-
Si tienes problemas:
|
| 172 |
-
|
| 173 |
-
1. Revisa los **Logs** en tu Space
|
| 174 |
-
2. Consulta este README.md y DEPLOY.md
|
| 175 |
-
3. Pregunta en el [foro del curso](https://huggingface.co/learn/agents-course)
|
| 176 |
-
|
| 177 |
-
---
|
| 178 |
-
|
| 179 |
-
¡Buena suerte con tu agente! 🚀
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEPLOY_QUICKSTART.md
CHANGED
|
@@ -1,18 +1,28 @@
|
|
| 1 |
-
# 📦 Guía
|
| 2 |
|
| 3 |
-
##
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
- [x] ✅ Variable `GEMINI_API_KEY` unificada en código
|
| 8 |
-
- [x] ✅
|
| 9 |
-
- [x] ✅
|
|
|
|
|
|
|
|
|
|
| 10 |
- [x] ✅ App corregido para pasar archivos al agent
|
|
|
|
| 11 |
- [x] ✅ Test suite creado (`test_agent.py`)
|
| 12 |
-
- [
|
| 13 |
-
- [ ] ⚠️ `GEMINI_API_KEY` configurado en HF Spaces
|
| 14 |
|
| 15 |
-
### 2. Configurar Secret en HF Spaces
|
| 16 |
|
| 17 |
1. Ve a tu Space: https://huggingface.co/spaces/[TU_USERNAME]/[TU_SPACE]
|
| 18 |
2. Click en **Settings**
|
|
@@ -20,101 +30,192 @@
|
|
| 20 |
4. Click **Add a secret**
|
| 21 |
5. Configurar:
|
| 22 |
- **Name**: `GEMINI_API_KEY` (EXACTO, case-sensitive)
|
| 23 |
-
- **Value**: Tu API key de Google
|
| 24 |
- Click **Add**
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
# Configurar API key temporalmente
|
| 30 |
-
$env:GEMINI_API_KEY = "tu_api_key_aqui"
|
| 31 |
-
|
| 32 |
-
# Ejecutar tests
|
| 33 |
-
python test_agent.py
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
```
|
| 37 |
|
| 38 |
-
### 4. Push a HF Spaces
|
| 39 |
|
| 40 |
```powershell
|
| 41 |
-
#
|
| 42 |
git status
|
| 43 |
|
| 44 |
-
# Agregar cambios
|
| 45 |
git add .
|
| 46 |
|
| 47 |
-
# Commit
|
| 48 |
-
git commit -m "
|
| 49 |
|
| 50 |
-
# Push a HF Spaces
|
| 51 |
git push
|
| 52 |
-
```
|
| 53 |
-
|
| 54 |
-
### 5. Monitorear Build
|
| 55 |
-
|
| 56 |
-
1. Ve a tu Space en HuggingFace
|
| 57 |
-
2. Abre la pestaña **Logs**
|
| 58 |
-
3. Observa el build process
|
| 59 |
-
4. Buscar errores:
|
| 60 |
-
- ❌ `ModuleNotFoundError` → Falta dependencia en requirements.txt
|
| 61 |
-
- ❌ `GEMINI_API_KEY not found` → Secret no configurado
|
| 62 |
-
- ❌ `ImportError` → Problema de sintaxis o imports
|
| 63 |
-
|
| 64 |
-
### 6. Verificar Funcionamiento
|
| 65 |
-
|
| 66 |
-
Una vez que el build termine:
|
| 67 |
-
|
| 68 |
-
1. Abre tu Space
|
| 69 |
-
2. Click en **Login to Hugging Face**
|
| 70 |
-
3. Click **Run Evaluation & Submit All Answers**
|
| 71 |
-
4. Observa los logs en la consola
|
| 72 |
-
5. Verifica el score
|
| 73 |
-
|
| 74 |
-
## 🔍 Troubleshooting
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
**Solución**: Verificar que `requirements.txt` contenga `smolagents>=0.1.0`
|
| 80 |
-
|
| 81 |
-
### Error: `GEMINI_API_KEY not configured`
|
| 82 |
|
| 83 |
-
|
| 84 |
-
**Solución**: Seguir paso 2 arriba
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
**
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
###
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
**
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
| 106 |
-
2. Si < 30%:
|
| 107 |
-
- Revisa logs de errores
|
| 108 |
-
- Ajusta prompts en `agents.py`
|
| 109 |
-
- Itera y vuelve a probar
|
| 110 |
-
3. Si >= 30%:
|
| 111 |
-
- ✅ ¡Felicidades! Curso completado
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
- **Meta
|
| 117 |
-
- **Meta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
## 📝 Comandos Útiles
|
| 120 |
|
|
@@ -125,23 +226,38 @@ git log --oneline -10
|
|
| 125 |
# Ver cambios pendientes
|
| 126 |
git status
|
| 127 |
|
| 128 |
-
#
|
| 129 |
-
git
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
#
|
| 132 |
-
git
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
```
|
| 134 |
|
| 135 |
-
##
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
---
|
| 146 |
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📦 Guía de Deploy Exitoso a Hugging Face Spaces
|
| 2 |
|
| 3 |
+
## 🎉 RESULTADO: Deploy Exitoso - Meta Alcanzada (30%)
|
| 4 |
|
| 5 |
+
**Space URL**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN
|
| 6 |
+
**Score Final**: 30.0% (6/20 correctas) ✅
|
| 7 |
+
**Modelo**: Gemini 2.5 Flash
|
| 8 |
+
**Fecha**: Octubre 2025
|
| 9 |
+
|
| 10 |
+
## 🚀 Pasos para Deploy (Verificados)
|
| 11 |
+
|
| 12 |
+
### 1. Pre-Deploy Checklist ✅
|
| 13 |
|
| 14 |
- [x] ✅ Variable `GEMINI_API_KEY` unificada en código
|
| 15 |
+
- [x] ✅ Todas las dependencias en `requirements.txt` (37 paquetes)
|
| 16 |
+
- [x] ✅ Dependencias de sistema en `packages.txt` (ffmpeg, tesseract)
|
| 17 |
+
- [x] ✅ Modelo actualizado a `gemini/gemini-2.5-flash`
|
| 18 |
+
- [x] ✅ Rate limiting implementado (20s entre preguntas)
|
| 19 |
+
- [x] ✅ Logging mejorado con timestamps y emojis
|
| 20 |
- [x] ✅ App corregido para pasar archivos al agent
|
| 21 |
+
- [x] ✅ Límite de 2 preguntas eliminado
|
| 22 |
- [x] ✅ Test suite creado (`test_agent.py`)
|
| 23 |
+
- [x] ✅ 15 herramientas configuradas y funcionando
|
|
|
|
| 24 |
|
| 25 |
+
### 2. Configurar Secret en HF Spaces ✅
|
| 26 |
|
| 27 |
1. Ve a tu Space: https://huggingface.co/spaces/[TU_USERNAME]/[TU_SPACE]
|
| 28 |
2. Click en **Settings**
|
|
|
|
| 30 |
4. Click **Add a secret**
|
| 31 |
5. Configurar:
|
| 32 |
- **Name**: `GEMINI_API_KEY` (EXACTO, case-sensitive)
|
| 33 |
+
- **Value**: Tu API key de Google AI Studio (https://aistudio.google.com/apikey)
|
| 34 |
- Click **Add**
|
| 35 |
|
| 36 |
+
**✅ Verificado funcionando**: La key se inyecta automáticamente como variable de entorno.
|
| 37 |
|
| 38 |
+
### 3. Estructura de Archivos Final ✅
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
```
|
| 41 |
+
hf-gaia-agents-course-MN/
|
| 42 |
+
├── app.py # Gradio UI con logging mejorado
|
| 43 |
+
├── agents.py # Agent wrapper de smolagents
|
| 44 |
+
├── model.py # Gemini model wrapper con retry
|
| 45 |
+
├── tool.py # Registry de 15 herramientas
|
| 46 |
+
├── tools/
|
| 47 |
+
│ ├── __init__.py # Package init
|
| 48 |
+
│ └── tools.py # Custom tools (vision, YouTube, OCR, etc.)
|
| 49 |
+
├── utils/
|
| 50 |
+
│ └── logger.py # Logger configuration
|
| 51 |
+
├── api.py # API client (opcional)
|
| 52 |
+
├── requirements.txt # 37 dependencias Python
|
| 53 |
+
├── packages.txt # 2 dependencias sistema (ffmpeg, tesseract)
|
| 54 |
+
├── test_agent.py # Test suite
|
| 55 |
+
├── README.md # Con metadata OAuth
|
| 56 |
+
└── *.md # Documentación
|
| 57 |
+
|
| 58 |
+
Archivos de documentación:
|
| 59 |
+
├── DIAGNOSTIC_REPORT.md
|
| 60 |
+
├── CORRECCIONES_APLICADAS.md
|
| 61 |
+
├── DEPLOY_QUICKSTART.md (este archivo)
|
| 62 |
+
├── RATE_LIMIT_FIX.md
|
| 63 |
+
├── READY_TO_DEPLOY.md
|
| 64 |
+
└── RESUMEN_IMPLEMENTACION.md
|
| 65 |
```
|
| 66 |
|
| 67 |
+
### 4. Push a HF Spaces ✅
|
| 68 |
|
| 69 |
```powershell
|
| 70 |
+
# Ver estado
|
| 71 |
git status
|
| 72 |
|
| 73 |
+
# Agregar todos los cambios
|
| 74 |
git add .
|
| 75 |
|
| 76 |
+
# Commit con mensaje descriptivo
|
| 77 |
+
git commit -m "Improve logging with timestamps, emojis, and progress tracking"
|
| 78 |
|
| 79 |
+
# Push a HF Spaces (origin apunta a huggingface.co)
|
| 80 |
git push
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
# Ver logs del build en HF Spaces
|
| 83 |
+
# https://huggingface.co/spaces/[USERNAME]/[SPACE]/logs
|
| 84 |
+
```
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
### 5. Monitorear Build ✅
|
|
|
|
| 87 |
|
| 88 |
+
**Build exitoso muestra**:
|
| 89 |
+
```
|
| 90 |
+
Installing dependencies from requirements.txt...
|
| 91 |
+
✓ gradio==5.49.1
|
| 92 |
+
✓ smolagents>=0.1.0
|
| 93 |
+
✓ litellm>=1.0.0
|
| 94 |
+
✓ google-generativeai>=0.8.0
|
| 95 |
+
... (33 más)
|
| 96 |
+
|
| 97 |
+
Installing system packages from packages.txt...
|
| 98 |
+
✓ ffmpeg
|
| 99 |
+
✓ tesseract-ocr
|
| 100 |
+
|
| 101 |
+
Starting Gradio app...
|
| 102 |
+
Running on http://0.0.0.0:7860
|
| 103 |
+
```
|
| 104 |
|
| 105 |
+
**Errores comunes resueltos**:
|
| 106 |
+
- ✅ `youtube-transcript-api==0.6.0` (versión específica, no 3.0.0)
|
| 107 |
+
- ✅ `ddgs>=0.0.1` (DuckDuckGo search dependency)
|
| 108 |
+
- ✅ `wikipedia-api>=0.5.0` (Wikipedia tool dependency)
|
| 109 |
+
- ✅ `markdownify` y `requests` (VisitWebpageTool dependencies)
|
| 110 |
|
| 111 |
+
### 6. Ejemplo de Logs de Ejecución Exitosa ✅
|
| 112 |
|
| 113 |
+
```
|
| 114 |
+
================================================================================
|
| 115 |
+
[07:27:28] ℹ️ 🚀 GAIA BENCHMARK EVALUATION STARTED
|
| 116 |
+
================================================================================
|
| 117 |
+
|
| 118 |
+
[07:27:28] ✅ User authenticated: MalcomNavarro
|
| 119 |
+
[07:27:28] ℹ️ Initializing agent...
|
| 120 |
+
[07:27:28] ✅ Agent initialized with model: gemini/gemini-2.5-flash
|
| 121 |
+
[07:27:28] ℹ️ Tools loaded: 15 tools available
|
| 122 |
+
|
| 123 |
+
[07:27:28] ℹ️ Fetching questions from scoring server...
|
| 124 |
+
[07:27:28] ✅ Fetched 20 questions from server
|
| 125 |
+
[07:27:28] ℹ️ Questions include: 5 with files
|
| 126 |
+
|
| 127 |
+
================================================================================
|
| 128 |
+
[07:27:28] ℹ️ 🤖 STARTING AGENT EVALUATION
|
| 129 |
+
================================================================================
|
| 130 |
+
|
| 131 |
+
[07:27:28] 🔄 [1/20] Starting question 1
|
| 132 |
+
[07:27:28] ℹ️ Processing task abc123
|
| 133 |
+
[07:27:28] ℹ️ Question: How many studio albums were published...
|
| 134 |
+
[07:27:28] ℹ️ Building context...
|
| 135 |
+
[07:27:28] ℹ️ 🤖 Running agent reasoning...
|
| 136 |
+
[07:27:40] ℹ️ 🧹 Cleaning answer...
|
| 137 |
+
[07:27:40] ℹ️ ✨ Final answer: 3
|
| 138 |
+
[07:27:40] ✅ Task abc123 completed: 3
|
| 139 |
+
|
| 140 |
+
[07:27:40] ℹ️ ⏳ Waiting 20 seconds before next question (Rate limit: 10 req/min)
|
| 141 |
+
[07:27:40] ℹ️ 📊 Progress: 1/20 completed | 19 remaining (~6 min left)
|
| 142 |
+
======================================================================
|
| 143 |
+
|
| 144 |
+
... (18 preguntas más con mismo formato) ...
|
| 145 |
+
|
| 146 |
+
[07:33:20] ✅ All 20 questions processed!
|
| 147 |
+
|
| 148 |
+
================================================================================
|
| 149 |
+
[07:33:20] ℹ️ 📤 PREPARING SUBMISSION
|
| 150 |
+
================================================================================
|
| 151 |
+
|
| 152 |
+
[07:33:20] ℹ️ Submitting to scoring server...
|
| 153 |
+
[07:33:28] ✅ 🎉 SUBMISSION SUCCESSFUL!
|
| 154 |
+
[07:33:28] ✅ 📊 Score: 30.0% (6/20 correct)
|
| 155 |
+
[07:33:28] ℹ️ Message: Score calculated successfully
|
| 156 |
+
================================================================================
|
| 157 |
+
```
|
| 158 |
|
| 159 |
+
## 📊 Métricas de Rendimiento
|
| 160 |
|
| 161 |
+
### Tiempo de Ejecución
|
| 162 |
+
- **Build time**: ~3-5 minutos
|
| 163 |
+
- **Evaluation time**: ~8-10 minutos (20 preguntas)
|
| 164 |
+
- **Total**: ~15 minutos desde push hasta score
|
| 165 |
|
| 166 |
+
### Rate Limits (Free Tier)
|
| 167 |
+
- **Modelo**: Gemini 2.5 Flash
|
| 168 |
+
- **Límite**: 10 requests/minuto
|
| 169 |
+
- **Delay**: 20 segundos entre preguntas
|
| 170 |
+
- **Retry**: 5 intentos con exponential backoff
|
| 171 |
|
| 172 |
+
### Recursos Utilizados
|
| 173 |
+
- **Memoria**: ~2-3 GB (Whisper, Transformers, etc.)
|
| 174 |
+
- **CPU**: Suficiente para Gradio + LLM calls
|
| 175 |
+
- **Disk**: ~500 MB (dependencias)
|
| 176 |
|
| 177 |
+
## 🎯 Score Final y Meta del Curso
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
### Resultado Alcanzado ✅
|
| 180 |
+
```
|
| 181 |
+
📊 Score: 30.0%
|
| 182 |
+
✓ Correct: 6/20
|
| 183 |
+
� User: MalcomNavarro
|
| 184 |
+
📅 Date: Octubre 2025
|
| 185 |
+
🤖 Model: Gemini 2.5 Flash
|
| 186 |
+
```
|
| 187 |
|
| 188 |
+
### Meta del Curso
|
| 189 |
+
- ✅ **Meta mínima**: 30% (ALCANZADO)
|
| 190 |
+
- 📈 **Meta buena**: 40-50%
|
| 191 |
+
- 🏆 **Meta excelente**: >50%
|
| 192 |
+
|
| 193 |
+
### Breakdown de Preguntas
|
| 194 |
+
- **Total intentadas**: 20
|
| 195 |
+
- **Correctas**: 6
|
| 196 |
+
- **Incorrectas**: 14
|
| 197 |
+
- **Con archivos**: 5
|
| 198 |
+
- **Solo texto**: 15
|
| 199 |
+
|
| 200 |
+
## 💡 Lecciones Aprendidas
|
| 201 |
+
|
| 202 |
+
### ✅ Lo que funcionó:
|
| 203 |
+
1. **smolagents framework** - Excelente manejo de herramientas
|
| 204 |
+
2. **Gemini 2.5 Flash** - Buen balance costo/rendimiento
|
| 205 |
+
3. **Logging detallado** - Facilita debugging enormemente
|
| 206 |
+
4. **Rate limiting** - Previene errores 429
|
| 207 |
+
5. **Múltiples tools** - Cubren diversos tipos de preguntas
|
| 208 |
+
|
| 209 |
+
### ⚠️ Desafíos:
|
| 210 |
+
1. **Free tier restrictivo** - 10 req/min vs 250 req/min (paid)
|
| 211 |
+
2. **Tiempo de evaluación** - ~10 minutos por rate limits
|
| 212 |
+
3. **Dependencias ocultas** - Algunos packages no documentados
|
| 213 |
+
|
| 214 |
+
### 🚀 Recomendaciones futuras:
|
| 215 |
+
1. Usar API key paga para 25x más velocidad
|
| 216 |
+
2. Implementar caching de respuestas
|
| 217 |
+
3. Mejorar prompts con más ejemplos GAIA
|
| 218 |
+
4. Fine-tuning específico para benchmark GAIA
|
| 219 |
|
| 220 |
## 📝 Comandos Útiles
|
| 221 |
|
|
|
|
| 226 |
# Ver cambios pendientes
|
| 227 |
git status
|
| 228 |
|
| 229 |
+
# Ver diferencias
|
| 230 |
+
git diff app.py
|
| 231 |
+
|
| 232 |
+
# Ver branches
|
| 233 |
+
git branch
|
| 234 |
|
| 235 |
+
# Crear nuevo branch
|
| 236 |
+
git checkout -b feature/mejora
|
| 237 |
+
|
| 238 |
+
# Push a branch específico
|
| 239 |
+
git push origin main
|
| 240 |
+
|
| 241 |
+
# Ver remote URLs
|
| 242 |
+
git remote -v
|
| 243 |
```
|
| 244 |
|
| 245 |
+
## 🔗 Enlaces Importantes
|
| 246 |
|
| 247 |
+
- **Space URL**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN
|
| 248 |
+
- **Repo URL**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN/tree/main
|
| 249 |
+
- **Logs**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN/logs
|
| 250 |
+
- **Settings**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN/settings
|
| 251 |
+
- **Gemini API**: https://aistudio.google.com/apikey
|
| 252 |
+
- **Rate Limits**: https://ai.google.dev/gemini-api/docs/rate-limits
|
| 253 |
+
- **GAIA Benchmark**: https://huggingface.co/gaia-benchmark
|
| 254 |
+
- **Curso HF**: https://huggingface.co/learn/agents-course/unit4/hands-on
|
| 255 |
|
| 256 |
---
|
| 257 |
|
| 258 |
+
**✅ Deploy Exitoso - Meta Alcanzada (30%)** 🎉
|
| 259 |
+
|
| 260 |
+
**Stack Final**: Python 3.10+, Gradio 5.x, Gemini 2.5 Flash, LiteLLM, smolagents
|
| 261 |
+
**Fecha**: Octubre 2025
|
| 262 |
+
**Malcom Navarro**
|
| 263 |
+
**Licencia**: MIT
|
DIAGNOSTIC_REPORT.md
DELETED
|
@@ -1,210 +0,0 @@
|
|
| 1 |
-
# 🔍 Diagnóstico Completo del Proyecto GAIA Agent
|
| 2 |
-
|
| 3 |
-
**Fecha**: 19 de Octubre, 2025
|
| 4 |
-
**Estado**: Revisión completa pre-deployment
|
| 5 |
-
|
| 6 |
-
---
|
| 7 |
-
|
| 8 |
-
## ✅ PROBLEMAS IDENTIFICADOS Y SOLUCIONES
|
| 9 |
-
|
| 10 |
-
### 🔴 CRÍTICOS (Bloquean ejecución)
|
| 11 |
-
|
| 12 |
-
#### 1. **Dependencias no instaladas**
|
| 13 |
-
- **Problema**: `smolagents`, `whisper`, `imageio`, `yt_dlp`, `transformers`, `torch` no están instalados
|
| 14 |
-
- **Impacto**: ModuleNotFoundError en runtime
|
| 15 |
-
- **Estado**: ✅ AGREGADO a requirements.txt
|
| 16 |
-
- **Solución**: Ejecutar `pip install -r requirements.txt`
|
| 17 |
-
- **Prioridad**: 🔴 MÁXIMA
|
| 18 |
-
|
| 19 |
-
#### 2. **Variable de entorno inconsistente**
|
| 20 |
-
- **Problema**: Algunos archivos usaban `GEMINI_API` en vez de `GEMINI_API_KEY`
|
| 21 |
-
- **Archivos afectados**:
|
| 22 |
-
- ✅ `model.py` - CORREGIDO
|
| 23 |
-
- ✅ `tools/tools.py` - CORREGIDO
|
| 24 |
-
- **Estado**: ✅ RESUELTO
|
| 25 |
-
- **Prioridad**: 🔴 MÁXIMA
|
| 26 |
-
|
| 27 |
-
#### 3. **Falta configurar secret en HF Spaces**
|
| 28 |
-
- **Problema**: `GEMINI_API_KEY` no está configurado como secret
|
| 29 |
-
- **Impacto**: Agent no puede llamar a Gemini API
|
| 30 |
-
- **Solución**: Ir a Settings → Secrets → Add `GEMINI_API_KEY`
|
| 31 |
-
- **Estado**: ⚠️ PENDIENTE (requiere acción del usuario)
|
| 32 |
-
- **Prioridad**: 🔴 MÁXIMA
|
| 33 |
-
|
| 34 |
-
---
|
| 35 |
-
|
| 36 |
-
### 🟡 IMPORTANTES (Afectan funcionalidad)
|
| 37 |
-
|
| 38 |
-
#### 4. **Archivo obsoleto: `agent.py`**
|
| 39 |
-
- **Problema**: Existe un `agent.py` obsoleto que usa OpenAI en vez de Gemini
|
| 40 |
-
- **Ubicación**: `d:\...\agent.py`
|
| 41 |
-
- **Contenido**:
|
| 42 |
-
```python
|
| 43 |
-
from openai import OpenAI # ❌ Obsoleto
|
| 44 |
-
```
|
| 45 |
-
- **Solución**: ELIMINAR este archivo
|
| 46 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 47 |
-
- **Prioridad**: 🟡 ALTA
|
| 48 |
-
|
| 49 |
-
#### 5. **Tool obsoleto: `describe_image_tool.py`**
|
| 50 |
-
- **Problema**: Usa OpenAI GPT-4 Vision en vez de Gemini
|
| 51 |
-
- **Ubicación**: `tools/describe_image_tool.py`
|
| 52 |
-
- **Línea**: `from openai import OpenAI`
|
| 53 |
-
- **Solución**: Reemplazar por `vision_tool` de `tools/tools.py` que usa Gemini
|
| 54 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 55 |
-
- **Prioridad**: 🟡 ALTA
|
| 56 |
-
|
| 57 |
-
#### 6. **Dependencia faltante: `youtube-transcript-api`**
|
| 58 |
-
- **Problema**: `youtube_transcription_tool.py` usa esta librería pero no está en requirements.txt
|
| 59 |
-
- **Solución**: Agregar a requirements.txt
|
| 60 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 61 |
-
- **Prioridad**: 🟡 ALTA
|
| 62 |
-
|
| 63 |
-
#### 7. **Archivo de test vacío**
|
| 64 |
-
- **Problema**: `test_agent.py` está completamente vacío
|
| 65 |
-
- **Impacto**: No hay forma de validar el agent localmente
|
| 66 |
-
- **Solución**: Recrear el archivo de test
|
| 67 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 68 |
-
- **Prioridad**: 🟡 ALTA
|
| 69 |
-
|
| 70 |
-
#### 8. **app.py no pasa archivos al agent**
|
| 71 |
-
- **Problema**: En `process_question`, se llama `agent(question)` sin pasar el archivo
|
| 72 |
-
- **Línea 21**: `answer = agent(question)`
|
| 73 |
-
- **Debería ser**: `answer = agent(question, files=[q.get("file_name")] if q.get("file_name") else None)`
|
| 74 |
-
- **Impacto**: Preguntas con archivos adjuntos fallarán
|
| 75 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 76 |
-
- **Prioridad**: 🟡 ALTA
|
| 77 |
-
|
| 78 |
-
#### 9. **Límite artificial de 2 preguntas**
|
| 79 |
-
- **Problema**: `app.py` línea 80: `questions_data = questions_data[:2]`
|
| 80 |
-
- **Impacto**: Solo evalúa 2 preguntas en vez de todas
|
| 81 |
-
- **Solución**: Eliminar esta línea
|
| 82 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 83 |
-
- **Prioridad**: 🟡 ALTA
|
| 84 |
-
|
| 85 |
-
---
|
| 86 |
-
|
| 87 |
-
### 🟢 MENORES (Mejoras recomendadas)
|
| 88 |
-
|
| 89 |
-
#### 10. **Tools redundantes en tools/**
|
| 90 |
-
- **Problema**: Existen múltiples implementaciones de tools similares
|
| 91 |
-
- **Archivos redundantes**:
|
| 92 |
-
- `youtube_transcription_tool.py` (class-based) vs `transcribe_youtube` en `tools.py` (decorator)
|
| 93 |
-
- `openai_speech_to_text_tool.py` (OpenAI) vs `audio_to_text` en `tools.py` (Whisper)
|
| 94 |
-
- `describe_image_tool.py` (OpenAI) vs `vision_tool` en `tools.py` (Gemini)
|
| 95 |
-
- **Solución**: Eliminar versiones obsoletas y unificar en `tools.py`
|
| 96 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 97 |
-
- **Prioridad**: 🟢 MEDIA
|
| 98 |
-
|
| 99 |
-
#### 11. **Final answer checks deshabilitados**
|
| 100 |
-
- **Problema**: `agents.py` tiene comentadas las validaciones de Ollama
|
| 101 |
-
- **Línea 5**: `# from tools.final_answer import check_reasoning, ensure_formatting`
|
| 102 |
-
- **Motivo**: Ollama no disponible en HF Spaces
|
| 103 |
-
- **Solución**: Implementar validaciones alternativas usando Gemini
|
| 104 |
-
- **Estado**: ℹ️ INFORMATIVO (diseño intencional)
|
| 105 |
-
- **Prioridad**: 🟢 BAJA
|
| 106 |
-
|
| 107 |
-
#### 12. **Falta archivo `__init__.py` en tools/**
|
| 108 |
-
- **Problema**: No existe `tools/__init__.py`
|
| 109 |
-
- **Impacto**: Puede causar problemas de importación en algunos entornos
|
| 110 |
-
- **Solución**: Crear archivo vacío o con exports
|
| 111 |
-
- **Estado**: ⚠️ PENDIENTE
|
| 112 |
-
- **Prioridad**: 🟢 BAJA
|
| 113 |
-
|
| 114 |
-
---
|
| 115 |
-
|
| 116 |
-
## 📋 CHECKLIST DE CORRECCIONES
|
| 117 |
-
|
| 118 |
-
### Antes de deploy a HF Spaces:
|
| 119 |
-
|
| 120 |
-
- [ ] 1. Instalar dependencias: `pip install -r requirements.txt`
|
| 121 |
-
- [ ] 2. Configurar `GEMINI_API_KEY` en HF Spaces Secrets
|
| 122 |
-
- [ ] 3. Eliminar `agent.py` obsoleto
|
| 123 |
-
- [ ] 4. Eliminar o reemplazar `tools/describe_image_tool.py`
|
| 124 |
-
- [ ] 5. Agregar `youtube-transcript-api` a requirements.txt
|
| 125 |
-
- [ ] 6. Recrear `test_agent.py` funcional
|
| 126 |
-
- [ ] 7. Corregir `app.py` para pasar archivos al agent
|
| 127 |
-
- [ ] 8. Eliminar límite de 2 preguntas en `app.py`
|
| 128 |
-
- [ ] 9. Crear `tools/__init__.py`
|
| 129 |
-
- [ ] 10. Limpiar tools redundantes
|
| 130 |
-
- [ ] 11. Probar localmente con `python test_agent.py`
|
| 131 |
-
- [ ] 12. Verificar logs en HF Spaces después del deploy
|
| 132 |
-
|
| 133 |
-
---
|
| 134 |
-
|
| 135 |
-
## 🔧 CORRECCIONES APLICADAS
|
| 136 |
-
|
| 137 |
-
### Ya resueltos:
|
| 138 |
-
- ✅ Variable de entorno unificada a `GEMINI_API_KEY` en:
|
| 139 |
-
- `model.py`
|
| 140 |
-
- `tools/tools.py`
|
| 141 |
-
- ✅ Dependencias agregadas a `requirements.txt`:
|
| 142 |
-
- `smolagents>=0.1.0`
|
| 143 |
-
- `yt-dlp>=2023.12.12`
|
| 144 |
-
- `openai-whisper>=20230314`
|
| 145 |
-
- `imageio>=2.31.1`
|
| 146 |
-
- `imageio-ffmpeg>=0.4.8`
|
| 147 |
-
- `ffmpeg-python>=0.2.0`
|
| 148 |
-
- `numpy>=1.24.0`
|
| 149 |
-
- `litellm>=1.0.0`
|
| 150 |
-
- `google-generativeai>=0.8.0`
|
| 151 |
-
|
| 152 |
-
---
|
| 153 |
-
|
| 154 |
-
## 🚀 PRÓXIMOS PASOS (Orden recomendado)
|
| 155 |
-
|
| 156 |
-
1. **Correcciones de código** (15 min)
|
| 157 |
-
- Eliminar archivos obsoletos
|
| 158 |
-
- Agregar dependencia faltante
|
| 159 |
-
- Corregir app.py
|
| 160 |
-
- Recrear test_agent.py
|
| 161 |
-
|
| 162 |
-
2. **Instalación local** (5-10 min)
|
| 163 |
-
```powershell
|
| 164 |
-
pip install -r requirements.txt
|
| 165 |
-
```
|
| 166 |
-
|
| 167 |
-
3. **Prueba local** (5 min)
|
| 168 |
-
```powershell
|
| 169 |
-
$env:GEMINI_API_KEY="tu_api_key_aqui"
|
| 170 |
-
python test_agent.py
|
| 171 |
-
```
|
| 172 |
-
|
| 173 |
-
4. **Deploy a HF Spaces** (10 min)
|
| 174 |
-
- Configurar secret `GEMINI_API_KEY`
|
| 175 |
-
- Push cambios
|
| 176 |
-
- Monitorear logs del build
|
| 177 |
-
|
| 178 |
-
5. **Evaluación GAIA** (variable)
|
| 179 |
-
- Ejecutar evaluación completa
|
| 180 |
-
- Analizar resultados
|
| 181 |
-
- Iterar en prompts/tools si es necesario
|
| 182 |
-
|
| 183 |
-
---
|
| 184 |
-
|
| 185 |
-
## 📊 RESUMEN EJECUTIVO
|
| 186 |
-
|
| 187 |
-
| Categoría | Total | Resueltos | Pendientes |
|
| 188 |
-
|-----------|-------|-----------|------------|
|
| 189 |
-
| 🔴 Críticos | 3 | 2 | 1 |
|
| 190 |
-
| 🟡 Importantes | 6 | 0 | 6 |
|
| 191 |
-
| 🟢 Menores | 3 | 0 | 3 |
|
| 192 |
-
| **TOTAL** | **12** | **2** | **10** |
|
| 193 |
-
|
| 194 |
-
**Estado general**: 🟡 REQUIERE ATENCIÓN
|
| 195 |
-
**Tiempo estimado de corrección**: 30-45 minutos
|
| 196 |
-
**Bloqueadores para deployment**: 1 (configurar GEMINI_API_KEY en HF Spaces)
|
| 197 |
-
|
| 198 |
-
---
|
| 199 |
-
|
| 200 |
-
## 💡 RECOMENDACIONES
|
| 201 |
-
|
| 202 |
-
1. **Prioridad máxima**: Configurar `GEMINI_API_KEY` en HF Spaces
|
| 203 |
-
2. **Quick wins**: Eliminar archivos obsoletos (5 min)
|
| 204 |
-
3. **Testing**: Ejecutar localmente antes de push
|
| 205 |
-
4. **Monitoring**: Revisar logs de HF Spaces después del deploy
|
| 206 |
-
5. **Iteración**: Preparar para ajustar prompts según resultados GAIA
|
| 207 |
-
|
| 208 |
-
---
|
| 209 |
-
|
| 210 |
-
**Generado automáticamente por GitHub Copilot**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RATE_LIMIT_FIX.md
DELETED
|
@@ -1,74 +0,0 @@
|
|
| 1 |
-
# Rate Limit Solution
|
| 2 |
-
|
| 3 |
-
## Problem
|
| 4 |
-
Gemini models on free tier have limited requests per minute (RPM), which is exhausted quickly by the agent (each question makes 10-15 API calls).
|
| 5 |
-
|
| 6 |
-
## Current Configuration
|
| 7 |
-
**Using Gemini 2.5 Flash** - The most advanced model available
|
| 8 |
-
- **10 requests/minute** (Free Tier)
|
| 9 |
-
- Most capable reasoning and agentic capabilities
|
| 10 |
-
- Best for GAIA benchmark tasks
|
| 11 |
-
|
| 12 |
-
## Solution Applied
|
| 13 |
-
Added **20-second delays** between questions in `app.py` to respect rate limits. This means:
|
| 14 |
-
- 20 questions × 20 seconds = ~6-7 minutes extra runtime
|
| 15 |
-
- Prevents rate limit errors
|
| 16 |
-
- Ensures all questions are processed
|
| 17 |
-
|
| 18 |
-
## Alternative Models Available
|
| 19 |
-
|
| 20 |
-
### Option 1: Gemini 2.5 Flash (CURRENT - RECOMMENDED)
|
| 21 |
-
```python
|
| 22 |
-
MODEL_ID = "gemini/gemini-2.5-flash"
|
| 23 |
-
```
|
| 24 |
-
- **10 requests/minute** (Free Tier)
|
| 25 |
-
- **Most advanced model** - Best reasoning capabilities
|
| 26 |
-
- Optimized for agentic use cases
|
| 27 |
-
- Best for GAIA benchmark
|
| 28 |
-
|
| 29 |
-
### Option 2: Gemini 2.0 Flash
|
| 30 |
-
```python
|
| 31 |
-
MODEL_ID = "gemini/gemini-2.0-flash"
|
| 32 |
-
```
|
| 33 |
-
- **15 requests/minute** (Free Tier)
|
| 34 |
-
- 50% higher rate limit than 2.5 Flash
|
| 35 |
-
- Slightly less capable but faster
|
| 36 |
-
|
| 37 |
-
### Option 3: Gemini 1.5 Flash
|
| 38 |
-
```python
|
| 39 |
-
MODEL_ID = "gemini/gemini-1.5-flash"
|
| 40 |
-
```
|
| 41 |
-
- **15 requests/minute** (Free Tier)
|
| 42 |
-
- Older model but proven
|
| 43 |
-
- Similar speed to 2.0 Flash
|
| 44 |
-
|
| 45 |
-
### Option 4: Paid API Key (Tier 1+)
|
| 46 |
-
If you have a paid Gemini API key:
|
| 47 |
-
- **Gemini 2.5 Flash**: 250 requests/minute
|
| 48 |
-
- **Gemini 2.0 Flash**: 200 requests/minute
|
| 49 |
-
- **Gemini 1.5 Flash**: 50 requests/minute
|
| 50 |
-
|
| 51 |
-
## How to Switch Models
|
| 52 |
-
|
| 53 |
-
1. Edit `app.py` line 15:
|
| 54 |
-
```python
|
| 55 |
-
MODEL_ID = "gemini/gemini-2.5-flash" # Change this
|
| 56 |
-
```
|
| 57 |
-
|
| 58 |
-
2. Edit `tools/tools.py` line 19:
|
| 59 |
-
```python
|
| 60 |
-
MODEL_ID = "gemini/gemini-2.5-flash" # Change this
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
3. Commit and push:
|
| 64 |
-
```bash
|
| 65 |
-
git add app.py tools/tools.py
|
| 66 |
-
git commit -m "Update Gemini model"
|
| 67 |
-
git push
|
| 68 |
-
```
|
| 69 |
-
|
| 70 |
-
## Final Configuration
|
| 71 |
-
- **Model**: `gemini/gemini-2.5-flash` (Most advanced)
|
| 72 |
-
- **Rate Limit**: 10 requests/minute (Free Tier)
|
| 73 |
-
- **Delay**: 20 seconds between questions
|
| 74 |
-
- **Expected runtime**: ~8-10 minutes for 20 questions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
READY_TO_DEPLOY.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
# ✅ CHECKLIST FINAL PRE-DEPLOY
|
| 2 |
-
|
| 3 |
-
## 🎯 Estado: LISTO PARA DEPLOY
|
| 4 |
-
|
| 5 |
-
### ✅ Configuraciones Completadas
|
| 6 |
-
|
| 7 |
-
- [x] ✅ `GEMINI_API_KEY` configurada en HF Spaces
|
| 8 |
-
- [x] ✅ Variable env unificada en código
|
| 9 |
-
- [x] ✅ Dependencies en `requirements.txt`
|
| 10 |
-
- [x] ✅ `packages.txt` creado (ffmpeg, tesseract)
|
| 11 |
-
- [x] ✅ `app.py` corregido (pasa archivos, sin límites)
|
| 12 |
-
- [x] ✅ `test_agent.py` funcional
|
| 13 |
-
|
| 14 |
-
### 🚀 DEPLOY AHORA
|
| 15 |
-
|
| 16 |
-
```bash
|
| 17 |
-
git add .
|
| 18 |
-
git commit -m "Ready for deployment: unified env vars, added deps, fixed app.py"
|
| 19 |
-
git push
|
| 20 |
-
```
|
| 21 |
-
|
| 22 |
-
### 📊 Qué Esperar
|
| 23 |
-
|
| 24 |
-
1. **Build**: 5-10 minutos (instala dependencies)
|
| 25 |
-
2. **Logs**: Monitorear en HF Spaces → Logs tab
|
| 26 |
-
3. **App**: Se lanzará automáticamente si build OK
|
| 27 |
-
4. **Test**: Login con HF → Click "Run Evaluation"
|
| 28 |
-
|
| 29 |
-
### ⚠️ Si Hay Errores en Build
|
| 30 |
-
|
| 31 |
-
**Error común 1**: `ModuleNotFoundError`
|
| 32 |
-
- Causa: Dependencia faltante
|
| 33 |
-
- Fix: Agregar a `requirements.txt`
|
| 34 |
-
|
| 35 |
-
**Error común 2**: `GEMINI_API_KEY not found`
|
| 36 |
-
- Causa: Secret mal configurado
|
| 37 |
-
- Fix: Verificar nombre exacto en Settings
|
| 38 |
-
|
| 39 |
-
**Error común 3**: `ffmpeg not found`
|
| 40 |
-
- Causa: Ya resuelto con `packages.txt`
|
| 41 |
-
- Fix: N/A
|
| 42 |
-
|
| 43 |
-
### 🎓 Después del Deploy
|
| 44 |
-
|
| 45 |
-
1. Ejecutar evaluación completa
|
| 46 |
-
2. Anotar score inicial
|
| 47 |
-
3. Si < 30%: iterar en prompts
|
| 48 |
-
4. Si ≥ 30%: ✅ ¡Curso completado!
|
| 49 |
-
|
| 50 |
-
---
|
| 51 |
-
|
| 52 |
-
**¡TODO LISTO! 🚀 Push y a probar!**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RESUMEN_FINAL.md
DELETED
|
@@ -1,229 +0,0 @@
|
|
| 1 |
-
# ✅ Resumen de Implementación: Sistema Flexible de Modelos
|
| 2 |
-
|
| 3 |
-
## 🎯 Objetivo Alcanzado
|
| 4 |
-
|
| 5 |
-
Sistema que permite elegir fácilmente entre:
|
| 6 |
-
1. **Modelo LOCAL** (Llama 2 en memoria del Space)
|
| 7 |
-
2. **API Externa** (Gemini, GPT, Claude)
|
| 8 |
-
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
## 📁 Archivos Creados/Modificados
|
| 12 |
-
|
| 13 |
-
### ✅ Nuevos Archivos
|
| 14 |
-
|
| 15 |
-
1. **`config.py`** - Sistema de configuración centralizado
|
| 16 |
-
- `USE_LOCAL_MODEL` / `USE_API_MODEL` flags
|
| 17 |
-
- `LOCAL_MODEL_CONFIG` / `API_MODEL_CONFIG` dictionaries
|
| 18 |
-
- Funciones helper: `get_active_model_config()`, `get_model_display_name()`, etc.
|
| 19 |
-
|
| 20 |
-
2. **`model_llama_local.py`** - Wrapper para modelos locales
|
| 21 |
-
- Clase `LocalHFModel` con transformers + pipeline
|
| 22 |
-
- Soporte para quantización 8-bit (ahorra RAM)
|
| 23 |
-
- Formato Llama 2 Chat template
|
| 24 |
-
- Método `generate_simple()` compatible con Agent
|
| 25 |
-
|
| 26 |
-
3. **`GUIA_MODELOS.md`** - Documentación completa
|
| 27 |
-
- Comparación entre opciones
|
| 28 |
-
- Instrucciones paso a paso para cambiar
|
| 29 |
-
- Solución de problemas
|
| 30 |
-
|
| 31 |
-
### ✅ Archivos Modificados
|
| 32 |
-
|
| 33 |
-
1. **`app.py`**
|
| 34 |
-
- Importa `config.py` para obtener modelo activo
|
| 35 |
-
- Importación dinámica: `model_llama_local` o `model` según configuración
|
| 36 |
-
- Pasa kwargs específicos para cada tipo de modelo
|
| 37 |
-
- Mensajes informativos sobre modelo en uso
|
| 38 |
-
|
| 39 |
-
2. **`requirements.txt`**
|
| 40 |
-
- Agregadas dependencias para modelos locales:
|
| 41 |
-
- `torch>=2.0.0`
|
| 42 |
-
- `transformers>=4.35.0`
|
| 43 |
-
- `accelerate>=0.25.0`
|
| 44 |
-
- `bitsandbytes>=0.41.0`
|
| 45 |
-
- `sentencepiece>=0.1.99`
|
| 46 |
-
- Mantenidas dependencias para APIs:
|
| 47 |
-
- `litellm>=1.0.0`
|
| 48 |
-
- `google-generativeai>=0.8.0`
|
| 49 |
-
|
| 50 |
-
3. **`README.md`**
|
| 51 |
-
- Actualizado título: "Agente GAIA Flexible"
|
| 52 |
-
- Documentación de ambas opciones
|
| 53 |
-
- Tabla comparativa
|
| 54 |
-
- Instrucciones de configuración
|
| 55 |
-
|
| 56 |
-
### 📂 Archivos NO Modificados (mantenidos)
|
| 57 |
-
|
| 58 |
-
- `model.py` - Wrapper para APIs (Gemini, GPT, Claude) ✅
|
| 59 |
-
- `agents.py` - Clase Agent (ya era agnóstica de modelo) ✅
|
| 60 |
-
- `tools.py`, `tool.py` - Herramientas del agente ✅
|
| 61 |
-
- `api.py` - Cliente HTTP para API del curso ✅
|
| 62 |
-
- `final_answer.py` - Validaciones GAIA ✅
|
| 63 |
-
|
| 64 |
-
---
|
| 65 |
-
|
| 66 |
-
## 🎛️ Cómo Funciona
|
| 67 |
-
|
| 68 |
-
### Flujo de Ejecución:
|
| 69 |
-
|
| 70 |
-
```
|
| 71 |
-
1. app.py se inicia
|
| 72 |
-
↓
|
| 73 |
-
2. Importa config.py
|
| 74 |
-
↓
|
| 75 |
-
3. config.py lee los flags:
|
| 76 |
-
- USE_LOCAL_MODEL = True/False
|
| 77 |
-
- USE_API_MODEL = True/False
|
| 78 |
-
↓
|
| 79 |
-
4. get_active_model_config() retorna:
|
| 80 |
-
- ("local", LOCAL_MODEL_CONFIG) o
|
| 81 |
-
- ("api", API_MODEL_CONFIG)
|
| 82 |
-
↓
|
| 83 |
-
5. app.py importa el módulo correcto:
|
| 84 |
-
- if "local": from model_llama_local import get_model
|
| 85 |
-
- if "api": from model import get_model
|
| 86 |
-
↓
|
| 87 |
-
6. Se crea el agente con el modelo elegido
|
| 88 |
-
↓
|
| 89 |
-
7. Agente ejecuta 20 preguntas GAIA
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
---
|
| 93 |
-
|
| 94 |
-
## 🚀 Configuración por Defecto
|
| 95 |
-
|
| 96 |
-
```python
|
| 97 |
-
# config.py
|
| 98 |
-
USE_LOCAL_MODEL = True # 🟢 ACTIVO
|
| 99 |
-
USE_API_MODEL = False # 🔴 INACTIVO
|
| 100 |
-
|
| 101 |
-
LOCAL_MODEL_CONFIG = {
|
| 102 |
-
"model_id": "meta-llama/Llama-2-7b-chat-hf",
|
| 103 |
-
"load_in_8bit": True, # ~7GB RAM
|
| 104 |
-
"max_new_tokens": 256,
|
| 105 |
-
"temperature": 0.0,
|
| 106 |
-
}
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
**Por defecto usa Llama 2 7B Local con quantización 8-bit**
|
| 110 |
-
|
| 111 |
-
---
|
| 112 |
-
|
| 113 |
-
## 📊 Comparación: Local vs API
|
| 114 |
-
|
| 115 |
-
| Aspecto | Modelo LOCAL | API Externa |
|
| 116 |
-
|---------|--------------|-------------|
|
| 117 |
-
| **Configuración** | `USE_LOCAL_MODEL = True` | `USE_API_MODEL = True` |
|
| 118 |
-
| **Módulo usado** | `model_llama_local.py` | `model.py` |
|
| 119 |
-
| **Secret requerido** | `HF_TOKEN` | `GEMINI_API_KEY` (u otros) |
|
| 120 |
-
| **Primera carga** | ⏳ 30-60s | ⚡ Instantánea |
|
| 121 |
-
| **Velocidad (después)** | ⚡ 1-2s/pregunta | 🐌 2-5s/pregunta |
|
| 122 |
-
| **Rate limits** | ❌ Ninguno | ✅ Sí (según proveedor) |
|
| 123 |
-
| **RAM usada** | 💾 ~7-10GB | 💾 ~1-2GB |
|
| 124 |
-
| **Accuracy estimada** | 🎯 10-20% | 🎯 15-30% |
|
| 125 |
-
| **Costo** | 💰 Gratis | 💰 Gratis/Pagado |
|
| 126 |
-
|
| 127 |
-
---
|
| 128 |
-
|
| 129 |
-
## 🔄 Para Cambiar de Modelo
|
| 130 |
-
|
| 131 |
-
### Opción 1: Cambiar a Local
|
| 132 |
-
```python
|
| 133 |
-
# En config.py
|
| 134 |
-
USE_LOCAL_MODEL = True
|
| 135 |
-
USE_API_MODEL = False
|
| 136 |
-
```
|
| 137 |
-
Secret: `HF_TOKEN`
|
| 138 |
-
|
| 139 |
-
### Opción 2: Cambiar a Gemini
|
| 140 |
-
```python
|
| 141 |
-
# En config.py
|
| 142 |
-
USE_LOCAL_MODEL = False
|
| 143 |
-
USE_API_MODEL = True
|
| 144 |
-
API_MODEL_CONFIG = {
|
| 145 |
-
"model_id": "gemini/gemini-2.0-flash-exp",
|
| 146 |
-
...
|
| 147 |
-
}
|
| 148 |
-
```
|
| 149 |
-
Secret: `GEMINI_API_KEY`
|
| 150 |
-
|
| 151 |
-
### Opción 3: Cambiar a GPT-4
|
| 152 |
-
```python
|
| 153 |
-
# En config.py
|
| 154 |
-
USE_LOCAL_MODEL = False
|
| 155 |
-
USE_API_MODEL = True
|
| 156 |
-
API_MODEL_CONFIG = {
|
| 157 |
-
"model_id": "gpt-4o-mini",
|
| 158 |
-
...
|
| 159 |
-
}
|
| 160 |
-
```
|
| 161 |
-
Secret: `OPENAI_API_KEY`
|
| 162 |
-
|
| 163 |
-
---
|
| 164 |
-
|
| 165 |
-
## 🧪 Testing Recomendado
|
| 166 |
-
|
| 167 |
-
1. **Test con Gemini (API)** - Baseline
|
| 168 |
-
- Configurar `USE_API_MODEL = True`
|
| 169 |
-
- Ejecutar 20 preguntas
|
| 170 |
-
- Medir accuracy (esperado: ~15%)
|
| 171 |
-
|
| 172 |
-
2. **Test con Llama 2 Local**
|
| 173 |
-
- Configurar `USE_LOCAL_MODEL = True`
|
| 174 |
-
- Ejecutar 20 preguntas
|
| 175 |
-
- Medir accuracy (esperado: ~10-20%)
|
| 176 |
-
- Comparar velocidad
|
| 177 |
-
|
| 178 |
-
3. **Comparar resultados**
|
| 179 |
-
- ¿Local es más rápido?
|
| 180 |
-
- ¿Accuracy es similar?
|
| 181 |
-
- ¿Hay problemas de memoria?
|
| 182 |
-
|
| 183 |
-
---
|
| 184 |
-
|
| 185 |
-
## 📝 Próximos Pasos
|
| 186 |
-
|
| 187 |
-
1. **Desplegar a HuggingFace Spaces**
|
| 188 |
-
```bash
|
| 189 |
-
git add .
|
| 190 |
-
git commit -m "Add flexible model system (local + API)"
|
| 191 |
-
git push
|
| 192 |
-
```
|
| 193 |
-
|
| 194 |
-
2. **Configurar HF_TOKEN en Secrets**
|
| 195 |
-
- Settings → Repository secrets
|
| 196 |
-
- Agregar `HF_TOKEN`
|
| 197 |
-
|
| 198 |
-
3. **Probar con modelo LOCAL**
|
| 199 |
-
- Primera ejecución: esperar 30-60s
|
| 200 |
-
- Verificar logs: "🦙 Cargando..."
|
| 201 |
-
- Medir velocidad y accuracy
|
| 202 |
-
|
| 203 |
-
4. **Si funciona bien, considerar**:
|
| 204 |
-
- Probar Llama 2 13B (más potente, ~13GB RAM)
|
| 205 |
-
- Comparar con Gemini
|
| 206 |
-
- Optimizar prompts específicos para Llama
|
| 207 |
-
|
| 208 |
-
---
|
| 209 |
-
|
| 210 |
-
## ✅ Ventajas de Esta Implementación
|
| 211 |
-
|
| 212 |
-
1. **Flexibilidad Total**: Cambia de modelo en segundos
|
| 213 |
-
2. **Sin Romper Nada**: Mantiene compatibilidad con código existente
|
| 214 |
-
3. **Documentación Completa**: README + GUIA_MODELOS.md
|
| 215 |
-
4. **Fácil Debug**: Mensajes informativos en logs
|
| 216 |
-
5. **Preparado para Escalar**: Fácil agregar más modelos
|
| 217 |
-
|
| 218 |
-
---
|
| 219 |
-
|
| 220 |
-
## 🎉 Estado Final
|
| 221 |
-
|
| 222 |
-
- ✅ Sistema de configuración implementado
|
| 223 |
-
- ✅ Modelo local (Llama 2) soportado
|
| 224 |
-
- ✅ APIs externas (Gemini/GPT/Claude) soportadas
|
| 225 |
-
- ✅ Documentación completa
|
| 226 |
-
- ✅ Sin errores de sintaxis
|
| 227 |
-
- ✅ Listo para desplegar
|
| 228 |
-
|
| 229 |
-
**¡Listo para probar en HuggingFace Spaces!** 🚀
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RESUMEN_IMPLEMENTACION.md
CHANGED
|
@@ -1,51 +1,44 @@
|
|
| 1 |
# 📝 Resumen de Implementación - Agente GAIA con Gemini
|
| 2 |
|
| 3 |
-
## 🎯 Objetivo
|
| 4 |
|
| 5 |
-
Crear un agente AI que resuelva tareas del benchmark GAIA Level 1 usando **Google Gemini**
|
|
|
|
|
|
|
| 6 |
|
| 7 |
## 🏗️ Arquitectura del Sistema
|
| 8 |
|
| 9 |
```
|
| 10 |
┌─────────────────────────────────────────────────────────────┐
|
| 11 |
│ app.py (Gradio UI) │
|
| 12 |
-
│ - OAuth Login
|
| 13 |
│ - Botón ejecutar evaluación │
|
|
|
|
| 14 |
│ - Tabla de resultados │
|
| 15 |
└─────────────────────┬───────────────────────────────────────┘
|
| 16 |
│
|
| 17 |
▼
|
| 18 |
┌─────────────────────────────────────────────────────────────┐
|
| 19 |
│ agents.py (Agent Class) │
|
|
|
|
| 20 |
│ - System prompt optimizado para GAIA │
|
| 21 |
│ - Construcción de contexto (pregunta + archivos) │
|
| 22 |
-
│ - Limpieza de respuestas
|
|
|
|
| 23 |
└─────────────────────┬───────────────────────────────────────┘
|
| 24 |
│
|
| 25 |
┌─────────────┼─────────────┐
|
| 26 |
▼ ▼ ▼
|
| 27 |
┌──────────────┐ ┌──────────┐ ┌──────────────────┐
|
| 28 |
-
│ model.py │ │ tool.py │ │
|
| 29 |
│ │ │ │ │ │
|
| 30 |
-
│ GeminiModel │ │ Tools
|
| 31 |
-
│ - LiteLLM │ │ Registry │ │
|
| 32 |
-
│ - Retry
|
| 33 |
-
│
|
| 34 |
-
│
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
└───────┬───────┘
|
| 38 |
-
▼
|
| 39 |
-
┌───────────────────────┐
|
| 40 |
-
│ tools.py │
|
| 41 |
-
│ │
|
| 42 |
-
│ - read_image_text() │
|
| 43 |
-
│ (OCR con Tesseract) │
|
| 44 |
-
│ - BytesIO handling │
|
| 45 |
-
└───────────────────────┘
|
| 46 |
-
│
|
| 47 |
-
▼
|
| 48 |
-
┌───────────────────────┐
|
| 49 |
│ api.py │
|
| 50 |
│ │
|
| 51 |
│ - get_questions() │
|
|
@@ -53,169 +46,221 @@ Crear un agente AI que resuelva tareas del benchmark GAIA Level 1 usando **Googl
|
|
| 53 |
└───────────────────────┘
|
| 54 |
```
|
| 55 |
|
| 56 |
-
## 📦 Componentes
|
| 57 |
|
| 58 |
### 1. `model.py` - Wrapper de Gemini
|
| 59 |
|
| 60 |
**Propósito**: Abstracción para llamar a Google Gemini con manejo robusto de errores.
|
| 61 |
|
| 62 |
**Características**:
|
| 63 |
-
- Usa **LiteLLM** para interfaz unificada
|
| 64 |
-
- Retry logic con
|
| 65 |
-
-
|
| 66 |
-
-
|
| 67 |
|
| 68 |
-
**Modelo
|
| 69 |
-
-
|
| 70 |
-
-
|
| 71 |
-
-
|
|
|
|
| 72 |
|
| 73 |
### 2. `agents.py` - Clase Agent Principal
|
| 74 |
|
| 75 |
-
**Propósito**:
|
| 76 |
|
| 77 |
**System Prompt**:
|
| 78 |
-
- Optimizado para benchmark GAIA
|
| 79 |
-
- Énfasis en precisión y formato estricto
|
| 80 |
-
- Instrucciones de "FINAL ANSWER:" obligatorio
|
| 81 |
-
|
| 82 |
-
**Métodos clave**:
|
| 83 |
-
- `_build_context()`: Construye el prompt con pregunta y archivos
|
| 84 |
-
- `_clean_answer()`: Extrae respuesta final con regex
|
| 85 |
-
- `_is_reversed_text()`: Detecta texto al revés (common GAIA trick)
|
| 86 |
-
|
| 87 |
-
### 3. `tools.py` - Procesamiento de Archivos
|
| 88 |
-
|
| 89 |
-
**Propósito**: OCR de imágenes y manejo de archivos.
|
| 90 |
-
|
| 91 |
-
**Fix aplicado**:
|
| 92 |
```python
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
```
|
| 95 |
|
| 96 |
-
**
|
| 97 |
-
- `
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
**Propósito**: UI web con OAuth y evaluación automática.
|
| 121 |
|
| 122 |
**Características**:
|
| 123 |
- **OAuth de HuggingFace**: Login obligatorio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
- **Flujo completo**:
|
| 125 |
-
1. Login usuario
|
| 126 |
-
2. Obtener preguntas
|
| 127 |
-
3. Procesar con agente
|
| 128 |
-
4. Enviar respuestas
|
| 129 |
-
5. Mostrar resultados
|
| 130 |
-
- **Manejo de errores**: Try-except en cada paso
|
| 131 |
-
- **Logging**: Prints informativos para debugging
|
| 132 |
|
| 133 |
-
###
|
| 134 |
|
| 135 |
-
```
|
| 136 |
gradio>=5.0.0 # Web UI
|
| 137 |
-
|
|
|
|
| 138 |
google-generativeai>=0.8.0 # Gemini SDK
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
pandas>=2.0.0 # DataFrames
|
| 140 |
-
|
| 141 |
-
pillow>=10.0.0 # Imágenes
|
| 142 |
pytesseract>=0.3.10 # OCR
|
|
|
|
|
|
|
| 143 |
python-dotenv>=1.0.0 # .env files
|
| 144 |
```
|
| 145 |
|
| 146 |
-
###
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
hf_oauth_expiration_minutes: 480 # 8 horas
|
| 152 |
-
sdk: gradio
|
| 153 |
-
sdk_version: 5.49.1
|
| 154 |
```
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
| Aspecto | OpenAI (antes) | Gemini (ahora) |
|
| 159 |
-
|---------|---------------|----------------|
|
| 160 |
-
| **Modelo** | `gpt-4o-mini` | `gemini-2.0-flash-exp` |
|
| 161 |
-
| **SDK** | `openai` | `litellm` + `google-generativeai` |
|
| 162 |
-
| **API Key** | `OPENAI_API_KEY` | `GEMINI_API_KEY` |
|
| 163 |
-
| **Costo** | Pago ($) | Gratis (con límites) |
|
| 164 |
-
| **Inicialización** | `OpenAI(api_key=...)` | `litellm.completion(model="gemini/...")` |
|
| 165 |
-
| **Rate Limits** | Más altos (pago) | 60 req/min (gratis) |
|
| 166 |
|
| 167 |
-
##
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
- Clic en botón "Ejecutar"
|
| 175 |
-
- `run_and_submit_all()` se ejecuta
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
-
- `process_question()` para cada una
|
| 183 |
-
- Agent construye prompt
|
| 184 |
-
- Gemini genera respuesta
|
| 185 |
-
- Validaciones GAIA aplicadas
|
| 186 |
-
- Extracción de "FINAL ANSWER:"
|
| 187 |
|
| 188 |
-
|
| 189 |
-
- POST request a API del curso
|
| 190 |
-
- Payload: username, agent_code, answers
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
## 🛡️ Manejo de Errores
|
| 197 |
|
| 198 |
### Rate Limits
|
| 199 |
```python
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
```
|
| 207 |
|
| 208 |
### Errores de Red
|
| 209 |
-
- Timeout de
|
| 210 |
- Try-except en cada llamada HTTP
|
| 211 |
-
- Mensajes de error informativos
|
| 212 |
-
|
| 213 |
-
### Errores de Gemini
|
| 214 |
-
- Retry automático hasta 3 veces
|
| 215 |
-
- Backoff exponencial (2^attempt segundos)
|
| 216 |
-
- Logging de errores para debugging
|
| 217 |
|
| 218 |
-
##
|
| 219 |
|
| 220 |
El agente cumple con las **reglas estrictas de GAIA**:
|
| 221 |
|
|
@@ -223,70 +268,92 @@ El agente cumple con las **reglas estrictas de GAIA**:
|
|
| 223 |
- ❌ `1,234 meters`
|
| 224 |
- ✅ `1234`
|
| 225 |
|
| 226 |
-
- **Strings**:
|
| 227 |
- ❌ `The Eiffel Tower`
|
| 228 |
-
- ✅ `
|
| 229 |
|
| 230 |
- **Listas**: Comas sin espacios, sin corchetes
|
| 231 |
- ❌ `[apple, banana]`
|
| 232 |
- ✅ `apple,banana`
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
1. **Settings → Repository secrets**:
|
| 239 |
-
- `GEMINI_API_KEY`: Tu API key de Google
|
| 240 |
-
|
| 241 |
-
2. **README.md** (metadata):
|
| 242 |
-
- `hf_oauth: true`
|
| 243 |
-
- `sdk: gradio`
|
| 244 |
-
|
| 245 |
-
### Variables de Entorno Automáticas
|
| 246 |
-
|
| 247 |
-
HF Spaces configura automáticamente:
|
| 248 |
-
- `SPACE_ID`: `usuario/nombre-space`
|
| 249 |
-
- `SPACE_HOST`: `nombre-space-usuario.hf.space`
|
| 250 |
-
|
| 251 |
-
Usadas para construir el link del código del agente.
|
| 252 |
|
| 253 |
-
##
|
| 254 |
|
| 255 |
-
|
| 256 |
-
# 1. Instalar dependencias
|
| 257 |
-
pip install -r requirements.txt
|
| 258 |
-
|
| 259 |
-
# 2. Configurar API key
|
| 260 |
-
export GEMINI_API_KEY="tu_api_key_aqui"
|
| 261 |
-
|
| 262 |
-
# 3. Ejecutar app
|
| 263 |
-
python app.py
|
| 264 |
-
|
| 265 |
-
# 4. Abrir navegador
|
| 266 |
-
# http://localhost:7860
|
| 267 |
```
|
|
|
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
-
|
| 281 |
|
| 282 |
-
|
| 283 |
-
-
|
| 284 |
-
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
---
|
| 289 |
|
| 290 |
-
**Implementado**:
|
| 291 |
-
**
|
|
|
|
|
|
|
|
|
|
| 292 |
**Licencia**: MIT
|
|
|
|
| 1 |
# 📝 Resumen de Implementación - Agente GAIA con Gemini
|
| 2 |
|
| 3 |
+
## 🎯 Objetivo Cumplido ✅
|
| 4 |
|
| 5 |
+
Crear un agente AI que resuelva tareas del benchmark GAIA Level 1 usando **Google Gemini** para el curso de Agentes de HuggingFace (Unit 4 Hands-on).
|
| 6 |
+
|
| 7 |
+
**🏆 RESULTADO FINAL: 30% de precisión (6/20 preguntas correctas) - META ALCANZADA**
|
| 8 |
|
| 9 |
## 🏗️ Arquitectura del Sistema
|
| 10 |
|
| 11 |
```
|
| 12 |
┌─────────────────────────────────────────────────────────────┐
|
| 13 |
│ app.py (Gradio UI) │
|
| 14 |
+
│ - OAuth Login con HuggingFace │
|
| 15 |
│ - Botón ejecutar evaluación │
|
| 16 |
+
│ - Logs mejorados con timestamps y emojis │
|
| 17 |
│ - Tabla de resultados │
|
| 18 |
└─────────────────────┬───────────────────────────────────────┘
|
| 19 |
│
|
| 20 |
▼
|
| 21 |
┌─────────────────────────────────────────────────────────────┐
|
| 22 |
│ agents.py (Agent Class) │
|
| 23 |
+
│ - Usa smolagents CodeAgent │
|
| 24 |
│ - System prompt optimizado para GAIA │
|
| 25 |
│ - Construcción de contexto (pregunta + archivos) │
|
| 26 |
+
│ - Limpieza de respuestas automática │
|
| 27 |
+
│ - Detección de texto invertido │
|
| 28 |
└─────────────────────┬───────────────────────────────────────┘
|
| 29 |
│
|
| 30 |
┌─────────────┼─────────────┐
|
| 31 |
▼ ▼ ▼
|
| 32 |
┌──────────────┐ ┌──────────┐ ┌──────────────────┐
|
| 33 |
+
│ model.py │ │ tool.py │ │ tools/tools.py │
|
| 34 |
│ │ │ │ │ │
|
| 35 |
+
│ GeminiModel │ │ 15 Tools │ │ Custom Tools: │
|
| 36 |
+
│ - LiteLLM │ │ Registry │ │ - vision_tool │
|
| 37 |
+
│ - Retry 5x │ │ │ │ - youtube tools │
|
| 38 |
+
│ logic │ │ Base: │ │ - audio_to_text │
|
| 39 |
+
│ │ │ -DuckDuck│ │ - OCR │
|
| 40 |
+
│ │ │ -Wikipedia│ │ - Excel/CSV │
|
| 41 |
+
└──────────────┘ └──────────┘ └──────────────────┘────┐
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
│ api.py │
|
| 43 |
│ │
|
| 44 |
│ - get_questions() │
|
|
|
|
| 46 |
└───────────────────────┘
|
| 47 |
```
|
| 48 |
|
| 49 |
+
## 📦 Componentes Principales
|
| 50 |
|
| 51 |
### 1. `model.py` - Wrapper de Gemini
|
| 52 |
|
| 53 |
**Propósito**: Abstracción para llamar a Google Gemini con manejo robusto de errores.
|
| 54 |
|
| 55 |
**Características**:
|
| 56 |
+
- Usa **LiteLLM** para interfaz unificada con Gemini
|
| 57 |
+
- Retry logic: 5 intentos con manejo de RateLimitError
|
| 58 |
+
- Factory pattern: `get_model("LiteLLMModel", model_id)`
|
| 59 |
+
- Soporte para modelos locales también
|
| 60 |
|
| 61 |
+
**Modelo final**: `gemini/gemini-2.5-flash`
|
| 62 |
+
- Modelo más avanzado de Google (2025)
|
| 63 |
+
- Optimizado para razonamiento y uso de herramientas
|
| 64 |
+
- 10 requests/minuto (Free Tier)
|
| 65 |
+
- Ideal para tareas GAIA
|
| 66 |
|
| 67 |
### 2. `agents.py` - Clase Agent Principal
|
| 68 |
|
| 69 |
+
**Propósito**: Wrapper de smolagents CodeAgent con prompts GAIA-específicos.
|
| 70 |
|
| 71 |
**System Prompt**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
```python
|
| 73 |
+
base_prompt = """
|
| 74 |
+
You are an advanced AI assistant specialized in solving GAIA benchmark tasks
|
| 75 |
+
with maximum precision.
|
| 76 |
+
|
| 77 |
+
CRITICAL RULES FOR GAIA:
|
| 78 |
+
1. EXACT ANSWER ONLY - Return ONLY the precise answer, no explanations
|
| 79 |
+
2. FORMAT MATTERS - Your answer will be compared using exact string matching
|
| 80 |
+
3. USE TOOLS when needed (vision, YouTube, audio, OCR, web search, etc.)
|
| 81 |
+
4. PROCESS FILES - If files are provided, analyze them thoroughly
|
| 82 |
+
5. NO HALLUCINATION - If you don't know, use tools to find the answer
|
| 83 |
+
6. ALWAYS use final_answer() to return your result
|
| 84 |
+
"""
|
| 85 |
```
|
| 86 |
|
| 87 |
+
**Métodos clave**:
|
| 88 |
+
- `__call__(question, files)`: Interfaz principal con logging mejorado
|
| 89 |
+
- `answer_question()`: Procesa pregunta con el CodeAgent
|
| 90 |
+
- `_build_context()`: Construye prompt con pregunta y archivos
|
| 91 |
+
- `_clean_answer()`: Limpieza de respuestas (remove prefixes, brackets, quotes)
|
| 92 |
+
- `_is_reversed_text()`: Detecta texto invertido (truco común en GAIA)
|
| 93 |
+
|
| 94 |
+
### 3. `tool.py` - Registro de 15 Herramientas
|
| 95 |
+
|
| 96 |
+
**Propósito**: Proporcionar toolkit completo al agente.
|
| 97 |
+
|
| 98 |
+
**Herramientas Base (smolagents)**:
|
| 99 |
+
1. `FinalAnswerTool()` - Dar respuesta final
|
| 100 |
+
2. `DuckDuckGoSearchTool()` - Búsqueda web
|
| 101 |
+
3. `PythonInterpreterTool()` - Ejecutar código Python
|
| 102 |
+
4. `WikipediaSearchTool()` - Búsqueda en Wikipedia
|
| 103 |
+
5. `VisitWebpageTool()` - Visitar páginas web
|
| 104 |
+
|
| 105 |
+
**Herramientas Custom (tools/tools.py)**:
|
| 106 |
+
6. `vision_tool` - Análisis de imágenes con Gemini multimodal
|
| 107 |
+
7. `youtube_frames_to_images` - Extraer frames de videos
|
| 108 |
+
8. `ask_youtube_video` - Hacer preguntas sobre videos
|
| 109 |
+
9. `transcribe_youtube` - Transcribir audio de videos
|
| 110 |
+
10. `audio_to_text` - Convertir audio a texto (Whisper)
|
| 111 |
+
11. `extract_text_via_ocr` - OCR con Tesseract
|
| 112 |
+
12. `summarize_csv_data` - Analizar archivos CSV
|
| 113 |
+
13. `summarize_excel_data` - Analizar archivos Excel
|
| 114 |
+
14. `read_text_file` - Leer archivos de texto
|
| 115 |
+
15. `file_from_url` - Descargar archivos desde URLs
|
| 116 |
+
|
| 117 |
+
### 4. `app.py` - Interfaz Gradio con Logging Mejorado
|
| 118 |
|
| 119 |
**Propósito**: UI web con OAuth y evaluación automática.
|
| 120 |
|
| 121 |
**Características**:
|
| 122 |
- **OAuth de HuggingFace**: Login obligatorio
|
| 123 |
+
- **Logging mejorado**:
|
| 124 |
+
- Timestamps en formato `[HH:MM:SS]`
|
| 125 |
+
- Emojis para identificación visual (ℹ️✅❌🔄⏳📊)
|
| 126 |
+
- Progress tracking: `[1/20]` con tiempo estimado
|
| 127 |
+
- Separadores visuales con `=` lines
|
| 128 |
+
- **Rate limiting**: 20 segundos entre preguntas (10 req/min límite)
|
| 129 |
- **Flujo completo**:
|
| 130 |
+
1. Login usuario → `✅ User authenticated: {username}`
|
| 131 |
+
2. Obtener preguntas → `✅ Fetched 20 questions from server`
|
| 132 |
+
3. Procesar con agente → `🔄 [1/20] Starting question 1`
|
| 133 |
+
4. Enviar respuestas → `📤 Submitting to scoring server`
|
| 134 |
+
5. Mostrar resultados → `🎉 SUBMISSION SUCCESSFUL! 📊 Score: 30.0%`
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
### 5. `requirements.txt` - Dependencias
|
| 137 |
|
| 138 |
+
```txt
|
| 139 |
gradio>=5.0.0 # Web UI
|
| 140 |
+
smolagents>=0.1.0 # Agent framework
|
| 141 |
+
litellm>=1.0.0 # LLM wrapper unificado
|
| 142 |
google-generativeai>=0.8.0 # Gemini SDK
|
| 143 |
+
yt-dlp>=2023.0.0 # YouTube downloader
|
| 144 |
+
openai-whisper>=20231117 # Audio transcription
|
| 145 |
+
imageio>=2.31.0 # Image/video I/O
|
| 146 |
+
imageio-ffmpeg>=0.4.9 # Video codec
|
| 147 |
+
ffmpeg-python>=0.2.0 # FFmpeg wrapper
|
| 148 |
+
numpy>=1.24.0 # Numerical computing
|
| 149 |
+
youtube-transcript-api>=0.6.0 # YouTube transcripts
|
| 150 |
+
ddgs>=0.0.1 # DuckDuckGo search
|
| 151 |
+
wikipedia-api>=0.5.0 # Wikipedia API
|
| 152 |
+
torch>=2.0.0 # PyTorch (for Whisper)
|
| 153 |
+
transformers>=4.30.0 # HF Transformers
|
| 154 |
pandas>=2.0.0 # DataFrames
|
| 155 |
+
pillow>=10.0.0 # Image processing
|
|
|
|
| 156 |
pytesseract>=0.3.10 # OCR
|
| 157 |
+
openpyxl>=3.1.0 # Excel files
|
| 158 |
+
requests>=2.31.0 # HTTP
|
| 159 |
python-dotenv>=1.0.0 # .env files
|
| 160 |
```
|
| 161 |
|
| 162 |
+
### 6. `packages.txt` - Dependencias del Sistema
|
| 163 |
|
| 164 |
+
```txt
|
| 165 |
+
ffmpeg # Video/audio processing
|
| 166 |
+
tesseract-ocr # OCR engine
|
|
|
|
|
|
|
|
|
|
| 167 |
```
|
| 168 |
|
| 169 |
+
**Nota**: HuggingFace Spaces instala automáticamente estos paquetes con `apt-get`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
+
## 🔑 Modelo y Rate Limits
|
| 172 |
|
| 173 |
+
| Aspecto | Configuración Final |
|
| 174 |
+
|---------|---------------------|
|
| 175 |
+
| **Modelo** | `gemini/gemini-2.5-flash` |
|
| 176 |
+
| **SDK** | `litellm` + `google-generativeai` + `smolagents` |
|
| 177 |
+
| **API Key** | `GEMINI_API_KEY` (en HF Secrets) |
|
| 178 |
+
| **Costo** | Gratis (Free Tier) |
|
| 179 |
+
| **Rate Limit** | 10 requests/minuto |
|
| 180 |
+
| **Delay entre preguntas** | 20 segundos |
|
| 181 |
+
| **Retry logic** | 5 intentos con manejo de RateLimitError |
|
| 182 |
+
| **Tiempo total evaluación** | ~8-10 minutos para 20 preguntas |
|
| 183 |
|
| 184 |
+
## 🚀 Flujo de Ejecución Exitoso
|
|
|
|
|
|
|
| 185 |
|
| 186 |
+
```
|
| 187 |
+
[07:27:00] ℹ️ 🚀 GAIA BENCHMARK EVALUATION STARTED
|
| 188 |
+
[07:27:00] ✅ User authenticated: MalcomNavarro
|
| 189 |
+
[07:27:01] ✅ Agent initialized with model: gemini/gemini-2.5-flash
|
| 190 |
+
[07:27:01] ℹ️ Tools loaded: 15 tools available
|
| 191 |
+
[07:27:02] ✅ Fetched 20 questions from server
|
| 192 |
+
[07:27:02] ℹ️ Questions include: 5 with files
|
| 193 |
+
|
| 194 |
+
[07:27:02] ℹ️ 🤖 STARTING AGENT EVALUATION
|
| 195 |
+
[07:27:02] ℹ️ Model: gemini/gemini-2.5-flash
|
| 196 |
+
[07:27:02] ℹ️ Rate limit: 10 requests/minute (Free Tier)
|
| 197 |
+
|
| 198 |
+
[07:27:02] 🔄 [1/20] Starting question 1
|
| 199 |
+
[07:27:02] ℹ️ Processing task abc123
|
| 200 |
+
[07:27:02] ℹ️ Question: How many studio albums were published...
|
| 201 |
+
[07:27:15] ✅ Task abc123 completed: 3
|
| 202 |
+
[07:27:15] ℹ️ ⏳ Waiting 20 seconds before next question
|
| 203 |
+
[07:27:15] ℹ️ 📊 Progress: 1/20 completed | 19 remaining (~6 min left)
|
| 204 |
+
|
| 205 |
+
... (18 preguntas más) ...
|
| 206 |
+
|
| 207 |
+
[07:27:25] ✅ All 20 questions processed!
|
| 208 |
+
|
| 209 |
+
[07:27:26] ℹ️ 📤 PREPARING SUBMISSION
|
| 210 |
+
[07:27:26] ℹ️ User: MalcomNavarro
|
| 211 |
+
[07:27:26] ℹ️ Answers ready: 20
|
| 212 |
+
[07:27:27] ℹ️ Submitting to scoring server...
|
| 213 |
+
|
| 214 |
+
[07:27:28] ✅ 🎉 SUBMISSION SUCCESSFUL!
|
| 215 |
+
[07:27:28] ✅ 📊 Score: 30.0% (6/20 correct)
|
| 216 |
+
[07:27:28] ℹ️ Message: Score calculated successfully
|
| 217 |
+
```
|
| 218 |
|
| 219 |
+
## 📊 Resultados Finales
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
+
**🎯 META ALCANZADA: 30% de precisión**
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
- **Total de preguntas**: 20
|
| 224 |
+
- **Respuestas correctas**: 6
|
| 225 |
+
- **Score**: 30.0%
|
| 226 |
+
- **Usuario**: MalcomNavarro
|
| 227 |
+
- **Fecha**: Octubre 2025
|
| 228 |
+
- **Modelo usado**: Gemini 2.5 Flash
|
| 229 |
|
| 230 |
+
## 🛡️ Manejo de Errores Implementado
|
| 231 |
|
| 232 |
### Rate Limits
|
| 233 |
```python
|
| 234 |
+
# En model.py - WrapperLiteLLMModel
|
| 235 |
+
for attempt in range(self.max_retries):
|
| 236 |
+
try:
|
| 237 |
+
return super().__call__(messages, **kwargs)
|
| 238 |
+
except Exception as e:
|
| 239 |
+
if "RateLimitError" in str(type(e)):
|
| 240 |
+
if attempt < self.max_retries - 1:
|
| 241 |
+
wait_time = 2 ** attempt # Exponential backoff
|
| 242 |
+
time.sleep(wait_time)
|
| 243 |
+
continue
|
| 244 |
+
raise e
|
| 245 |
+
```
|
| 246 |
+
|
| 247 |
+
### Delays entre preguntas
|
| 248 |
+
```python
|
| 249 |
+
# En app.py - run_questions_async
|
| 250 |
+
if idx < total_questions:
|
| 251 |
+
remaining = total_questions - idx
|
| 252 |
+
estimated_time = remaining * 20 // 60
|
| 253 |
+
log_info(f"⏳ Waiting 20 seconds (Rate limit: 10 req/min)")
|
| 254 |
+
log_info(f"📊 Progress: {idx}/{total_questions} | ~{estimated_time} min left")
|
| 255 |
+
await asyncio.sleep(20)
|
| 256 |
```
|
| 257 |
|
| 258 |
### Errores de Red
|
| 259 |
+
- Timeout de 15-60s en requests
|
| 260 |
- Try-except en cada llamada HTTP
|
| 261 |
+
- Mensajes de error informativos con logging mejorado
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
+
## � Formato GAIA
|
| 264 |
|
| 265 |
El agente cumple con las **reglas estrictas de GAIA**:
|
| 266 |
|
|
|
|
| 268 |
- ❌ `1,234 meters`
|
| 269 |
- ✅ `1234`
|
| 270 |
|
| 271 |
+
- **Strings**: Lowercase, sin artículos
|
| 272 |
- ❌ `The Eiffel Tower`
|
| 273 |
+
- ✅ `eiffel tower`
|
| 274 |
|
| 275 |
- **Listas**: Comas sin espacios, sin corchetes
|
| 276 |
- ❌ `[apple, banana]`
|
| 277 |
- ✅ `apple,banana`
|
| 278 |
|
| 279 |
+
- **Yes/No**: Lowercase
|
| 280 |
+
- ❌ `Yes`
|
| 281 |
+
- ✅ `yes`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
+
## 🔧 Configuración en HuggingFace Spaces
|
| 284 |
|
| 285 |
+
### 1. Repository Secrets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
```
|
| 287 |
+
Settings → Repository secrets → Add a secret
|
| 288 |
|
| 289 |
+
Name: GEMINI_API_KEY
|
| 290 |
+
Value: AIza... (tu API key de Google AI Studio)
|
| 291 |
+
```
|
| 292 |
|
| 293 |
+
### 2. README.md (metadata)
|
| 294 |
+
```yaml
|
| 295 |
+
---
|
| 296 |
+
title: HF GAIA Agents Course MN
|
| 297 |
+
emoji: 🤖
|
| 298 |
+
colorFrom: blue
|
| 299 |
+
colorTo: green
|
| 300 |
+
sdk: gradio
|
| 301 |
+
sdk_version: 5.49.1
|
| 302 |
+
app_file: app.py
|
| 303 |
+
pinned: false
|
| 304 |
+
license: mit
|
| 305 |
+
hf_oauth: true
|
| 306 |
+
hf_oauth_expiration_minutes: 480
|
| 307 |
+
hf_oauth_scopes:
|
| 308 |
+
- read-repos
|
| 309 |
+
- write-repos
|
| 310 |
+
---
|
| 311 |
+
```
|
| 312 |
|
| 313 |
+
### 3. Variables de Entorno Automáticas
|
| 314 |
|
| 315 |
+
HF Spaces configura automáticamente:
|
| 316 |
+
- `SPACE_ID`: `MalcomNavarro/hf-gaia-agents-course-MN`
|
| 317 |
+
- `SPACE_HOST`: `malcomnavarro-hf-gaia-agents-course-mn.hf.space`
|
| 318 |
+
|
| 319 |
+
## 🎓 Lecciones Aprendidas
|
| 320 |
+
|
| 321 |
+
### ✅ Lo que funcionó bien:
|
| 322 |
+
1. **smolagents framework** - Excelente para manejar herramientas
|
| 323 |
+
2. **Gemini 2.5 Flash** - Buen balance costo/calidad para GAIA
|
| 324 |
+
3. **Logging mejorado** - Timestamps y emojis hacen debugging más fácil
|
| 325 |
+
4. **Rate limit handling** - Delays de 20s evitan errores 429
|
| 326 |
+
5. **Múltiples herramientas** - 15 tools cubren casos diversos
|
| 327 |
+
6. **Retry logic** - 5 intentos con backoff exponencial
|
| 328 |
+
|
| 329 |
+
### ⚠️ Desafíos enfrentados:
|
| 330 |
+
1. **Rate limits** - Free tier muy restrictivo (10 req/min)
|
| 331 |
+
2. **Nombres de modelos** - `gemini-2.0-flash-exp` deprecado → cambio a `2.5-flash`
|
| 332 |
+
3. **Dependencias ocultas** - `ddgs`, `wikipedia-api` no documentadas
|
| 333 |
+
4. **Tiempo de evaluación** - ~10 minutos por rate limits (no hay otra opción en free tier)
|
| 334 |
+
|
| 335 |
+
### 💡 Recomendaciones futuras:
|
| 336 |
+
1. **Usar API key paga** - 250 req/min vs 10 req/min (25x más rápido)
|
| 337 |
+
2. **Cachear respuestas** - Evitar re-procesar preguntas iguales
|
| 338 |
+
3. **Batch processing** - Procesar múltiples preguntas en paralelo (con API key paga)
|
| 339 |
+
4. **Mejorar prompts** - Más ejemplos específicos de GAIA en system prompt
|
| 340 |
+
5. **Fine-tuning** - Entrenar modelo específico para GAIA
|
| 341 |
+
|
| 342 |
+
## 🎉 Conclusión
|
| 343 |
+
|
| 344 |
+
✅ **Implementación exitosa del agente GAIA con Gemini**
|
| 345 |
+
✅ **Meta del 30% alcanzada (6/20 correctas)**
|
| 346 |
+
✅ **Código limpio, bien documentado y mantenible**
|
| 347 |
+
✅ **Logs informativos para debugging**
|
| 348 |
+
✅ **Manejo robusto de errores y rate limits**
|
| 349 |
+
|
| 350 |
+
**Stack Final**: Python 3.10+, Gradio 5.x, Google Gemini 2.5 Flash, LiteLLM, smolagents
|
| 351 |
|
| 352 |
---
|
| 353 |
|
| 354 |
+
**Implementado**: Octubre 2025
|
| 355 |
+
**Curso**: HuggingFace Agents Course - Unit 4
|
| 356 |
+
**Repositorio**: https://huggingface.co/spaces/MalcomNavarro/hf-gaia-agents-course-MN
|
| 357 |
+
**Score**: 30.0% (6/20 correctas) ✅
|
| 358 |
+
**Malcom Navarro**
|
| 359 |
**Licencia**: MIT
|