A comprehensive platform for deploying, managing, and serving machine learning models through REST APIs with an intuitive web interface.
ModelHub is a professional-grade ML model serving platform that allows data scientists and developers to easily deploy, manage, and serve machine learning models through REST APIs. Built with Django and featuring a modern, responsive web interface, ModelHub provides everything you need to productionize your ML models.
- π Easy Model Deployment - Deploy sklearn, TensorFlow, PyTorch models with minimal configuration
- π API Key Authentication - Secure access with rate limiting and usage tracking
- π Interactive Dashboard - Professional web interface for model management and testing
- π Usage Analytics - Comprehensive prediction logging and performance metrics
- π― Multi-Framework Support - Support for popular ML frameworks (scikit-learn, TensorFlow, PyTorch)
- π± Responsive Design - Modern, mobile-friendly interface with split-screen authentication
- π API Documentation - Auto-generated interactive API docs with Swagger/ReDoc
- π₯ User Management - Complete authentication system with user dashboards
ModelHub/
βββ π accounts/ # User authentication & management
βββ π api/ # REST API endpoints & ML prediction logic
βββ π dashboard/ # Web interface & interactive features
βββ π models/ # Model definitions & database schemas
βββ π modelhub/ # Django project settings & configuration
βββ π media/ # File storage for models & assets
β βββ π models/
β βββ π diabetes/ # Diabetes prediction model files
β βββ π fake_news/ # Fake news detection model files
βββ π static/ # CSS, JavaScript, images
βββ π templates/ # HTML templates
βββ π logs/ # Application logs
βββ π§ manage.py # Django management script
βββ π requirements.txt # Python dependencies
βββ π README.md # This file
- Python: 3.8 or higher
- Operating System: Linux, macOS, or Windows
- Memory: Minimum 2GB RAM (4GB+ recommended)
- Storage: 1GB+ free space
Package | Version | Purpose |
---|---|---|
Django | 4.2.7 | Web framework |
djangorestframework | 3.14.0 | REST API framework |
scikit-learn | β₯1.3.0 | ML framework |
numpy | β₯1.21.0 | Numerical computing |
pandas | β₯2.0.0 | Data manipulation |
joblib | β₯1.3.0 | Model serialization |
psycopg2-binary | 2.9.7 | PostgreSQL adapter |
django-cors-headers | 4.3.1 | CORS handling |
drf-yasg | 1.21.7 | API documentation |
See requirements.txt
for complete dependency list
git clone https://github.com/AnkushGitRepo/ModelHub.git
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
pip install -r requirements.txt
Create a .env
file in the project root:
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=sqlite:///db.sqlite3
# Run migrations
python manage.py migrate
# Create superuser (optional)
python manage.py createsuperuser
# Load initial model data
python manage.py loaddata models/fixtures/initial_models.json
python manage.py runserver
π Success! Visit http://127.0.0.1:8000
to access ModelHub
accounts/
βββ views.py # Authentication views, user dashboard
βββ urls.py # Account-related URL patterns
βββ models.py # User profile extensions
βββ templates/ # Login, signup, dashboard templates
api/
βββ views.py # API endpoints (prediction, models, keys)
βββ serializers.py # Data serialization for API responses
βββ authentication.py # API key authentication logic
βββ ml_predictor.py # Generic ML model prediction interface
βββ diabetes_predictor.py # Specialized diabetes model predictor
βββ urls.py # API URL routing
dashboard/
βββ views.py # Web interface views (home, model details)
βββ urls.py # Dashboard URL patterns
βββ templatetags/ # Custom template filters and tags
models/
βββ models.py # Database models (MLModel, APIKey, PredictionLog)
βββ admin.py # Django admin interface configuration
βββ management/ # Custom Django management commands
static/
βββ css/ # Stylesheets
βββ js/ # JavaScript files
βββ images/ # Images and icons
βββ fonts/ # Custom fonts
templates/
βββ base.html # Base template with navigation
βββ dashboard/ # Dashboard page templates
β βββ home.html # Homepage with model showcase
β βββ api_docs.html # API documentation
β βββ model_api_docs.html # Model-specific API docs
βββ registration/ # Authentication templates
β βββ login.html # Split-screen login page
β βββ signup.html # Split-screen signup page
βββ accounts/ # User account templates
media/models/
βββ diabetes/ # Diabetes prediction model
βββ diabetes_classifier.pkl # Trained SVM model
βββ diabetes_scaler.pkl # Feature scaler
βββ feature_names.pkl # Feature definitions
βββ model_metrics.json # Performance metrics
βββ diabetes.csv # Training dataset
βββ train_diabetes_model.py # Training script
βββ test_diabetes_prediction.py # Testing script
βββ README.md # Model documentation
Variable | Description | Default | Required |
---|---|---|---|
SECRET_KEY |
Django secret key | - | β |
DEBUG |
Debug mode | False |
β |
ALLOWED_HOSTS |
Allowed hostnames | localhost |
β |
DATABASE_URL |
Database connection | SQLite | β |
Key configuration files:
modelhub/settings.py
- Main Django settingsmodelhub/urls.py
- URL routing configurationmodelhub/wsgi.py
- WSGI application entry point
- Homepage:
http://127.0.0.1:8000/
- Browse available models - API Docs:
http://127.0.0.1:8000/api-docs/
- Interactive API documentation - Admin Panel:
http://127.0.0.1:8000/admin/
- Django admin interface
- Sign Up: Create account with split-screen interface
- Login: Secure authentication with password toggle
- Dashboard: Manage API keys and view usage statistics
- Interactive model testing interface
- Real-time prediction results
- Input validation and error handling
# Get API key from user dashboard
curl -X POST http://127.0.0.1:8000/api/v1/keys/ \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "My API Key"}'
curl -X GET http://127.0.0.1:8000/api/v1/models/
curl -X POST http://127.0.0.1:8000/api/v1/predict/ \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_id": "model-uuid-here",
"inputs": {
"feature1": 1.0,
"feature2": 2.0
}
}'
# Save your trained model
import joblib
joblib.dump(model, 'my_model.pkl')
joblib.dump(scaler, 'my_scaler.pkl')
# In Django shell or admin
from models.models import MLModel
model = MLModel.objects.create(
name="My Custom Model",
description="Description of what the model does",
framework="sklearn",
version="1.0.0",
input_schema={
"feature1": {"type": "number", "description": "First feature"},
"feature2": {"type": "number", "description": "Second feature"}
},
output_schema={
"prediction": {"type": "number", "description": "Model prediction"}
}
)
The platform includes a pre-configured diabetes prediction model:
- Algorithm: Support Vector Machine (Linear Kernel)
- Dataset: PIMA Indian Diabetes Dataset
- Accuracy: ~77% test accuracy
- Features: 8 health indicators
cd media/models/diabetes
python train_diabetes_model.py
cd media/models/diabetes
python test_diabetes_prediction.py
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/api/v1/models/ |
GET | List all models | β |
/api/v1/predict/ |
POST | Make prediction | β |
/api/v1/keys/ |
GET, POST | Manage API keys | β |
/api/v1/history/ |
GET | Prediction history | β |
- Swagger UI:
http://127.0.0.1:8000/swagger/
- ReDoc:
http://127.0.0.1:8000/redoc/
- JSON Schema:
http://127.0.0.1:8000/swagger.json
{
"prediction_id": "uuid-here",
"model_id": "model-uuid",
"model_name": "Diabetes Prediction Model",
"prediction": {
"prediction_text": "Low Risk",
"confidence": 85.2,
"risk_level": "Low",
"interpretation": {
"key_factors": ["BMI", "Age"],
"recommendations": ["Maintain healthy lifestyle"]
}
},
"execution_time": 0.045,
"timestamp": "2024-01-15T10:30:00Z"
}
- Create Account: Sign up through web interface
- Generate API Key: Access user dashboard
- Use API Key: Include in request headers
- Monitor Usage: Track requests and rate limits
- π API Key Authentication with rate limiting
- π‘οΈ CSRF Protection for web interface
- π Secure Password Storage with Django's built-in hashing
- π Request Logging for audit trails
- π« Input Validation to prevent malicious requests
pip install -r requirements.txt
pip install django-debug-toolbar # For debugging
DEBUG=True
DJANGO_DEBUG_TOOLBAR=True
# Create migrations for model changes
python manage.py makemigrations
# Apply migrations
python manage.py migrate
# Load test data
python manage.py loaddata fixtures/test_data.json
# Run all tests
python manage.py test
# Run specific app tests
python manage.py test api
python manage.py test dashboard
# Format code (if using black)
black .
# Check code style (if using flake8)
flake8 .
- Models: Define in respective app's
models.py
- Views: Separate API views from web views
- Templates: Use consistent naming and inheritance
- Static Files: Organize by type (css, js, images)
- Model Files: Store in
media/models/{model_name}/
# Check model file permissions
ls -la media/models/diabetes/
# Verify model file integrity
python -c "import joblib; print(joblib.load('media/models/diabetes/diabetes_classifier.pkl'))"
# Reset database (development only)
rm db.sqlite3
python manage.py migrate
python manage.py createsuperuser
# Collect static files
python manage.py collectstatic
# Check static files configuration in settings.py
- Verify API key is active in user dashboard
- Check rate limits haven't been exceeded
- Ensure proper header format:
X-API-Key: your-key-here
# Check Python path
python -c "import sys; print(sys.path)"
# Verify virtual environment
which python
pip list
Enable detailed error messages:
DEBUG=True
LOGGING_LEVEL=DEBUG
Check application logs:
tail -f logs/modelhub.log
- π Documentation: Check this README and inline code comments
- π Issues: Report bugs via GitHub Issues
- π¬ Discussions: Join community discussions
- π§ Contact: Reach out to maintainers
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open Pull Request
- Support for more ML frameworks (XGBoost, LightGBM)
- Model versioning and A/B testing
- Batch prediction endpoints
- Model performance monitoring
- Docker containerization
- Kubernetes deployment configs
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Django and Django REST Framework
- UI components inspired by modern design systems
- ML integration powered by scikit-learn
- API documentation generated with drf-yasg
Made with β€οΈ
For more information, visit our documentation or check out the API reference.