Themis analyzes legal documents and generates defense strategies using Large Language Models.
# Clone the repository
git clone https://github.com/HunterR0se/Themis.git
cd Themis
# Create and activate virtual environment
python -m venv legalenv
source legalenv/bin/activate # On Windows: .\legalenv\Scripts\activate
# Install dependencies
pip install PyPDF2 requests tqdm colorama
# Install OCR support (optional)
pip install pytesseract pdf2image pillow
# Plus system dependencies: tesseract-ocr and poppler-utils-
Put your case PDF documents in a directory:
~/Legal/MyCase/*.pdf -
Run Themis:
# Full analysis and defense generation python themis.py full-process --case-dir ~/Legal/MyCase/ # Or try with a specific model python themis.py full-process deepseek-r1 --case-dir ~/Legal/MyCase/ # Or run on all available models to compare results python themis.py all-models --case-dir ~/Legal/MyCase/
-
View results in your case directory:
YYYYMMDD_modelname.md- Complete reportYYYYMMDD_modelname/- All detailed outputs
Watch the Themis Demo (Asciinema)
- SBF Analysis with Openthinker
- SBF Analysis with QwQ
- SBF Analysis with Initium/Law
- SBF Analysis with Mistral
- Many more in the
examplefolder
# Analyze documents
python themis.py analyze --dir ~/Legal/MyCase/
# Generate defense materials from analysis
python themis.py defend --case-dir ~/Legal/MyCase/
# Run full process (analysis + defense)
python themis.py full-process --case-dir ~/Legal/MyCase/
# Run with all available models
python themis.py all-models --case-dir ~/Legal/MyCase/Themis creates:
- Document Analysis - Questions and answers about each document
- Defense Strategy - Legal strategy based on the analysis
- Action Items - Tasks and next steps for the defense
- Case Timeline - Chronological sequence of relevant events
- Combined Report - All of the above in a single document
# Use a specific model
python themis.py full-process deepseek-r1 --case-dir ~/Legal/MyCase/
# Use custom questions
python themis.py analyze --dir ~/Legal/MyCase/ --questions my_questions.md
# Connect to a remote Ollama server
python themis.py --ollama-host 192.168.1.100 analyze --dir ~/Legal/MyCase/
# Compare specific models
python themis.py all-models --case-dir ~/Legal/MyCase/ --models llama3 mistral gpt-4oClick to expand for more details
Themis organizes case files according to the following structure:
YOUR_CASE_DIR/ # Your specified case directory
├── *.pdf # Source PDF documents
├── YYYYMMDD_modelname.md # Combined report (when using full-process)
├── YYYYMMDD_modelname/ # Date and model-specific directory
│ ├── case_analysis.log # Analysis log file
│ ├── analysis_cache.json # Cache to speed up repeat runs
│ ├── document_analysis_modelname.json # Analysis results (JSON)
│ ├── document_analysis_modelname.md # Analysis results (readable)
│ └── defense_materials/ # Generated defense materials
│ ├── defense_strategy.md # Defense strategy document
│ ├── action_items.md # Action items list
│ └── case_timeline.md # Case timeline
When working with model names that contain slashes or other special characters (like "initium/law_model:latest"), Themis automatically sanitizes these names for use in filenames.
Themis includes automatic OCR (Optical Character Recognition) for scanned PDFs when needed:
- Requires additional dependencies:
pytesseract,pdf2image, andpoppler-utils - Automatically used when minimal text is detected in a PDF
Analysis results are cached to avoid re-analyzing documents unnecessarily. Each model has its own cache file.
The all-models command runs Themis with multiple models sequentially:
python themis.py all-models --case-dir ~/Legal/MyCase/This generates a comparison summary (model_comparison_YYYYMMDD.md) that links to all the outputs.
You can create a custom questions file (markdown format) to guide the analysis:
1. What are the central claims or charges against the defendant?
2. What key evidence is presented to support these allegations?
3. What are the legal issues identified in this document?Themis maintains a configuration file at ~/.themis/themis.cfg but you can override settings:
# Show current configuration
python themis.py config --show
# Reset to default configuration
python themis.py config --reset