A local-first, full-stack AI chat application β combining real-time LLM conversations with on-device AI image and video generation, all in a sleek ChatGPT-like interface.
Kepler AI runs entirely on your own hardware. No cloud subscriptions. No data leaving your machine. Just a powerful, privacy-first AI assistant powered by Ollama, ComfyUI, and Next.js 14.
| Feature | Description |
|---|---|
| π¬ Real-time Streaming Chat | Token-by-token streaming responses from local LLMs via Server-Sent Events (SSE) |
| π¨ AI Image Generation | Text-to-image powered by ComfyUI + SD Turbo (Stable Diffusion) |
| π₯ AI Video Generation | Text-to-video powered by ComfyUI + AnimateDiff |
| π§ Intent Detection | Auto-detects when you ask for images/videos β no special commands needed |
| π Live Job Polling | Non-blocking background generation with real-time status updates |
| π Remote Access | Cloudflare Tunnel support β share your local AI from anywhere |
| βοΈ Vercel Deployable | Frontend deploys to Vercel; backend exposed via tunnel or cloud GPU |
| π± Fully Responsive | Mobile-friendly chat UI with sidebar navigation |
| π Dark Mode | First-class dark mode support throughout the interface |
| βοΈ Markdown + Code Highlighting | Renders rich markdown with syntax-highlighted code blocks via Shiki |
Kepler is built as a microservice-style local stack. The frontend never calls AI services directly β everything routes through the AI Gateway.
βββββββββββββββ SSE / REST ββββββββββββββββββββββββββββ
β β ββββββββββββββββββΊ β Next.js 14 Frontend β
β User β β (Vercel / localhost) β
β (Browser) β ββββββββββββββββββ β App Router + TypeScriptβ
βββββββββββββββ Streamed UI ββββββββββββ¬ββββββββββββββββ
β REST / SSE Proxy
βΌ
ββββββββββββββββββββββββββββ
β AI Gateway (Python) β
β FastAPI @ port 9000 β
β βββββββββββββββββββββββββ
β β /chat β Ollama ββ
β β /image β ComfyUI ββ
β β /video β ComfyUI ββ
β βββββββββββββββββββββββββ
ββββββ¬βββββββββββ¬ββββββββββββ
β β
SSE Stream β β HTTP + WebSocket
βΌ βΌ
βββββββββββββββ ββββββββββββββββ
β Ollama β β ComfyUI β
β qwen2.5 LLM β β SD Turbo / β
β port 11434 β β AnimateDiff β
βββββββββββββββ β port 8188 β
ββββββββββββββββ
| Service | Technology | Port | Purpose |
|---|---|---|---|
| Frontend | Next.js 14 (TypeScript) | 3000 |
Chat UI, media rendering, polling |
| AI Gateway | FastAPI (Python) | 9000 |
Central API proxy & job orchestrator |
| LLM Engine | Ollama (qwen2.5) |
11434 |
Text generation & intent detection |
| Image/Video Engine | ComfyUI | 8188 |
Stable Diffusion & AnimateDiff inference |
| Tech | Version | Purpose |
|---|---|---|
| Next.js | ^14.2 |
App Router, SSR, API Routes |
| React | ^18.3 |
UI component system |
| TypeScript | ^5.5 |
Type-safe frontend |
| Tailwind CSS | ^3.4 |
Utility-first styling |
| Shadcn UI / Radix UI | Latest | Accessible UI primitives |
| Lucide React | ^0.400 |
Icon library |
| react-markdown | ^9.0 |
Markdown rendering |
| Shiki | ^1.0 |
Syntax highlighting for code blocks |
| remark-gfm | ^4.0 |
GitHub Flavored Markdown support |
| Tech | Version | Purpose |
|---|---|---|
| FastAPI | >=0.111 |
Async Python web framework |
| Uvicorn | >=0.30 |
ASGI server |
| httpx | >=0.27 |
Async HTTP client for service calls |
| Pydantic | >=2.7 |
Request/response validation |
| Tech | Version | Purpose |
|---|---|---|
| FastAPI | 0.109.2 |
Direct generation API |
| Websockets | 12.0 |
ComfyUI WebSocket protocol |
| websocket-client | 1.7.0 |
Synchronous WS connection |
| Requests | 2.31.0 |
HTTP calls to Ollama |
| Service | Purpose |
|---|---|
| Ollama | Runs local LLMs β default model: qwen2.5:latest |
| ComfyUI | Node-graph AI inference engine |
SD Turbo (sd_turbo.safetensors) |
Fast Stable Diffusion model for image generation |
AnimateDiff (mm_sd_v15_v2.ckpt) |
Motion module for video/animation generation |
| Tool | Purpose |
|---|---|
| Vercel | Frontend deployment (serverless Next.js) |
| Cloudflare Tunnel | Expose local GPU services to the internet (free) |
| Windows Batch Scripts | One-click local startup orchestration |
Kepler/
βββ app/ # Next.js 14 App Router
β βββ api/ # Server-side API Routes (proxies to Gateway)
β β βββ chat/
β β β βββ route.ts # SSE streaming proxy β Gateway /chat
β β βββ image/
β β β βββ route.ts # Trigger image generation β Gateway /image
β β β βββ status/[jobId]/
β β β βββ route.ts # Poll image job status
β β βββ video/
β β β βββ route.ts # Trigger video generation β Gateway /video
β β β βββ status/[jobId]/
β β β βββ route.ts # Poll video job status
β β βββ generated/ # (Static generated media serving)
β βββ chat/
β β βββ page.tsx # Main chat UI page
β βββ globals.css # Global styles + dark mode variables
β βββ layout.tsx # Root layout
β
βββ components/ # Reusable React components
β βββ ChatMessage.tsx # Individual chat bubble (text/image/video)
β βββ ChatList.tsx # Scrollable message list
β βββ ChatInput.tsx # Text input with send button
β βββ MediaDisplay.tsx # Image/video render with loading state
β βββ Sidebar.tsx # Navigation sidebar
β βββ CodeBlock.tsx # Syntax-highlighted code block
β βββ ui/ # Shadcn UI primitives
β
βββ lib/ # Core frontend utilities & clients
β βββ llm.ts # SSE streaming client, message types
β βββ generation.ts # Intent parser, image/video trigger hooks
β βββ job-store.ts # In-memory job tracking (client side)
β βββ comfyui.ts # ComfyUI workflow definitions & API
β βββ cogvideo.ts # CogVideo workflow integration
β βββ system_prompt.ts # System prompt configuration
β
βββ gateway/ # AI Gateway β FastAPI microservice
β βββ main.py # FastAPI app, route registration (port 9000)
β βββ utils.py # Job store, health checks
β βββ requirements.txt # Python dependencies
β βββ routes/
β β βββ chat.py # POST /chat β SSE proxy to Ollama
β β βββ image.py # POST /image + GET /image/status/{jobId}
β β βββ video.py # POST /video + GET /video/status/{jobId}
β βββ services/
β βββ ollama_service.py # Async SSE streaming from Ollama
β βββ comfy_service.py # ComfyUI job trigger, poll, base64 fetch
β βββ routing_service.py # Optional intent-based routing logic
β
βββ backend/ # Legacy direct backend (FastAPI, port 8000)
β βββ main.py # Synchronous image/video generation endpoints
β βββ utils.py # WebSocket connection to ComfyUI
β βββ requirements.txt # Python dependencies
β βββ start_services.py # Service manager
β
βββ ComfyUI/ # Local ComfyUI installation (git submodule / clone)
β
βββ docs/ # Documentation assets
β
βββ START_ALL_SERVICES.bat # π One-click: starts all 4 services
βββ START_GATEWAY.bat # Starts the AI Gateway only
βββ START_GENERATION_SERVICES.bat # Starts ComfyUI (and optionally backend)
βββ START_TUNNEL.bat # Starts Cloudflare Tunnel for remote access
β
βββ .env.local # Local environment configuration
βββ next.config.js # Next.js config
βββ tailwind.config.js # Tailwind theme config
βββ tsconfig.json # TypeScript config
βββ package.json # Node.js dependencies
- User types a message in
ChatInput.tsx lib/generation.ts::parseGenerationCommand()checks if it's an image/video request- If it's plain text β
lib/llm.ts::streamLLMResponse()POSTs to/api/chat - Next.js API route proxies the request to the AI Gateway (
http://127.0.0.1:9000/chat) - Gateway streams the response from Ollama as Server-Sent Events (SSE)
- Frontend decodes the token stream and progressively updates the message bubble
- If the LLM's response itself contains an image/video intent, generation is auto-triggered
User: "generate an image of a sunset"
β
βΌ
parseGenerationCommand() β { type: 'image', prompt: 'a sunset' }
β
βΌ
POST /api/image β Gateway POST /image
β β
β βΌ
β trigger_image_job()
β - Builds SD Turbo ComfyUI workflow JSON
β - POST to ComfyUI /prompt
β - Returns { job_id }
β - Starts background async poll_comfyui()
β
βΌ
Frontend gets { jobId }
Adds "Generating image..." placeholder message (MediaDisplay.tsx)
β
βΌ every 2 seconds
GET /api/image/status/[jobId] β Gateway GET /image/status/{jobId}
β
βΌ (when completed)
ComfyUI output fetched as raw bytes
β base64 encoded Data URL (data:image/png;base64,...)
β stored in job store
β
βΌ
Frontend replaces placeholder with <img> rendered from base64 data URL
The base64 Data URL approach ensures cross-origin compatibility β works both locally and when the gateway is behind a Cloudflare tunnel.
- Node.js 18+ and npm
- Python 3.10+
- Ollama installed and running
- Ollama model pulled (default:
qwen2.5)ollama pull qwen2.5
- ComfyUI installed in
./ComfyUI - ComfyUI models placed in
ComfyUI/models/:checkpoints/sd_turbo.safetensorsβ for image generationanimatediff_models/mm_sd_v15_v2.ckptβ for video generation
npm installcd gateway
pip install -r requirements.txt
cd ..Create .env.local in the project root:
# Local development defaults
AI_GATEWAY_URL=http://127.0.0.1:9000
LOCAL_LLM_URL=http://127.0.0.1:11434
COMFYUI_URL=http://127.0.0.1:8188
# For Vercel + Cloudflare Tunnel (production):
# AI_GATEWAY_URL=https://your-tunnel-id.trycloudflare.comOption A β One-click (Recommended for Windows):
START_ALL_SERVICES.batThis script automatically:
- Checks if Ollama is running (starts it if not)
- Starts image & video generation services (ComfyUI)
- Starts the AI Gateway (port 9000)
- Starts Next.js dev server (port 3000)
Option B β Manual startup:
# Terminal 1: Start Ollama
ollama serve
# Terminal 2: Start ComfyUI
cd ComfyUI && python main.py
# Terminal 3: Start AI Gateway
cd gateway && uvicorn main:app --host 0.0.0.0 --port 9000 --reload
# Terminal 4: Start Next.js
npm run devOpen http://localhost:3000 in your browser.
This is the recommended approach if you want to access Kepler from anywhere while keeping all AI inference on your local GPU.
Architecture:
Browser β Vercel (Next.js frontend) β Cloudflare Tunnel β Your Local Machine (Gateway + Ollama + ComfyUI)
Steps:
Step 1: Install cloudflared
winget install --id Cloudflare.cloudflaredStep 2: Start your local services
START_ALL_SERVICES.batStep 3: Start the Cloudflare Tunnel (exposes Gateway port 9000)
START_TUNNEL.batCopy the generated URL (e.g., https://xxxx.trycloudflare.com).
Step 4: Deploy the frontend to Vercel
npx vercel --prodStep 5: Set environment variable on Vercel In your Vercel dashboard β Project Settings β Environment Variables:
AI_GATEWAY_URL = https://xxxx.trycloudflare.com
Notes:
- The Cloudflare Tunnel URL changes each time you restart
START_TUNNEL.bat. For a permanent URL, use a named tunnel with acloudflaredconfig file. - All inference stays on your hardware β Vercel only serves the UI
- Free tier on both Vercel and Cloudflare works perfectly for personal use
For 24/7 availability without keeping your local machine running:
- Spin up a GPU instance (e.g., RunPod, Vast.ai, Lambda Labs, AWS g4dn)
- Install Ollama + ComfyUI + the Gateway on the cloud instance
- Set
AI_GATEWAY_URLin Vercel to point to your cloud instance's public IP/domain - (Optional) Put NGINX in front of the Gateway as a reverse proxy with SSL
Edit gateway/services/ollama_service.py:
"model": "llama3.2", # or mistral, gemma2, phi4, etc.Then pull the model:
ollama pull llama3.2The default is 512Γ512 (optimized for SD Turbo speed). Edit gateway/services/comfy_service.py:
def create_image_workflow(prompt: str, width: int = 768, height: int = 768):In comfy_service.py, update the checkpoint name:
"4": {"class_type": "CheckpointLoaderSimple", "inputs": {"ckpt_name": "your_model.safetensors"}},Place the model in ComfyUI/models/checkpoints/.
Edit lib/system_prompt.ts to give the AI a persona or set of instructions.
Modify app/globals.css for CSS custom properties and tailwind.config.js for the design token system.
| Variable | Default | Description |
|---|---|---|
AI_GATEWAY_URL |
http://127.0.0.1:9000 |
URL of the AI Gateway service |
LOCAL_LLM_URL |
http://127.0.0.1:11434 |
Ollama API base URL |
COMFYUI_URL |
http://127.0.0.1:8188 |
ComfyUI server URL |
- Persistent chat history (local SQLite or IndexedDB)
- Multiple model selection UI
- Image-to-image and inpainting support
- File/document upload for RAG-style Q&A
- Named Cloudflare Tunnel for a persistent public URL
- Docker Compose setup for one-command deployment
MIT β Do whatever you want. Ship it, fork it, hack it.
Built with β€οΈ using Ollama, ComfyUI, Next.js, and FastAPI.