Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ cython_debug/

# Project-specific files
design/

# macOS
.DS_Store

# Local translation files
durex/
94 changes: 84 additions & 10 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,91 @@
# Notes for Claude
# CLAUDE.md

## Environment Setup
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

- Use `uv pip install` instead of regular pip for package installation
- For local development installation: `uv pip install -e .`
## Project Overview

## Common Commands
Tinbox is a CLI tool for translating large documents (especially PDFs) using LLMs. It handles model limitations, bypasses refusals, and uses multimodal capabilities for direct PDF translation without OCR.

Use `tinbox --help` to see all available options. A few useful commands:
## Development Commands

- `tinbox --to es document.pdf` — translate a PDF to Spanish
- `tinbox --from zh --to en document.docx` — translate a Word document from Chinese to English
### Installation
- Use `uv pip install -e .` for development installation (not regular pip)
- Install with extras: `uv pip install -e ".[pdf,docx,dev]"`

## Project-Specific Information
### Testing
```bash
pytest # Run all tests
pytest tests/test_cli.py # Run specific test file
pytest -k test_name # Run specific test
pytest --cov=tinbox # Run with coverage
```

- Pillow is required for image processing in the PDF processor and LiteLLM translator
### Code Quality
```bash
ruff check . # Run linter
ruff format . # Format code
mypy src/tinbox # Type checking
black src tests # Alternative formatter
isort src tests # Sort imports
```

## Architecture

### Translation Pipeline
1. **Document Loading** (`core/processor/`): Handles PDF, DOCX, and text files
- PDF: Converts pages to images for multimodal processing
- DOCX: Extracts text while preserving structure
- Text: Direct text processing

2. **Translation Algorithms** (`core/translation/algorithms.py`):
- **Page-by-page**: Default for PDFs, includes seam repair between pages
- **Sliding window**: For long text documents, maintains context overlap

3. **Model Interfaces** (`core/translation/`):
- `interface.py`: Protocol definition for model implementations
- `litellm.py`: LiteLLM integration for OpenAI/Anthropic/Ollama
- Supports checkpointing for resumable translations

4. **Cost Management** (`core/cost.py`):
- Estimates tokens and costs before translation
- Warns about high-cost operations
- Tracks actual usage during translation

## Key Technical Details

- **Model Specification Format**: `provider:model` (e.g., `anthropic:claude-3-sonnet`, `openai:gpt-4o`, `ollama:mistral-small`)
- **GPT-5 Support**: Full support for OpenAI's GPT-5 models (`gpt-5`, `gpt-5-mini`, `gpt-5-nano`)
- GPT-5 models automatically use optimized translation parameters:
- `reasoning_effort="low"` (faster processing, adequate quality for translation)
- `verbosity="low"` (concise output without explanations)
- Temperature/top_p are NOT supported by GPT-5 (automatically excluded)
- **GPT-5 Pricing** (accurate cost tracking implemented):
- `gpt-5`: $1.25/$10.00 per 1M tokens (input/output)
- `gpt-5-mini`: $0.25/$2.00 per 1M tokens (recommended for most translations)
- `gpt-5-nano`: $0.05/$0.40 per 1M tokens (fastest, most economical)
- **Language codes**: ISO 639-1 format with aliases (e.g., 'en', 'zh', 'es')
- **Source language 'auto'**: Accepted as valid value for automatic detection in LiteLLM translator
- **Async architecture**: Core translation operations use asyncio
- **Progress tracking**: Rich library for terminal UI
- **Pillow dependency**: Required for PDF image processing

## Common Usage Examples

```bash
# Basic translation
tinbox translate --to es document.pdf

# With specific model
tinbox translate --model openai:gpt-4o --to fr document.docx

# With GPT-5 models (optimized parameters applied automatically)
tinbox translate --model openai:gpt-5 --to es document.pdf # Highest quality
tinbox translate --model openai:gpt-5-mini --to fr document.docx # Recommended
tinbox translate --model openai:gpt-5-nano --to de document.txt # Most economical

# Cost estimation only
tinbox translate --dry-run --to de large_document.pdf

# Sliding window for long texts
tinbox translate --algorithm sliding-window --to zh document.txt
```
149 changes: 149 additions & 0 deletions QUICKSTART_GUI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Tinbox GUI - Quick Start Guide

Get the Tinbox Electron GUI up and running in 5 minutes!

## Installation

### Step 1: Install Python Dependencies

```bash
# Install Tinbox with GUI support
uv pip install -e ".[gui,pdf,docx]"
```

This installs:
- Tinbox core
- FastAPI for the REST API server
- Uvicorn for serving the API
- PDF and DOCX support

### Step 2: Install Node Dependencies

```bash
cd electron
npm install
```

## Running the App

### Development Mode

From the `electron/` directory:

```bash
npm run dev
```

