Metadata-Version: 2.4
Name: minillama
Version: 0.2.1
Summary: A private local AI workspace for llama.cpp, ComfyUI media studios, and LAN/PWA access
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31
Requires-Dist: Pillow>=10.0
Requires-Dist: pystray>=0.19
Requires-Dist: psutil>=5.9
Requires-Dist: gguf>=0.10
Requires-Dist: cryptography>=42.0
Requires-Dist: numpy>=1.26
Dynamic: license-file

# MiniLlama (Python)

Private, local-first AI workspace for running GGUF language & vision models (`llama.cpp`), Image / Video / Music studios (`ComfyUI`), fast PC-to-Phone checkpoint conversion, and self-contained on-device Android inference.

---

## Features

- **Modern Dark Chat Workspace**: Sleek obsidian & emerald-sapphire web dashboard inspired by ChatGPT and Gemini — collapsible sidebar with instant search and floating `More` menu, centered pill composer with `+` tools popover, streaming responses, stop controls, and responsive phone layout with zero ads or subscription prompts.
- **First-Start Setup Questionnaire & Live Available-VRAM Model Recommender**:
  - Measures **real-time available (free) VRAM** on your GPU (or available RAM on Android) *before* making any suggestions.
  - Fetches live trending **Hugging Face** models across **LLMs (GGUF)**, **Images**, **Video**, and **Music** that actually fit your current hardware budget.
  - Works for both **PC** and **Phone** targets, with options to skip setup or enter any custom Hugging Face repo / model name manually.
- **Local LLM & Vision Chat**: OpenAI-compatible (`/v1/*`) and Ollama-compatible (`/api/*`) local API on port `11434`, automatic GGUF metadata inspection, vision `mmproj` pairing, and multi-engine support (`llama.cpp`, `KoboldCpp`, `ik_llama.cpp`).
- **Image, Video & Music Studios (ComfyUI)**:
  - **Image Studio**: Stable Diffusion (SD 1.5, SDXL, Illustrious, Flux, SD3), LoRAs, img2img, and optional upscaling with Hugging Face & Civitai downloads.
  - **Video Studio**: Local text-to-video and image-to-video workflows (Wan 2.2, LTX-Video).
  - **Music Studio**: Original song generation and audio-to-music covers using YuE2 (with SheetSage2 conditioning) and ACE-Step.
  - **Automatic VRAM Handoff & Persistent Gallery**: Automatically unloads the active LLM before running media jobs (and frees ComfyUI VRAM before loading an LLM) while saving all outputs in a browsable local gallery.
- **PC-to-Phone Fast LAN Transfer & Streaming Converter**: On-the-fly streaming conversion of `.safetensors` checkpoints to **FP8** (`F8_E4M3`), **4-Bit GGUF (`Q4_0`)**, or **8-Bit GGUF (`Q8_0`)** over LAN with HTTP Range resume.
- **Self-Contained Android App (`mobile/android/` -> `MiniLlama.apk`)**:
  - Runs GGUF LLMs and Stable Diffusion directly on Android via Vulkan GPU, CPU, Hybrid, or NPU modes.
  - Dynamic **Phone Link** QR & 6-digit code pairing with `.local` mDNS support and rotating LAN tokens.
  - Hardened mobile privacy: anonymous `Mozilla/5.0` headers, reduced WebView User-Agent, and zero device metadata sent to external servers.
  - Built-in **GitHub Releases Self-Updater**: automatically checks `minillama-dev` GitHub Releases, verifies the APK SHA-256 checksum against `SHA256SUMS.txt`, and upgrades in place without needing a PC.
- **Performance Lab & Auto-Tune**: Live hardware telemetry, multi-GPU layer split and loop-aware tensor placement, safe OOM KV-cache fallbacks (`f16` -> `q8_0` -> `q4_0` without shrinking your context length), speculative decoding, and built-in benchmarking.

---

## Installation

### Option 1: Install via `pip` (Wheel, GitHub, or PyPI)

Because MiniLlama is packaged as a standard Python wheel (`minillama-0.2.1-py3-none-any.whl`), you can install it directly with `pip`:

