Skip to content

Bucin404/AI-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Platform

Full-stack AI chat platform with intelligent model routing built with Flask, Tailwind CSS, and open-source AI models.

Features

πŸ€– Intelligent Model Routing

  • DeepSeek Coder: Specialized for coding, debugging, and programming tasks
  • Llama.cpp: Optimized for document processing, PDFs, and large files
  • Vicuna: Multimodal AI for images, videos, and rich media content
  • GPT4All: General-purpose conversational AI for everyday tasks
  • Auto-Select: Automatically routes queries to the best model based on content type

✨ Core Features

  • User authentication with registration, login, and password reset
  • Rate limiting by tier (Free: 10/hour, Premium: 100/hour, Admin: 1000/hour)
  • Chat history with message persistence
  • Admin panel for user management and analytics
  • Payment integration with Midtrans
  • Email notifications via Postfix SMTP
  • Dark/light mode toggle
  • Markdown rendering with code syntax highlighting
  • RESTful API for programmatic access

πŸ›‘οΈ Security

  • CSRF protection
  • Secure password hashing (Werkzeug)
  • Session management with secure cookies
  • Rate limiting (Redis-backed)
  • Input sanitization
  • Security headers (CSP, X-Frame-Options, etc.)

Quick Start

Using Docker (Recommended)

# Clone repository
git clone https://github.com/Bucin404/AI-platform.git
cd AI-platform

# Configure environment
cp .env.example .env
# Edit .env with your configuration

# Download & integrate AI models (AUTOMATIC - recommended!)
python download_models.py
# Downloads models + installs dependencies + configures platform
# Use --lite for smaller models (~1.6GB vs ~16GB)

# Start services
docker-compose up -d

# Initialize database
docker-compose exec web flask db upgrade

# Create admin user
docker-compose exec web flask create-admin

# Access at http://localhost:5000

Using Docker on MacBook M4 (Apple Silicon)

# Use M4-optimized configuration
docker-compose -f docker-compose.m4.yml up -d

# Initialize database
docker-compose -f docker-compose.m4.yml exec web flask db upgrade

# Create admin user
docker-compose -f docker-compose.m4.yml exec web flask create-admin

# See full M4 setup guide: docs/SETUP_M4.md

Local Development (Without Docker)

Important: For local development, use .env.local.example instead of .env.example:

# Clone and setup
git clone https://github.com/Bucin404/AI-platform.git
cd AI-platform

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Configure for LOCAL development
cp .env.local.example .env
# Edit .env - use localhost for database, or SQLite for simplicity

# Option 1: Use SQLite (no PostgreSQL needed)
# In .env: DATABASE_URL=sqlite:///app.db

# Option 2: Use local PostgreSQL
# Install PostgreSQL, create database, then:
# In .env: DATABASE_URL=postgresql://user:pass@localhost:5432/aiplatform

# Initialize database
export FLASK_APP=run.py
flask db init
flask db migrate -m "Initial migration"
flask db upgrade

# Download AI models (automatic integration!)
python download_models.py

# Run application
python run.py

# Access at http://localhost:5000

Troubleshooting? See docs/TROUBLESHOOTING.md for common issues and solutions.

Previous Local Development

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Set up environment
cp .env.example .env
# Edit .env with your configuration

# Download & integrate AI models (AUTOMATIC!)
python download_models.py --lite  # Lite version for local dev (~1.6GB)
# Or use: python download_models.py  # Full version (~16GB)
# This automatically installs deps and configures the platform!

# Initialize database
export FLASK_APP=run.py
flask db init
flask db migrate -m "Initial migration"
flask db upgrade

# Create admin user
flask create-admin

# Run application
python run.py

Documentation

Tech Stack

Backend:

  • Flask (Python web framework)
  • PostgreSQL (Database)
  • Redis (Caching & rate limiting)
  • SQLAlchemy (ORM)
  • Flask-Login (Authentication)
  • Flask-WTF (Forms & CSRF)
  • Flask-Mail (Email)
  • Flask-Limiter (Rate limiting)
  • Flask-Migrate (Database migrations)

Frontend:

  • Tailwind CSS (Styling)
  • Vanilla JavaScript
  • Marked.js (Markdown rendering)
  • Highlight.js (Code syntax highlighting)

AI Models:

  • DeepSeek Coder
  • Llama.cpp
  • Vicuna
  • GPT4All

Infrastructure:

  • Docker & Docker Compose
  • Nginx (Reverse proxy)
  • Postfix (Email)
  • Midtrans (Payments)

Project Structure

AI-platform/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ blueprints/          # Flask blueprints
β”‚   β”‚   β”œβ”€β”€ auth/            # Authentication routes
β”‚   β”‚   β”œβ”€β”€ chat/            # Chat routes
β”‚   β”‚   β”œβ”€β”€ admin/           # Admin panel routes
β”‚   β”‚   β”œβ”€β”€ payments/        # Payment routes
β”‚   β”‚   └── api/             # API routes
β”‚   β”œβ”€β”€ models/              # Database models
β”‚   β”œβ”€β”€ services/            # Business logic services
β”‚   β”‚   β”œβ”€β”€ model_service.py # AI model adapters
β”‚   β”‚   β”œβ”€β”€ email_service.py # Email service
β”‚   β”‚   └── payment_service.py # Payment service
β”‚   β”œβ”€β”€ templates/           # HTML templates
β”‚   β”œβ”€β”€ static/              # Static files (CSS, JS)
β”‚   └── utils/               # Utility functions
β”œβ”€β”€ tests/                   # Unit tests
β”œβ”€β”€ docs/                    # Documentation
β”œβ”€β”€ config.py                # Configuration
β”œβ”€β”€ run.py                   # Application entry point
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ Dockerfile               # Docker configuration
└── docker-compose.yml       # Docker Compose configuration

Environment Variables

See .env.example for all required environment variables. Key variables:

# Flask
SECRET_KEY=your-secret-key
DEBUG=False

# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/aiplatform

# Redis
REDIS_URL=redis://localhost:6379/0

# Email (Postfix)
MAIL_SERVER=localhost
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=

# Midtrans Payment
MIDTRANS_SERVER_KEY=your-server-key
MIDTRANS_CLIENT_KEY=your-client-key
MIDTRANS_IS_PRODUCTION=False

# Admin
ADMIN_EMAIL=admin@aiplatform.com
ADMIN_PASSWORD=changeme

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=app tests/

# Run specific test file
pytest tests/test_auth.py

API Usage

import requests

# Login
session = requests.Session()
session.post('http://localhost:5000/auth/login', data={
    'email': 'user@example.com',
    'password': 'password'
})

# Send chat message with auto model selection
response = session.post('http://localhost:5000/api/chat', json={
    'message': 'Write a Python function to sort a list',
    'model': 'auto'  # Will automatically use DeepSeek for coding
})

print(response.json())

Model Routing Logic

The platform intelligently routes queries based on content detection:

Query Type Model Example Keywords
Coding DeepSeek Coder code, function, debug, python, javascript
Documents Llama.cpp pdf, document, file, csv
Images/Videos Vicuna image, photo, video, analyze
General GPT4All weather, explain, tell me

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Support

Credits

Built with ❀️ using open-source AI models and modern web technologies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors