hpmor / deploy.sh
deenaik's picture
Add huggingface-hub dependency to pyproject.toml and uv.lock for enhanced model support
a90f6af
#!/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 <your_key> --space-id ${HF_USERNAME}/${SPACE_NAME}"
echo ""
echo "πŸ“Š Monitor build progress:"
echo " https://huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}"