Test / README.md
Hfzune's picture
Upload 11 files
330e43a verified
|
Raw History Blame Contribute Delete
3.45 kB
---
title: TTT v1.4 — Adaptive Lossless Transmitter
emoji: 📦
colorFrom: blue
colorTo: indigo
sdk: gradio
app_file: app.py
python_version: "3.11"
---
# TTT v1.4 — Adaptive Lossless Transmitter
A lossless, byte-oriented compression/transmission testbed. Uses Gradio Server mode (Gradio 6.30+) to host the interface and custom binary API on one managed port. Auto mode tries raw, GZIP, Zstandard and BZIP2 and keeps the **smallest complete packet**. The receiver checks a declared length and CRC-32 before returning the original bytes.
## UI
- **Encode text**: paste text and download a `.ttt4` packet.
- **Encode a file**: encode arbitrary file bytes.
- **Decode packet**: reconstruct the original bytes from a `.ttt4` file.
The interface is served at `/ui/`; `/` redirects there. The binary API remains at the root paths below.
## HTTP API
The app also exposes simple binary HTTP endpoints alongside the Gradio UI:
- `GET /health`
- `GET /api/spec`
- `POST /encode?mode=auto` — request body is original bytes; response body is a TTT4 packet.
- `POST /decode` — request body is a TTT4 packet; response body is the exact original bytes.
Example:
```bash
curl -sS --data-binary @input.txt 'https://YOUR-SPACE.hf.space/encode?mode=auto' -o message.ttt4
curl -sS --data-binary @message.ttt4 'https://YOUR-SPACE.hf.space/decode' -o restored.txt
cmp input.txt restored.txt
```
For local testing:
```bash
python -m pip install -r requirements.txt
python self_test_v14.py
python test_api_v14.py
python app.py
```
## Wire format
The packet has a 13-byte binary header: `TTT4` magic (4 bytes), codec ID (1 byte), original length (4-byte big-endian unsigned integer), and CRC-32 of the original bytes (4-byte big-endian integer), followed by the payload. Codec IDs: 0 raw, 1 gzip, 2 Zstandard, 3 BZIP2.
Safety limits per request: 16 MiB of original bytes and 32 MiB per packet. These limits are prototype guardrails, not a denial-of-service protection system by themselves. Public deployments should use reasonable hardware and monitoring.
## Why there is no tokenizer vocabulary file
TTT v1.4 uses byte-preserving general-purpose compressors rather than a tokenizer vocabulary. A language-model tokenizer is primarily for mapping text into model tokens; it is not automatically a more efficient lossless wire codec. Avoiding a shared vocabulary removes first-use download cost and dictionary-version mismatch. A trained shared compression dictionary can be added later after testing on a representative corpus and measuring its distribution cost.
## Results and limitations
No fixed compression ratio is promised. Short messages and already-compressed data can become larger because the TTT header adds 13 bytes. Auto mode compares available encoder outputs on the input itself, so it can choose raw when compression would cost more. Benchmarks should use representative text, JSON, source code, logs, binary data, and both small and large message sizes.
Hugging Face note: this version uses the Gradio Server mode launcher (`app.launch()`) rather than manually starting Uvicorn on port 7860. Gradio 6.30 or newer is required.
This project is an experimental transmission demo. Use HTTPS in deployment, keep dependencies patched, and do not expose sensitive content in shared/public test spaces. CRC-32 catches accidental corruption; it is not cryptographic authentication or encryption. Compression does not provide confidentiality.