Step-by-step guide to deploy Code Reviewer Environment to Hugging Face Spaces
Before starting, ensure you have:
- GitHub account
- Hugging Face account
- Hugging Face token with write access
- Git installed locally
# Create directory and initialize git
mkdir openenv-code-reviewer
cd openenv-code-reviewer
# Initialize git
git init
# Add all project files
git add .
# Create initial commit
git commit -m "Initial commit: Code Reviewer Environment for OpenEnv Hackathon"# If you already have the project locally
cd /path/to/your/project
# Initialize git (if not already)
git init
# Add remote
git remote add origin https://github.com/YOUR_USERNAME/openenv-code-reviewer.git# Create main branch
git branch -M main
# Add .gitignore
cat > .gitignore << 'EOF'
__pycache__/
*.pyc
.env
*.egg-info/
.pytest_cache/
EOF
# Commit and push
git add .gitignore
git commit -m "Add .gitignore"
git push -u origin main-
Go to Hugging Face Spaces
https://huggingface.co/new-space -
Configure your Space
Owner: Your username Space Name: code-reviewer-env SDK: Docker Hardware: CPU (free tier) License: MIT -
Click "Create Space"
- Go to https://huggingface.co/settings/tokens
- Click "New Token"
- Name it
HF_DEPLOY - Select role: Write
- Copy the token
# Install Hugging Face CLI
pip install huggingface-hub
# Login
huggingface-cli login
# Enter your HF token when prompted
# Clone your new Space
git clone https://huggingface.co/spaces/YOUR_USERNAME/code-reviewer-env
cd code-reviewer-env
# Copy all project files
cp -r /path/to/openenv-code-reviewer/* .
cp -r /path/to/openenv-code-reviewer/.* . 2>/dev/null || true
# Verify files
ls -la
# Commit and push
git add .
git commit -m "Deploy Code Reviewer Environment"
git push- Go to your Space's Files tab
- Click "Add file" → "Upload files"
- Drag and drop all project files
- Commit changes
- Go to your Space Settings
- Find "Linked Accounts"
- Connect your GitHub account
- Select repository:
YOUR_USERNAME/openenv-code-reviewer - Enable "Auto-redeploy on push"
Hugging Face Spaces with Docker typically take 2-5 minutes to build.
# Test health endpoint
curl https://YOUR_USERNAME-code-reviewer-env.hf.space/health
# Expected response:
{
"status": "running",
"environment": "code-reviewer-env",
"version": "1.0.0",
"available_tasks": [...]
}curl -X POST https://YOUR_USERNAME-code-reviewer-env.hf.space/reset \
-H "Content-Type: application/json" \
-d '{"task": "syntax_check", "session_id": "test"}'
# Expected response:
{
"observation": {...},
"session_id": "test",
"status": "success"
}curl -X POST https://YOUR_USERNAME-code-reviewer-env.hf.space/step \
-H "Content-Type: application/json" \
-d '{
"session_id": "test",
"action": {"action_type": "submit_review"}
}'# SSH into your Space (if needed) or run locally
export API_BASE_URL="https://router.huggingface.co/v1"
export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
export HF_TOKEN="hf_your_token_here"# Task 1: Syntax Check (Easy)
export CODE_REVIEWER_TASK="syntax_check"
python inference.py
# Expected output:
# [START] task=syntax_check env=code-reviewer-env ...
# [STEP] step=1 action=identify_issue ... error=null
# ...
# [END] success=true steps=12 rewards=0.40,0.40,0.30,0.55# Task 2: Logic Bug Detection (Medium)
export CODE_REVIEWER_TASK="logic_bug_detection"
python inference.py# Task 3: Security Audit (Hard)
export CODE_REVIEWER_TASK="security_audit"
python inference.pyCreate .github/workflows/deploy.yml:
name: Deploy to Hugging Face Spaces
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Push to HF Spaces
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
# Install git lfs
git lfs install
# Clone HF Space
git clone https://huggingface.co/spaces/${{ vars.HF_SPACE_NAME }} hf_space
# Copy files
cp -r . hf_space/
cd hf_space
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Commit and push
git add .
git commit -m "Auto-deploy from GitHub Actions"
git push-
Go to:
https://github.com/YOUR_USERNAME/openenv-code-reviewer/settings/secrets/actions -
Click "New repository secret"
-
Add:
- Name:
HF_TOKEN - Secret: Your Hugging Face write token
- Name:
-
Go to:
https://github.com/YOUR_USERNAME/openenv-code-reviewer/settings/variables/actions -
Add:
- Name:
HF_SPACE_NAME - Value:
YOUR_USERNAME/code-reviewer-env
- Name:
# 1. Run tests
python test_environment.py
# Expected: Passed: 8/8 ✓
# 2. Test server
python server.py &
# Test endpoints...
pkill -f server.py
# 3. Verify deployment
curl https://YOUR_SPACE.hf.space/health- Go to the hackathon submission page
- Fill in:
- GitHub Repository:
https://github.com/YOUR_USERNAME/openenv-code-reviewer - Hugging Face Space:
https://YOUR_USERNAME-code-reviewer-env.hf.space - Demo Video (optional): Record a quick demo
- Description: Brief explanation of your project
- GitHub Repository:
Error: Container fails to start
Solution:
# Check Dockerfile syntax
docker build -t test-build .
# Look for errors in local build
docker run test-buildError: Connection refused on HF Space URL
Solution: Ensure Dockerfile has:
EXPOSE 7860
CMD ["python", "server.py"]Error: ModuleNotFoundError
Solution: Check requirements.txt includes all dependencies:
fastapi>=0.104.0
uvicorn[standard]>=0.24.0
pydantic>=2.5.0
websockets>=12.0
python-multipart>=0.0.6
openai>=1.6.0
pyyaml>=6.0
Error: First request times out
Solution: This is normal. HF Spaces have 30-60s cold starts. Subsequent requests are faster.
- Go to your Space:
https://huggingface.co/spaces/YOUR_USERNAME/code-reviewer-env - Click "Files and versions"
- Click "Logs"
- View
container.log
If changes don't appear:
- Go to Space Settings
- Click "Factory Rebuild"
- Wait for rebuild to complete
# Local testing
python test_environment.py # Run all tests
python server.py # Start server
curl http://localhost:7860/health # Test local server
# Docker
docker build -t code-reviewer . # Build image
docker run -p 7860:7860 code-reviewer # Run container
docker logs <container_id> # View logs
# Hugging Face
huggingface-cli login # Login to HF
git clone https://huggingface.co/spaces/USERNAME/SPACE_NAME # Clone Space
# GitHub
git add . && git commit -m "message" # Commit
git push # Push to remote| Resource | Link |
|---|---|
| Hugging Face Spaces Docs | https://huggingface.co/docs/hub/spaces |
| Docker Deployment Guide | https://huggingface.co/docs/hub/spaces-sdks-docker |
| OpenEnv Repository | https://github.com/meta-pytorch/OpenEnv |
| Hackathon Discord | Check your hackathon dashboard |
Good luck with your submission! 🚀