Spaces:
Sleeping
Sleeping
File size: 4,703 Bytes
c5292d8 | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | ---
title: LLM Code Deployment API
emoji: 🚀
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
---
# LLM Code Deployment - Student API
This is a Hugging Face Space that hosts the student API endpoint for the LLM Code Deployment project. It receives build requests, generates code using LLMs, and deploys to GitHub Pages.
## Setup on Hugging Face Spaces
### 1. Create a New Space
1. Go to https://huggingface.co/new-space
2. Choose a name for your Space
3. Select **Docker** as the SDK
4. Click **Create Space**
### 2. Configure Environment Variables
Go to your Space's **Settings** → **Variables and secrets** tab and add:
**Required:**
- `STUDENT_EMAIL` - Your email address (matching the submission form)
- `STUDENT_SECRET` - Your secret key (matching the submission form)
- `GITHUB_TOKEN` - Your GitHub personal access token (with `repo` permissions)
- `GITHUB_USERNAME` - Your GitHub username
- `AIPIPE_TOKEN` - Your AIPipe token from https://aipipe.org/login
**Optional (advanced):**
- `LLM_PROVIDER` - `aipipe` (default), `anthropic`, or `openai`
- `LLM_MODEL` - Model name (default: `google/gemini-2.0-flash-lite-001`)
- `AIPIPE_BASE_URL` - AIPipe endpoint (default: `https://aipipe.org/openrouter/v1`)
### 3. Get Your AIPipe Token
1. Visit https://aipipe.org/login
2. Sign in with your `@ds.study.iitm.ac.in` email
3. Copy your API token
4. You get **$2 per month free** - don't exceed this
### 4. Deploy the Code
**Option A: Clone from GitHub**
```bash
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd YOUR_REPO
git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE
git push space main
```
**Option B: Direct Upload**
1. Upload all project files to your Space via the web interface
2. Ensure `Dockerfile`, `requirements.txt`, and all code files are present
### 5. Wait for Build
The Space will automatically build using the Dockerfile. This may take 5-10 minutes.
### 6. Get Your API Endpoint
Once deployed, your endpoint will be:
```
https://YOUR_USERNAME-YOUR_SPACE.hf.space/api/build
```
Use this URL when submitting to the instructor's Google Form.
## Testing Your Deployment
Test your endpoint locally first:
```bash
curl -X POST https://YOUR_USERNAME-YOUR_SPACE.hf.space/api/build \
-H "Content-Type: application/json" \
-d '{
"email": "your-email@ds.study.iitm.ac.in",
"secret": "your-secret",
"task": "test-task-123",
"round": 1,
"nonce": "test-nonce-456",
"brief": "Create a simple Hello World page with Bootstrap",
"checks": ["Page displays Hello World"],
"evaluation_url": "https://example.com/evaluate",
"attachments": []
}'
```
Expected response:
```json
{
"status": "accepted",
"message": "Task test-task-123-1 accepted for processing",
"task": "test-task-123",
"round": 1
}
```
## Health Check
Check if your Space is running:
```bash
curl https://YOUR_USERNAME-YOUR_SPACE.hf.space/health
```
## Monitoring
View logs in the **Logs** tab of your Space to monitor:
- Task requests received
- Code generation progress
- GitHub deployment status
- Evaluation notification results
## Troubleshooting
### Space won't start
- Check the **Logs** tab for build errors
- Ensure all environment variables are set correctly
- Verify Dockerfile and requirements.txt are present
### Authentication errors
- Verify `STUDENT_SECRET` matches what you submitted in the form
- Check `STUDENT_EMAIL` is correct
- Ensure `GITHUB_TOKEN` has repo permissions
### LLM generation fails
- Verify `AIPIPE_TOKEN` is set and valid
- Check you haven't exceeded the $2/month quota
- Review logs for specific error messages
### GitHub deployment fails
- Ensure `GITHUB_TOKEN` has correct permissions
- Check `GITHUB_USERNAME` is correct
- Verify token hasn't expired
## Cost Management
**AIPipe Limits:**
- Free tier: $2 per month for @ds.study.iitm.ac.in emails
- Models recommended:
- `google/gemini-2.0-flash-lite-001` (cheapest)
- `anthropic/claude-3-haiku` (good quality)
- `openai/gpt-4.1-nano` (balanced)
**Monitoring usage:**
- Check https://aipipe.org/usage
- Each code generation uses ~1000-2000 tokens
- Budget for ~50-100 task submissions per month
## Local Development
To test locally before deploying to Spaces:
```bash
# Set environment variables
cp .env.example .env
# Edit .env with your credentials
# Run with Docker
docker build -t llm-code-deploy .
docker run -p 7860:7860 --env-file .env llm-code-deploy
# Or run directly with Python
uv run python main.py student-api
```
## Support
For issues:
1. Check the project README.md
2. Review Hugging Face Spaces documentation
3. Contact the course instructors
## License
MIT License - See LICENSE file
|