```bash
# Directly from PyPI:
pip install minillama

# Or from a downloaded GitHub Release wheel:
pip install https://github.com/minillama-dev/minillama-py/releases/download/v0.2.1/minillama-0.2.1-py3-none-any.whl

# Or straight from the GitHub repository:
pip install git+https://github.com/minillama-dev/minillama-py.git
```

After installing via `pip`, download the optimal inference engine for your GPU and launch the app:

```bash
minillama update              # Download the best llama.cpp build for your GPU
minillama serve               # Start daemon + tray icon and open the dashboard
```

> **Why is the `.whl` only ~900 KB?**
> A `.whl` file is a Deflate-compressed ZIP archive containing all 38 Python source modules, the full web dashboard, app icons, and package metadata (`entry_points` + `dependencies`). When you run `pip install`, `pip` automatically downloads the required Python libraries (`requests`, `Pillow`, `psutil`, `pystray`, `gguf`, `cryptography`, `numpy`) from PyPI. Heavy OS/GPU-specific runtimes (`llama.cpp`, ComfyUI + PyTorch) and AI model weights are downloaded on demand so the wheel stays tiny and cross-platform.

### Option 2: Modular One-Click Installer (Recommended for Full Setup)

Installs an isolated `.venv`, MiniLlama, the best `llama.cpp` GPU build, the native Desktop App wrapper, and **ComfyUI Media Studio** automatically.

**Windows:**
```powershell
install.bat
```

**macOS / Linux:**
```bash
chmod +x install.sh start_minillama.sh minillama.sh
./install.sh --add-path
```

**Or run `install.py` directly on any OS with modular flags:**
```bash
python install.py                    # Full modular install (Core + llama.cpp + Desktop App + ComfyUI)
python install.py --interactive      # Pick modules interactively
python install.py --no-comfyui       # Skip ComfyUI Media Studio
python install.py --no-engine        # Skip llama.cpp download
python install.py --no-desktop-app   # Skip Desktop App wrapper
python install.py --port 11500 --autostart --add-path --lan --start
```

### Option 3: Portable Archive & Android APK

- **Portable Python Zip (`minillama-py-portable.zip`)**: Extract anywhere and run `install.bat` (Windows) or `./install.sh` (macOS/Linux).
- **Android (`MiniLlama.apk`)**: Transfer or scan the QR code from the dashboard's **Phone Link** tab to install the companion on-device Android app.

