File size: 2,608 Bytes
aba8087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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"