Dracula AI Agent
August 2025
An interactive chatbot trained on Bram Stoker’s Dracula. Built with a custom GPT-style model in PyTorch, deployed via FastAPI + Nginx, and featuring a real-time chat UI.
Project Overview
Dracula AI Agent is an interactive, full-stack AI chatbot trained on Bram Stoker’s Dracula. Originally built as a Hugging Face model, it has since been expanded into a production-ready FastAPI web service, hosted on an Ubuntu server with Nginx.
The system combines a PyTorch-based GPT-style model (trained from scratch with tiktoken tokenization) and a frontend chat UI (“VampChat”) that allows users to converse with Dracula in real time. This project demonstrates expertise in machine learning, backend deployment, and AI-driven web applications.
- GPT-style transformer with token and positional embeddings
- Trained with cross-entropy loss using AdamW
- Inference supports temperature/top-k sampling for varied outputs
- tiktoken (GPT-2) encoding for efficient tokenization
- Text chunked into fixed-length context windows with stride
- PyTorch DataLoader batches/shuffles train/validation splits
- Multi-epoch training with periodic validation passes
- Loss tracking and visualization for diagnostics
- Checkpoint save/load via torch.save / torch.load
- FastAPI endpoints (e.g., /generate) serve model inference
- JSON request/response schema for prompts and outputs
- CORS enabled for browser clients behind Nginx
- HTML/CSS/JavaScript chat UI (“VampChat”)
- Sends user prompts to the API; renders model replies (optionally streamed)
- Simple session controls (new chat/clear history)
- Deployed on Ubuntu with Nginx reverse proxying to the FastAPI app
- Nginx serves static frontend and proxies API requests
- Basic logging/monitoring for reliable production use
🧠 Model Architecture
📊 Tokenization & Data Pipeline
🧪 Training & Evaluation
🖥️ Backend API
💬 Frontend
🌐 Hosting & Deployment
Project Features
- 📚 Custom GPT Model: Transformer-style architecture trained on full Dracula text.
- 🔡 tiktoken Tokenization: GPT-2 compatible encoding for efficient batching.
- 🔁 Training Pipeline: PyTorch training loop with checkpointing and evaluation.
- 📈 Diagnostics: Real-time loss visualization with Matplotlib.
- 🧛 Interactive Chat UI: Web frontend where users “talk with Dracula.”
- 🌐 Web Deployment: FastAPI backend served directly, with NGINX handling static frontend files.
- ⚡ Chat Integration: Frontend sends POST requests to FastAPI to generate Dracula’s responses in real time.
Project User Workflow
- Place the cleaned Dracula text into your data directory
- Run training with Python gpt_train.py
- Monitor training loss and visual plots
- Generate text samples using a provided prompt
- Save and load model checkpoints for further experimentation
Technologies Used
- 🐍 Python Core programming language
- 🔦 PyTorch Deep learning framework
- 🔡 tiktoken GPT-2 tokenization library
- 🧠 Custom GPT Transformer model implementation
- 🧪 AdamW Optimizer for stable convergence
- 📈 Matplotlib Visualizing training and validation loss
- 🚀 FastAPI backend API for serving model
- 🌐 JavaScript (ES6), HTML, CSS chat frontend
- 🐧 Ubuntu Server + Nginx production deployment
- 💾 torch.save / torch.load checkpointing