> Looking for a **zero-Python native C++20 binary** with graphical installers for Windows, macOS, and Linux? See the companion **[minillama-cpp](https://github.com/minillama-dev/minillama-cpp)** repository.

---

## Quick Usage

```bash
# Launch Desktop App
start_minillama_app.bat      # Windows
./start_minillama_app.sh     # macOS / Linux

# Or start daemon + tray + web dashboard (http://127.0.0.1:11434)
minillama serve

# Pull any GGUF directly from Hugging Face
minillama pull bartowski/Qwen2.5-7B-Instruct-GGUF:Q4_K_M

# Import existing Ollama or LM Studio models (uses hard links — zero extra disk space)
minillama import ollama
minillama import lmstudio
```

---

## CLI Reference

| Command | Description |
| :--- | :--- |
| `minillama serve [--no-tray]` | Start the daemon in the foreground (HTTP API, dashboard, and tray icon). |
| `minillama daemon` | Run the background daemon (used by autostart). |
| `minillama list` | List all local GGUF models and SD checkpoints. |
| `minillama pull <user>/<repo>[:<quant>]` | Download a GGUF model (and vision `mmproj` if present) from Hugging Face. |
| `minillama import ollama \| lmstudio` | Import local models from Ollama or LM Studio via hard links. |
| `minillama run <model> [prompt] [--ctx N]` | Load a model and open an interactive terminal chat or run a one-shot prompt. |
| `minillama load <model> [--ctx N]` | Load a model into memory without opening terminal chat. |
| `minillama unload` | Unload the active model and free VRAM/RAM while keeping the daemon running. |
| `minillama ps` / `minillama status` | Show daemon health, loaded model, context size, and live GPU/VRAM usage. |
| `minillama endpoints` | Display OpenAI- and Ollama-compatible local API URLs. |
| `minillama image "<prompt>" [--image file] [--upscale]` | Generate or edit an image via ComfyUI (`--aspect`, `--lora`, `--steps`, `--cfg`). |
| `minillama video "<prompt>" [--image file] [--res 720\|1080]` | Generate a text-to-video or image-to-video clip via ComfyUI. |
| `minillama music "<style>" [--lyrics ...] [--audio file]` | Generate a song or YuE2 music cover locally via ComfyUI. |
| `minillama gallery [list \| rm <id>]` | Browse or delete saved image, video, and music outputs. |
| `minillama lan [status \| on \| off \| rotate \| rotation \| code]` | Manage Phone Link LAN access, token rotation, `.local` URL, and 6-digit pairing codes. |
| `minillama engine [list \| set \| update <id\|all> \| auto-update \| tune]` | Manage `llama.cpp`, `KoboldCpp`, `ik_llama.cpp`, and `ComfyUI`. |
| `minillama update` | Install the latest verified `llama.cpp` build (retains the newest two builds). |
| `minillama config [show \| get \| set \| reset]` | View or update runtime profiles, KV cache, speculation, threads, batch size, and ports. |
| `minillama net list \| allow \| deny \| firewall` | Inspect or edit the outbound host whitelist. |
| `minillama autostart on \| off` | Toggle daemon startup at OS login (never auto-loads a model). |
| `minillama rm <model> [--trash]` | Delete a model (or move to `_trash`). |
| `minillama stats [reset]` | View or reset peak tokens/second metrics. |
| `minillama restart [--daemon]` | Reload the active model or restart the daemon. |
| `minillama stop` / `minillama kill` | Gracefully stop the daemon or terminate tracked MiniLlama processes. |
| `minillama selftest` | Run isolated self-tests for Phone Link, VRAM handoff, and media endpoints. |

---

## HTTP API

See **[API.md](API.md)** for full documentation of all OpenAI-compatible (`/v1/*`), Ollama-compatible (`/api/*`), Media/Gallery (`/api/media/*`), Recommender/Control/Updater (`/minillama/*`), and LAN Pairing endpoints.

---

## Privacy, Memory & Architecture

- **100% Local Inference**: Prompts, images, audio, and videos are processed strictly on your hardware.
- **Zero Device Telemetry**: Trending model recommendations query Hugging Face with generic anonymous headers (`Mozilla/5.0`), never sending hardware IDs, phone model strings, or personal paths.
- **Strict Outbound Whitelist**: Outbound downloads go through `minillama/net.py`, enforcing an allowlist (`*.huggingface.co`, `*.hf.co`, `*.github.com`, `*.githubusercontent.com`), manual redirect validation, cross-host credential stripping, and SHA-256 verification.
- **Loopback by Default**: Binds to `127.0.0.1` until you explicitly enable **Phone Link (LAN mode)** with rotating access tokens and short-lived 6-digit pairing codes.
- **Exact GGUF Context & Safe OOM Fallbacks**: Uses the model's true GGUF `context_length` by default without silently shrinking it, stepping down KV cache precision (`f16` -> `q8_0` -> `q4_0`) on OOM.
- **Standard Data Locations** (override via `MINILLAMA_HOME`):
  - **Windows**: `%APPDATA%\MiniLlama` (config) & `%LOCALAPPDATA%\MiniLlama` (engines, models, logs)
  - **macOS**: `~/Library/Application Support/MiniLlama`
  - **Linux**: `$XDG_CONFIG_HOME/minillama` & `$XDG_DATA_HOME/minillama`

---

## Building the Wheel & Publishing to PyPI

```bash
pip install build twine
python -m build --wheel          # Creates dist/minillama-0.2.0-py3-none-any.whl
twine upload dist/*.whl          # Publish to PyPI so anyone can run: pip install minillama
```

## Running Tests

```bash
pytest -q
```

## License

MIT — see [LICENSE](LICENSE).
