#!/bin/bash set -e # Configuration SPACE_NAME="hpmor" HF_USERNAME="deenaik" # Your HuggingFace username echo "🚀 Deploying HPMOR Q&A to HuggingFace Spaces..." echo "" # Check if logged in echo "🔐 Checking HuggingFace authentication..." # Try different HF CLI commands if command -v hf &> /dev/null; then HF_CMD="hf" elif command -v huggingface-cli &> /dev/null; then HF_CMD="huggingface-cli" else echo "❌ HuggingFace CLI not found." echo "Please install: pip install huggingface_hub[cli]" exit 1 fi # Check authentication AUTH_CHECK_OUTPUT=$($HF_CMD auth whoami 2>&1) if [ $? -ne 0 ]; then echo "❌ Not logged in to HuggingFace." echo "Please run: $HF_CMD auth login" exit 1 fi # Extract username from output CURRENT_USER=$(echo "$AUTH_CHECK_OUTPUT" | head -n 1) if [ -z "$CURRENT_USER" ]; then CURRENT_USER="(authenticated)" fi echo "✅ Logged in as: $CURRENT_USER" echo "" # Ask for confirmation read -p "Deploy to space '${HF_USERNAME}/${SPACE_NAME}'? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "❌ Deployment cancelled" exit 1 fi # Create Space if it doesn't exist echo "📦 Creating/checking HuggingFace Space..." $HF_CMD space create $SPACE_NAME --sdk gradio 2>/dev/null || echo " (Space may already exist - continuing...)" echo "" # Copy files for deployment echo "📝 Preparing deployment files..." cp README_HF.md README.md cp requirements_hf.txt requirements.txt echo " ✓ Copied README_HF.md → README.md" echo " ✓ Copied requirements_hf.txt → requirements.txt" echo "" # Initialize git if needed if [ ! -d .git ]; then echo "🔧 Initializing git repository..." git init fi # Add HuggingFace remote echo "🔗 Setting up HuggingFace remote..." git remote remove space 2>/dev/null || true git remote add space https://huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME} echo "" # Stage files echo "📦 Staging files for deployment..." git add app.py README.md requirements.txt src/ data/ .gitignore .env.example echo " Files staged:" git status --short echo "" # Commit echo "💾 Creating commit..." git commit -m "Deploy: HPMOR Q&A chatbot - $(date +%Y-%m-%d)" || { echo " (No new changes to commit - using existing commit)" } echo "" # Push echo "🚀 Pushing to HuggingFace Spaces..." echo " This may take a few minutes..." git push --force space main echo "" echo "✅ Deployment complete!" echo "" echo "🌐 Your Space: https://huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}" echo "" echo "⚠️ IMPORTANT: Don't forget to set your GROQ_API_KEY!" echo " 1. Go to: https://huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}/settings" echo " 2. Navigate to 'Repository secrets'" echo " 3. Add secret: GROQ_API_KEY = your_groq_api_key" echo "" echo "Or run:" echo " ${HF_CMD} space secret set GROQ_API_KEY --space-id ${HF_USERNAME}/${SPACE_NAME}" echo "" echo "📊 Monitor build progress:" echo " https://huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}"