model / deploy-hf.sh
likhonsheikh's picture
Upload 10 files
aba8087 verified
#!/bin/bash
# Deploy to Hugging Face Spaces
set -e
echo "πŸ€— Deploying to Hugging Face Spaces"
echo "===================================="
# Check if git is configured
if ! git config user.email > /dev/null; then
echo "⚠️ Please configure git:"
echo "git config --global user.email 'your-email@example.com'"
echo "git config --global user.name 'Your Name'"
exit 1
fi
# Check if HF_TOKEN is set
if [ -z "$HF_TOKEN" ]; then
echo "⚠️ Please set your Hugging Face token:"
echo "export HF_TOKEN=your_hf_token_here"
exit 1
fi
SPACE_NAME=${1:-"deepcoder-api"}
HF_USERNAME=${2:-$(whoami)}
echo "Creating Space: $HF_USERNAME/$SPACE_NAME"
# Create Hugging Face Space files
cat > README.md << EOF
---
title: DeepCoder API
emoji: πŸš€
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
---
# DeepCoder API
High-performance code generation API powered by DeepCoder-14B model.
## Features
- 🎯 60.6% pass rate on LiveCodeBench v5
- πŸ† 1936 Elo rating on Codeforces (95.3 percentile)
- πŸ“ 92.6% accuracy on HumanEval+
- ⚑ 131K token context length
- πŸ”§ Optimized Q4_K_M quantization
## API Endpoints
- \`POST /generate\` - Generate code from prompts
- \`POST /chat\` - Chat-style code assistance
- \`GET /model/info\` - Model information
- \`GET /health\` - Health check
## Usage
\`\`\`bash
curl -X POST /generate \\
-H 'Content-Type: application/json' \\
-d '{"prompt": "def fibonacci(n):", "max_tokens": 200}'
\`\`\`
EOF
# Create Dockerfile for HF Spaces
cat > Dockerfile.hf << EOF
FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
EOF
# Update app.py for HF Spaces (port 7860)
sed 's/port=8000/port=7860/g' app.py > app_hf.py
mv app_hf.py app.py
# Initialize git repo if not exists
if [ ! -d .git ]; then
git init
git lfs install
fi
# Track large model files with git LFS
echo "*.bin filter=lfs diff=lfs merge=lfs -text" >> .gitattributes
echo "*.safetensors filter=lfs diff=lfs merge=lfs -text" >> .gitattributes
# Add remote if not exists
if ! git remote get-url origin > /dev/null 2>&1; then
git remote add origin https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
fi
# Commit and push
git add .
git commit -m "Initial DeepCoder API deployment" || true
git push -u origin main
echo "βœ… Deployed to: https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"