gpt-local / manage-repos.sh
DRDELATV's picture
Upload folder using huggingface_hub
22ca508 verified
#!/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 "$@"