File size: 7,888 Bytes
22ca508 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
#!/bin/bash
# 🔧 Script de gestión de repositorios para GPT Local
# Automatiza la creación y configuración de repositorios en GitHub y Hugging Face
set -e
# Cargar variables de entorno
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
fi
# Colores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Función para crear repositorio en GitHub
create_github_repo() {
local repo_name=${1:-"gpt-local"}
local description="🤖 Sistema de chat GPT local con Hugging Face - Soporte Docker, CLI y múltiples modelos"
print_status "Creando repositorio en GitHub: $repo_name"
# Verificar autenticación
if ! gh auth status &> /dev/null; then
print_error "GitHub CLI no está autenticado"
print_status "Ejecuta: gh auth login --with-token"
return 1
fi
# Crear repositorio
if gh repo create "$repo_name" --description "$description" --public --clone=false; then
print_success "Repositorio '$repo_name' creado en GitHub"
# Configurar remoto
if git remote | grep -q "origin"; then
git remote set-url origin "https://github.com/$(gh api user --jq .login)/$repo_name.git"
else
git remote add origin "https://github.com/$(gh api user --jq .login)/$repo_name.git"
fi
print_success "Remoto configurado"
return 0
else
print_warning "El repositorio puede ya existir o hubo un error"
return 1
fi
}
# Función para crear repositorio en Hugging Face
create_huggingface_repo() {
local repo_name=${1:-"gpt-local"}
local repo_type=${2:-"space"} # space, model, dataset
print_status "Creando repositorio en Hugging Face: $repo_name"
# Verificar token
if [ -z "$HUGGINGFACE_TOKEN" ]; then
print_error "Token de Hugging Face no configurado"
print_status "Configura HUGGINGFACE_TOKEN en .env"
return 1
fi
# Crear repositorio usando API
case $repo_type in
"space")
print_status "Creando Hugging Face Space..."
if huggingface-cli upload . . --repo-id "$(huggingface-cli whoami | head -1)/$repo_name" --repo-type space --create; then
print_success "Hugging Face Space creado: https://huggingface.co/spaces/$(huggingface-cli whoami | head -1)/$repo_name"
else
print_warning "Error creando Space o ya existe"
fi
;;
"model")
print_status "Creando repositorio de modelo..."
# Para modelos fine-tuneados
;;
"dataset")
print_status "Creando repositorio de dataset..."
# Para datasets personalizados
;;
esac
}
# Función para configurar git
setup_git() {
print_status "Configurando Git..."
# Inicializar si no existe
if [ ! -d ".git" ]; then
git init
print_success "Repositorio Git inicializado"
fi
# Configurar gitignore si no existe
if [ ! -f ".gitignore" ]; then
cat > .gitignore << 'EOF'
# Tokens y configuración sensible
.env
*.token
.cache/
.secrets/
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Modelos y cache
models_cache/
models/*/
*.bin
*.safetensors
.cache/
huggingface_cache/
# Logs
*.log
logs/
.logs/
# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# Docker
.docker/
docker-data/
# Jupyter
.ipynb_checkpoints/
*.ipynb
# Test coverage
htmlcov/
.coverage
.coverage.*
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
EOF
print_success "Archivo .gitignore creado"
fi
# Agregar archivos
git add .
# Commit inicial si no hay commits
if ! git log --oneline -1 &> /dev/null; then
git commit -m "🚀 Initial commit: GPT Local project setup
- ✅ Complete project structure with models, UI, and config
- ✅ Docker support with multi-service configuration
- ✅ Hugging Face and GitHub integration
- ✅ Python CLI tools and utilities
- ✅ Multiple model support (DialoGPT, Mistral, Gemma)
- ✅ Terminal and web chat interfaces
- ✅ Apple Silicon MPS optimization
- ✅ Comprehensive documentation and setup scripts"
print_success "Commit inicial creado"
fi
}
# Función para hacer push completo
push_to_github() {
print_status "Subiendo código a GitHub..."
# Verificar que tenemos remoto
if ! git remote | grep -q "origin"; then
print_error "No hay remoto configurado. Ejecuta create_github_repo primero"
return 1
fi
# Push
if git push -u origin main 2>/dev/null || git push -u origin master 2>/dev/null; then
print_success "Código subido a GitHub exitosamente"
# Mostrar URL del repositorio
local repo_url=$(git remote get-url origin | sed 's/\.git$//')
print_status "Repositorio disponible en: $repo_url"
else
print_error "Error subiendo a GitHub"
return 1
fi
}
# Función para crear README de Hugging Face Space
create_huggingface_readme() {
cat > README_HF.md << 'EOF'
---
title: GPT Local Chat
emoji: 🤖
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.44.1
app_file: main.py
pinned: false
license: mit
tags:
- chatbot
- gpt
- huggingface
- pytorch
- transformers
- gradio
- spanish
- conversational-ai
---
# 🤖 GPT Local Chat
Un sistema de chat GPT local potenciado por modelos de Hugging Face.
## Características
- 💬 Chat conversacional en tiempo real
- 🤗 Múltiples modelos de Hugging Face
- 🍎 Optimizado para Apple Silicon (MPS)
- ⚡ GPU acceleration automática
- 🌐 Interfaz web moderna con Gradio
## Modelos Soportados
- DialoGPT (small/medium/large)
- Mistral 7B Instruct
- Google Gemma 2B
## Uso
Simplemente escribe tu mensaje y presiona Enter para chatear con el modelo.
## Código Fuente
El código completo está disponible en: [GitHub Repository](https://github.com/tu-usuario/gpt-local)
EOF
print_success "README de Hugging Face creado"
}
# Función principal
main() {
local action=${1:-"full"}
local repo_name=${2:-"gpt-local"}
print_status "🚀 Iniciando gestión de repositorios..."
case $action in
"github")
setup_git
create_github_repo "$repo_name"
push_to_github
;;
"huggingface")
create_huggingface_readme
create_huggingface_repo "$repo_name" "space"
;;
"full")
setup_git
create_github_repo "$repo_name"
push_to_github
create_huggingface_readme
create_huggingface_repo "$repo_name" "space"
;;
"setup")
setup_git
;;
"push")
push_to_github
;;
*)
echo "Uso: $0 [github|huggingface|full|setup|push] [nombre_repo]"
echo ""
echo "Comandos:"
echo " github - Crear solo repositorio GitHub"
echo " huggingface - Crear solo Hugging Face Space"
echo " full - Crear ambos repositorios"
echo " setup - Solo configurar Git local"
echo " push - Solo subir cambios a GitHub"
exit 1
;;
esac
print_success "✅ Gestión de repositorios completada!"
}
# Ejecutar script
main "$@"
|