Spaces:
Runtime error
Runtime error
π Deploy ClassLens to Hugging Face Spaces
Prerequisites
- Hugging Face account with access to taboola-cz organization
- Git installed
- OpenAI API key
Step 1: Create the Space
Option A: Via Hugging Face Web UI
- Go to https://huggingface.co/new-space?owner=taboola-cz
- Fill in:
- Space name:
examinsight - License: MIT
- SDK: Docker
- Visibility: Public (or Private)
- Space name:
- Click "Create Space"
Option B: Via Git
# Clone the empty space
git clone https://huggingface.co/spaces/taboola-cz/examinsight
cd examinsight
Step 2: Push the Code
# From the examinsight-app/chatkit directory
cd /path/to/ClassLens/examinsight-app/chatkit
# Add HF as remote
git remote add hf https://huggingface.co/spaces/taboola-cz/examinsight
# Push to HF Spaces
git push hf main
Or copy files manually:
# Copy necessary files to the HF Space repo
cp -r backend frontend Dockerfile README.md .dockerignore /path/to/examinsight-space/
Step 3: Configure Secrets
Go to your Space settings: https://huggingface.co/spaces/taboola-cz/examinsight/settings
Add these Repository secrets:
| Secret Name | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | β Yes |
ENCRYPTION_KEY |
Fernet key for token encryption | β Yes |
GOOGLE_CLIENT_ID |
Google OAuth client ID | Optional |
GOOGLE_CLIENT_SECRET |
Google OAuth secret | Optional |
GOOGLE_REDIRECT_URI |
https://taboola-cz-examinsight.hf.space/auth/callback |
Optional |
GMAIL_USER |
Gmail address for sending reports | Optional |
GMAIL_APP_PASSWORD |
Gmail App Password | Optional |
VITE_CHATKIT_API_DOMAIN_KEY |
ChatKit domain key | β Yes |
Generate Encryption Key
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
Get ChatKit Domain Key
- Go to https://platform.openai.com/settings/organization/security/domain-allowlist
- Add domain:
taboola-cz-examinsight.hf.space - Copy the generated domain key
Step 4: Update Google OAuth (if using)
- Go to Google Cloud Console
- Edit your OAuth 2.0 Client
- Add to Authorized redirect URIs:
https://taboola-cz-examinsight.hf.space/auth/callback - Add to Authorized JavaScript origins:
https://taboola-cz-examinsight.hf.space
Step 5: Deploy
The Space will automatically build when you push. Watch the build logs at: https://huggingface.co/spaces/taboola-cz/examinsight/logs
File Structure for HF Spaces
examinsight/
βββ Dockerfile # Multi-stage build
βββ README.md # Space config (YAML frontmatter)
βββ .dockerignore # Files to exclude from build
βββ backend/
β βββ pyproject.toml
β βββ app/
β βββ main.py # FastAPI + static file serving
β βββ server.py # ChatKit agent
β βββ ...
βββ frontend/
βββ package.json
βββ src/
βββ ...
Troubleshooting
Build Failed
Check the build logs for errors:
- Missing dependencies β Update
pyproject.toml - Node version issues β Update Dockerfile
ChatKit Not Working
- Verify
OPENAI_API_KEYis set in secrets - Verify
VITE_CHATKIT_API_DOMAIN_KEYis set and valid - Check that domain is allowlisted in OpenAI dashboard
Google OAuth Not Working
- Verify redirect URI matches exactly
- Check that test users are added (if app is in testing mode)
- Verify Google Cloud APIs are enabled
Static Files Not Serving
- Check that frontend build succeeded (look for
/static/index.htmlin container) - Verify
STATIC_DIRpath inmain.py
Local Testing with Docker
# Build the image
docker build -t examinsight .
# Run with env file
docker run -p 7860:7860 --env-file .env examinsight
# Open http://localhost:7860
Updating the Space
# Make changes locally
# Commit and push
git add .
git commit -m "Update feature X"
git push hf main
The Space will automatically rebuild.
Quick Reference
| URL | Description |
|---|---|
| https://huggingface.co/spaces/taboola-cz/examinsight | Live Space |
| https://huggingface.co/spaces/taboola-cz/examinsight/settings | Settings & Secrets |
| https://huggingface.co/spaces/taboola-cz/examinsight/logs | Build & Runtime Logs |
| https://platform.openai.com/settings/organization/security/domain-allowlist | ChatKit Domain Keys |