Skip to content

ModelHub is a Django-based platform that enables seamless deployment, management, and API serving of machine learning models.

Notifications You must be signed in to change notification settings

AnkushGitRepo/ModelHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– ModelHub - ML Model Serving Platform

Python Django License Build Status API GitHub stars GitHub forks GitHub followers

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.

✨ Key Features

  • πŸš€ 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

πŸ—οΈ Project Architecture

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

πŸ“‹ Requirements

System Requirements

  • Python: 3.8 or higher
  • Operating System: Linux, macOS, or Windows
  • Memory: Minimum 2GB RAM (4GB+ recommended)
  • Storage: 1GB+ free space

Python Dependencies

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

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/AnkushGitRepo/ModelHub.git

2. Set Up Virtual Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Environment Configuration

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

5. Database Setup

# Run migrations
python manage.py migrate

# Create superuser (optional)
python manage.py createsuperuser

6. Load Sample Data

# Load initial model data
python manage.py loaddata models/fixtures/initial_models.json

7. Start Development Server

python manage.py runserver

πŸŽ‰ Success! Visit http://127.0.0.1:8000 to access ModelHub

πŸ“ Detailed Folder Structure

Core Applications

πŸ” accounts/ - User Management

accounts/
β”œβ”€β”€ views.py          # Authentication views, user dashboard
β”œβ”€β”€ urls.py           # Account-related URL patterns
β”œβ”€β”€ models.py         # User profile extensions
└── templates/        # Login, signup, dashboard templates

🌐 api/ - REST API Layer

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/ - Web Interface

dashboard/
β”œβ”€β”€ views.py          # Web interface views (home, model details)
β”œβ”€β”€ urls.py           # Dashboard URL patterns
└── templatetags/     # Custom template filters and tags

πŸ—„οΈ models/ - Data Models

models/
β”œβ”€β”€ models.py         # Database models (MLModel, APIKey, PredictionLog)
β”œβ”€β”€ admin.py          # Django admin interface configuration
└── management/       # Custom Django management commands

Static Assets & Templates

🎨 static/ - Frontend Assets

static/
β”œβ”€β”€ css/              # Stylesheets
β”œβ”€β”€ js/               # JavaScript files
β”œβ”€β”€ images/           # Images and icons
└── fonts/            # Custom fonts

πŸ“„ templates/ - HTML Templates

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

Model Storage

πŸ“¦ media/models/ - Model Files

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

βš™οΈ Configuration

Environment Variables

Variable Description Default Required
SECRET_KEY Django secret key - βœ…
DEBUG Debug mode False ❌
ALLOWED_HOSTS Allowed hostnames localhost ❌
DATABASE_URL Database connection SQLite ❌

Django Settings

Key configuration files:

  • modelhub/settings.py - Main Django settings
  • modelhub/urls.py - URL routing configuration
  • modelhub/wsgi.py - WSGI application entry point

πŸ”§ Usage Instructions

Web Interface

1. Access the Platform

  • 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

2. User Authentication

  • Sign Up: Create account with split-screen interface
  • Login: Secure authentication with password toggle
  • Dashboard: Manage API keys and view usage statistics

3. Model Testing

  • Interactive model testing interface
  • Real-time prediction results
  • Input validation and error handling

API Usage

1. Authentication

# 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"}'

2. List Available Models

curl -X GET http://127.0.0.1:8000/api/v1/models/

3. Make Predictions

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
    }
  }'

🧠 Model Management

Adding New Models

1. Prepare Model Files

# Save your trained model
import joblib
joblib.dump(model, 'my_model.pkl')
joblib.dump(scaler, 'my_scaler.pkl')

2. Create Model Entry

# 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"}
    }
)

Diabetes Model Example

The platform includes a pre-configured diabetes prediction model:

Features

  • Algorithm: Support Vector Machine (Linear Kernel)
  • Dataset: PIMA Indian Diabetes Dataset
  • Accuracy: ~77% test accuracy
  • Features: 8 health indicators

Training the Model

cd media/models/diabetes
python train_diabetes_model.py

Testing the Model

cd media/models/diabetes
python test_diabetes_prediction.py

πŸ“š API Documentation

Core Endpoints

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 βœ…

Interactive Documentation

  • 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

Example API Response

{
  "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"
}

πŸ” Authentication & Security

API Key Management

  1. Create Account: Sign up through web interface
  2. Generate API Key: Access user dashboard
  3. Use API Key: Include in request headers
  4. Monitor Usage: Track requests and rate limits

Security Features

  • πŸ”’ 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

πŸ‘¨β€πŸ’» Development Setup

For Contributors

1. Development Dependencies

pip install -r requirements.txt
pip install django-debug-toolbar  # For debugging

2. Enable Debug Mode

DEBUG=True
DJANGO_DEBUG_TOOLBAR=True

3. Database Development

# 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

4. Running Tests

# Run all tests
python manage.py test

# Run specific app tests
python manage.py test api
python manage.py test dashboard

5. Code Style

# Format code (if using black)
black .

# Check code style (if using flake8)
flake8 .

Project Structure Guidelines

  • 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}/

πŸ› Troubleshooting

Common Issues

1. Model Loading Errors

# 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'))"

2. Database Issues

# Reset database (development only)
rm db.sqlite3
python manage.py migrate
python manage.py createsuperuser

3. Static Files Not Loading

# Collect static files
python manage.py collectstatic

# Check static files configuration in settings.py

4. API Authentication Errors

  • 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

5. Import Errors

# Check Python path
python -c "import sys; print(sys.path)"

# Verify virtual environment
which python
pip list

Debug Mode

Enable detailed error messages:

DEBUG=True
LOGGING_LEVEL=DEBUG

Log Files

Check application logs:

tail -f logs/modelhub.log

πŸ“ž Support & Contributing

Getting Help

  • πŸ“– Documentation: Check this README and inline code comments
  • πŸ› Issues: Report bugs via GitHub Issues
  • πŸ’¬ Discussions: Join community discussions
  • πŸ“§ Contact: Reach out to maintainers

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Development Roadmap

  • Support for more ML frameworks (XGBoost, LightGBM)
  • Model versioning and A/B testing
  • Batch prediction endpoints
  • Model performance monitoring
  • Docker containerization
  • Kubernetes deployment configs

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


🌟 Community & Social

GitHub discussions LinkedIn Instagram GitHub Profile

Made with ❀️

For more information, visit our documentation or check out the API reference.

About

ModelHub is a Django-based platform that enables seamless deployment, management, and API serving of machine learning models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published