Skip to content

Tomnguyen2604/Gaia_AI_1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 Gaia

Mother Nature AI - A nurturing AI assistant powered by Gemma-2-2B.
Fine-tune via LoRA, chat via Streamlit UI with 32k context window.

πŸ“ Project Structure

Gaia/
β”œβ”€β”€ server/              # AI Backend (all AI components)
β”‚   β”œβ”€β”€ scripts/        # Python scripts (training, chat, utilities)
β”‚   β”œβ”€β”€ data/           # Training datasets
β”‚   β”œβ”€β”€ gaia-merged/    # Fine-tuned models (excluded from git)
β”‚   β”œβ”€β”€ templates/      # Jinja2 templates
β”‚   β”œβ”€β”€ main.py         # FastAPI backend
β”‚   └── rag_system.py   # RAG implementation
β”œβ”€β”€ frontend/           # Next.js Web UI
β”œβ”€β”€ .venv/             # Python virtual environment
β”œβ”€β”€ *.bat              # Quick start scripts
└── *.md               # Documentation

βœ… Features

Core AI

  • βœ… Gemma-2-2B-IT with 32k context window
  • βœ… LoRA fine-tuning with BF16 precision
  • βœ… Up to 8192 token responses
  • βœ… Optimized for RTX GPUs (tested on RTX 5080)
  • βœ… Custom identity training (Gaia persona)
  • βœ… Automatic model validation - detects and backs up corrupted models
  • βœ… Auto-merge after training - ready to use immediately

User Interfaces

  • βœ… Streamlit chat interface with professional dark mode
  • βœ… Next.js Web UI with shadcn/ui components
  • βœ… Real-time settings and conversation history
  • βœ… Voice input support
  • βœ… Conversation export (Markdown, JSON, Text)

Advanced Features

  • βœ… RAG System - Retrieval-Augmented Generation with scientific citations
  • βœ… GraphQL API - Real-time streaming with subscriptions and flexible queries
  • βœ… Multiple dataset support (CSV + HuggingFace)
  • βœ… FastAPI backend for production deployment
  • βœ… Git LFS support for large model files

πŸš€ Quickstart

Installation

# Create virtual environment
python -m venv .venv
.venv\Scripts\activate  # Windows
# source .venv/bin/activate  # Linux/Mac

# Install dependencies
pip install -r requirements.txt

# Install PyTorch with CUDA 13.0 (for RTX 5080)
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu130

# Login to HuggingFace (for Gemma access)
huggingface-cli login

πŸ’¬ Chat with Gaia

Option 1: Streamlit UI (Recommended)

start_chat.bat
# Or: cd server && streamlit run scripts/chat.py

Opens at http://localhost:8501

  • 🌍 Professional dark mode with green theme
  • πŸ’¬ Real-time chat with conversation history
  • βš™οΈ Adjustable settings (tokens, temperature, etc.)
  • πŸ“š Save and load past conversations
  • 32K context window, up to 8K token responses

Option 2: Professional Web UI

start_web_ui.bat

Opens at http://localhost:3000

  • Modern Next.js + shadcn/ui interface
  • FastAPI backend
  • Production-ready design

Fine-tuning

Recommended: Use BF16 for best performance on RTX GPUs

The training script now includes automatic validation and merging:

  1. βœ… Checks if existing merged model is corrupted
  2. πŸ“¦ Backs up corrupted models automatically
  3. πŸš€ Trains new LoRA adapter
  4. πŸ”„ Auto-merges with base model
  5. βœ… Ready to use immediately!
# Quick start with batch files (Windows)
train_safe.bat      # BF16 mode (recommended)
train_8bit.bat      # 8-bit mode (lower VRAM)

# Or run directly:
cd server

# With Gaia identity + knowledge datasets (recommended)
python scripts/finetune.py --datasets-file data/datasets_with_identity.txt --bf16

# With single HuggingFace dataset
python scripts/finetune.py --dataset databricks/databricks-dolly-15k --bf16

# With custom CSV only
python scripts/finetune.py --csv data/gaia_identity.csv --bf16

# Skip auto-merge (manual merge later)
python scripts/finetune.py --datasets-file data/datasets_with_identity.txt --bf16 --skip-merge

# Skip validation (trust existing model)
python scripts/finetune.py --datasets-file data/datasets_with_identity.txt --bf16 --skip-validation

Training Configuration:

  • Batch size: 1 (safe for BF16 full precision)
  • Gradient accumulation: 16 steps
  • Effective batch size: 16
  • Precision: BF16 (recommended) or 8-bit
  • Expected time: ~30-40 minutes for 4000 samples

Corrupted Model Detection: If your merged model generates gibberish, the training script will:

  • Detect the corruption automatically
  • Backup the corrupted model with timestamp
  • Train and create a fresh merged model

🧠 RAG System (Optional)

Add knowledge retrieval with scientific citations:

cd server

# Install RAG dependencies
pip install sentence-transformers chromadb

# Build knowledge base (one-time setup)
python scripts/build_knowledge_base.py

# Start server with RAG enabled
python main.py

See RAG_SETUP.md for detailed instructions.

🌐 Deploy with Cloudflare Tunnel (Public Access)

# Terminal 1: Start Streamlit
cd server && streamlit run scripts/chat.py

# Terminal 2: Start Cloudflare Tunnel
.\cloudflared.exe tunnel --url http://localhost:8501

Get a public HTTPS URL to share your Gaia instance!

πŸš€ Deployment

Deploy Gaia to the cloud for 24/7 access:

Quick Deploy:

# Option 1: Vercel Frontend + Local Backend (Best Performance)
deploy_vercel.bat
start_local_backend.bat

# Option 2: Hugging Face Spaces (24/7 Availability)
# See QUICKSTART_DEPLOYMENT.md

πŸ“š Documentation

πŸ› οΈ Development

Project Organization

All AI-related code is in the server/ directory:

  • server/scripts/ - Training, chat, and utility scripts
  • server/data/ - Training datasets and configuration
  • server/gaia-merged/ - Fine-tuned models (not in git)
  • server/main.py - FastAPI backend server
  • server/rag_system.py - RAG implementation

Running Scripts

Always run scripts from the server/ directory:

cd server

# Training
python scripts/finetune.py --datasets-file data/datasets_with_identity.txt --bf16

# Chat
streamlit run scripts/chat.py

# RAG setup
python scripts/build_knowledge_base.py

# FastAPI server
python main.py

Or use the convenient batch files from the root:

start_chat.bat      # Streamlit UI
start_web_ui.bat    # Next.js + FastAPI
train_safe.bat      # Training (BF16)
train_8bit.bat      # Training (8-bit)

🀝 Contributing

This project uses:

  • Python 3.11+ for AI backend
  • Next.js 14 for web frontend
  • Git LFS for large model files

Model files are excluded from git via .gitignore. Only code and configuration are tracked.

πŸ“„ License

This project uses the Gemma-2-2B model which requires acceptance of Google's terms.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors