Spaces:
Paused
Paused
metadata
title: FunCaptcha Solver API
emoji: π§©
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
suggested_hardware: cpu-basic
app_file: app.py
π§© FunCaptcha Solver API - Hugging Face Spaces
High-performance FunCaptcha solver dengan fuzzy matching dan API key authentication
π Features
- β FastAPI - High performance async web framework
- β Docker optimization - Multi-stage build untuk size minimal
- β Fuzzy label matching - Handle variasi label seperti "ice cream" vs "ice"
- β API key authentication - Secure access menggunakan HF Secrets
- β Response caching - Fast responses untuk requests yang sama
- β Multi-model support - Support berbagai jenis CAPTCHA challenges
- β Memory efficient - Optimized untuk HF Spaces environment
- β Auto health checks - Built-in monitoring
π Supported Challenge Types
| Challenge Type | Description | Response |
|---|---|---|
pick_the |
Pick specific objects dari images | {status, box, confidence} |
upright |
Find correctly oriented objects | {status, button_index, confidence} |
π§ Deployment ke Hugging Face Spaces
1. Create New Space
- Buka Hugging Face Spaces
- Click "Create new Space"
- Pilih:
- Space name:
funcaptcha-solver-api(atau nama pilihan Anda) - License:
mit - Space SDK:
Docker - Space visibility:
Private(recommended)
- Space name:
2. Upload Files
Upload semua files dalam folder ini ke Space repository:
hf-funcaptcha-deployment/
βββ Dockerfile # Docker configuration
βββ app.py # Main FastAPI application
βββ requirements.txt # Python dependencies
βββ README.md # Documentation (this file)
βββ data.yaml # Class names untuk default model
βββ best.onnx # ONNX model file (upload manually)
βββ test-api.py # Testing script
3. Setup API Key (CRITICAL!)
- Di Space settings, buka tab "Settings"
- Scroll ke "Repository secrets"
- Add new secret:
- Name:
FUNCAPTCHA_API_KEY - Value:
your-secure-api-key-here(generate strong key)
- Name:
β οΈ PENTING: Tanpa API key, aplikasi tidak akan start!
4. Upload Model Files
Upload model files ke Space repository:
best.onnx- Main detection modeldata.yaml- Class names configurationbestspiral.onnx(optional) - Spiral galaxy modeldataspiral.yaml(optional) - Spiral galaxy classesbest_Upright.onnx(optional) - Upright detection modeldata_upright.yaml(optional) - Upright detection classes
5. Deploy & Test
- Space akan auto-deploy setelah files uploaded
- Wait untuk build process selesai (~5-10 minutes)
- Test endpoint:
https://your-space-url.hf.space/health
π Authentication
Semua API endpoints require Bearer token authentication:
# Example request
curl -X POST "https://your-space-url.hf.space/solve" \\
-H "Authorization: Bearer YOUR_API_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"challenge_type": "pick_the",
"image_b64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"target_label": "ice cream"
}'
π API Documentation
Endpoints
| Endpoint | Method | Description | Auth Required |
|---|---|---|---|
/ |
GET | Root info & status | β |
/health |
GET | Health check | β |
/solve |
POST | Solve FunCaptcha | β |
/docs |
GET | Interactive API docs | β |
Request Format
{
"challenge_type": "pick_the",
"image_b64": "data:image/png;base64,iVBORw0KGgo...",
"target_label": "ice cream"
}
Response Format
{
"status": "success",
"box": [120.5, 80.3, 150.0, 100.0],
"confidence": 0.89,
"processing_time": 0.245,
"message": null
}
π§ͺ Testing
Local Testing
# Install dependencies
pip install -r requirements.txt
# Set API key
export FUNCAPTCHA_API_KEY="your-test-key"
# Run server
python app.py
# Test with provided script
python test-api.py
Production Testing
import requests
import base64
# Load test image
with open("test_image.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
# Make request
response = requests.post(
"https://your-space-url.hf.space/solve",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"challenge_type": "pick_the",
"image_b64": f"data:image/png;base64,{image_b64}",
"target_label": "ice cream"
}
)
print(response.json())
βοΈ Configuration
Model Configuration
Edit CONFIGS in app.py untuk custom models:
CONFIGS = {
'default': {
'model_path': 'best.onnx',
'yaml_path': 'data.yaml',
'input_size': 640,
'confidence_threshold': 0.4,
'nms_threshold': 0.2
}
# Add more models...
}
Environment Variables
| Variable | Description | Required |
|---|---|---|
FUNCAPTCHA_API_KEY |
API key untuk authentication | β |
OMP_NUM_THREADS |
CPU threads untuk optimization | β (default: 2) |
CACHE_MAX_SIZE |
Maximum cache entries | β (default: 100) |
π Monitoring & Debugging
Health Check
curl https://your-space-url.hf.space/health
Logs
- Check HF Spaces logs dalam space interface
- Logs include processing times, cache hits, errors
Performance Metrics
- Processing time: Biasanya < 300ms per request
- Memory usage: ~500MB dengan 1 model loaded
- Cache hit rate: Displayed in
/healthendpoint
π¨ Troubleshooting
Common Issues
"API key not found"
- Solution: Set
FUNCAPTCHA_API_KEYdi Space secrets
- Solution: Set
"Model file not found"
- Solution: Upload model files (.onnx, .yaml) ke repository
"401 Unauthorized"
- Solution: Check API key dalam request header
Slow responses
- Check: Model loading, enable caching
- Monitor: Memory usage dalam Space logs
Debug Mode
Untuk debugging, set logging level:
import logging
logging.basicConfig(level=logging.DEBUG)
π Performance Optimization
- β Model caching - Models loaded once, reused
- β Response caching - Identical requests cached
- β CPU optimization - ONNX dengan CPU-specific settings
- β Memory efficiency - Minimal memory footprint
- β Async operations - Non-blocking request handling
π Security
- β API key authentication via Bearer tokens
- β CORS protection configured
- β Input validation dengan Pydantic models
- β Error handling tanpa expose internal details
π Support
- Issues: Report dalam repository issues
- Updates: Check Space status dan rebuild jika needed
- Performance: Monitor via
/healthendpoint
π― Ready to deploy? Upload files, set API key, dan Space siap digunakan!
π Client Integration
Update client untuk menggunakan Space URL:
// funcaptcha-blob-fixed.js
const SOLVER_SERVER_URL = 'https://your-space-url.hf.space/solve';
const API_KEY = 'your-api-key-here';