This will:
1. Start the FastAPI backend on `http://127.0.0.1:8765`
2. Start the Vite dev server on `http://localhost:5173`
3. Launch the Electron app

The app should open automatically with hot reload enabled.

## First Use

### 1. Configure API Keys

Click the **settings icon** (⚙️) in the top right and enter your API keys:

- **OpenAI**: For GPT-4, GPT-5 models
- **Anthropic**: For Claude models
- **Google**: For Gemini models (optional)

### 2. Set Default Preferences

In Settings, configure:
- **Default Model**: e.g., `openai:gpt-4o-mini` (recommended for most users)
- **Source Language**: `auto` for auto-detection
- **Target Language**: e.g., `en` for English
- **Algorithm**: `page-by-page` for PDFs (default)
- **Output Format**: `text` (default)

Click **Save Settings**.

### 3. Translate Your First Document

1. **Drag and drop** a PDF, DOCX, or TXT file into the window
- Or click the drop zone to browse for files

2. **Review the cost estimate** that appears
- Shows estimated tokens and cost
- Click "OK" to proceed

3. **Watch the progress** in real-time
- Progress bar shows current page
- Token count and cost update live
- Multiple files process in queue

4. **Download the result** when complete
- Click the download icon (⬇️)
- Choose where to save the translation

## Tips

### Batch Processing
- Drop multiple files at once
- They'll queue automatically
- Max 2 concurrent translations (configurable)

### Cost Management
- Start with `gpt-4o-mini` or `gpt-5-nano` for testing
- Cost estimates help avoid surprises
- View actual cost per job in the progress card

### File Support
- **PDF**: Converted to images, works with scanned docs
- **DOCX**: Text extraction maintains structure
- **TXT**: Direct text processing

### Keyboard Shortcuts
- **Cmd/Ctrl + ,**: Open settings (coming soon)
- **Cmd/Ctrl + Q**: Quit app

## Troubleshooting

### "Failed to start Python server"

**Solution**: Make sure you installed the GUI dependencies:
```bash
uv pip install -e ".[gui]"
```

### "API key not found"

**Solution**: Either:
1. Add key in Settings UI, or
2. Set environment variable:
```bash
export OPENAI_API_KEY="sk-..."
```

### Port 8765 already in use

**Solution**:
1. Stop other Tinbox instances
2. Or change port in `electron/main.js` (line 13)

### Translation stuck at 0%

**Solution**:
1. Check that your API key is valid
2. Ensure you have sufficient API credits
3. Check console for error messages

## Next Steps

- Explore different models and compare quality
- Try both translation algorithms
- Experiment with output formats
- Check the full README for advanced features

## Need Help?

- Full documentation: `electron/README.md`
- Python backend: `src/tinbox/api/`
- React frontend: `electron/src/`
- Report issues: https://github.com/anthropics/tinbox/issues

Happy translating! 🎉
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,38 @@ tinbox --to es document.pdf
- Automatic context preservation between sections

### 🤖 Flexible Model Support
- **GPT-5 Models**: Full support with optimized parameters (see below)
- Use powerful cloud models (GPT-4V, Claude 3.5 Sonnet)
- Run translations locally with Ollama
- Mix and match models for different tasks

#### GPT-5 Models (Recommended)

Tinbox fully supports OpenAI's latest GPT-5 models with automatic parameter optimization:

| Model | Best For | Cost (per 1M tokens) | Speed |
|-------|----------|----------------------|-------|
| **gpt-5** | Complex documents, highest quality | $1.25 / $10.00 (in/out) | Standard |
| **gpt-5-mini** | Most translations (recommended) | $0.25 / $2.00 (in/out) | Fast |
| **gpt-5-nano** | Simple docs, high volume | $0.05 / $0.40 (in/out) | Fastest |

**Automatic Optimizations**:
- `reasoning_effort="low"` - Faster processing for translation tasks
- `verbosity="low"` - Concise output without unnecessary explanations
- No temperature parameter (not supported by GPT-5)

**Usage**:
```bash
# Recommended for most use cases
tinbox --model openai:gpt-5-mini --to es document.pdf

# For highest quality
tinbox --model openai:gpt-5 --to fr complex_report.pdf

# For maximum speed/economy
tinbox --model openai:gpt-5-nano --to de simple_doc.txt
```

### 🌐 Language Support
- Flexible source/target language specification using ISO 639-1 codes
- Common language aliases (e.g., "en", "zh", "es")
Expand Down
32 changes: 32 additions & 0 deletions electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Dependencies
node_modules/
package-lock.json

# Build outputs
dist/
dist-electron/

# Vite
.vite/

# TypeScript
*.tsbuildinfo

# OS files
.DS_Store
Thumbs.db

# IDE
.vscode/
.idea/
*.swp
*.swo

# Logs
logs/
*.log
npm-debug.log*

# Electron
out/
.webpack/
Loading