Skip to content

Commit ef9c8c0

Browse files
authored
Pypi Packaging (#1)
* type checking, beginning of unit tests * some tests, need to switch to pytest * wrapping up tests * adding python version * changing python version * requirements.dev * fix install typo * removing specified pytorch version * removing testing for python 3.8 and 3.9 * removing unneeded imports from test files * one more * fixing linter * commenting out type checking for now * updates to gh actions, pyproject.toml * update .gitignore * small update to github actions * new unit tests and integration tests * fixing linter check * formatting * adding pytest-cov to dev dependencies * installing wget on windows runner
1 parent f9d1997 commit ef9c8c0

39 files changed

Lines changed: 3580 additions & 873 deletions

.github/workflows/ci.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- releases/*
8+
tags:
9+
- "v*.*.*"
10+
pull_request:
11+
branches:
12+
- main
13+
- releases/*
14+
15+
workflow_dispatch:
16+
17+
env:
18+
PYTORCH_VERSION: "2.7"
19+
20+
jobs:
21+
build_and_test:
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
matrix:
25+
python-version: ["3.10", "3.11", "3.12"]
26+
os: [ubuntu-latest, macos-latest, windows-latest]
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Cache pip
37+
uses: actions/cache@v3
38+
with:
39+
path: ~/.cache/pip
40+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
41+
restore-keys: |
42+
${{ runner.os }}-pip-${{ matrix.python-version }}-
43+
${{ runner.os }}-pip-
44+
45+
- name: Install dependencies (Ubuntu)
46+
if: runner.os == 'Linux'
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install -y ffmpeg libsm6 libxext6 libfontconfig1 libxrender1
50+
# Install audio libraries for pydub
51+
sudo apt-get install -y libavcodec-extra
52+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
53+
54+
- name: Install dependencies (macOS)
55+
if: runner.os == 'macOS'
56+
run: |
57+
brew update
58+
brew install ffmpeg
59+
pip3 install torch torchvision torchaudio
60+
61+
- name: Install dependencies (Windows)
62+
if: runner.os == 'Windows'
63+
run: |
64+
# Install ffmpeg using chocolatey
65+
choco install -y ffmpeg
66+
# Add ffmpeg to PATH
67+
echo "C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin" >> $GITHUB_PATH
68+
# Install wget
69+
choco install -y wget
70+
pip3 install torch torchvision torchaudio
71+
72+
- name: Upgrade pip and dependencies
73+
run: |
74+
python -m pip install --upgrade pip setuptools wheel
75+
pip install -e .[dev]
76+
77+
- name: Lint with flake8
78+
run: |
79+
flake8 src/ tests/
80+
81+
- name: Format code with black
82+
run: |
83+
black --check src/ tests/
84+
85+
# Will implement type checking later
86+
# - name: Run type checks with mypy
87+
# run: |
88+
# mypy --install-types --non-interactive --ignore-missing-imports
89+
# mypy src/
90+
- name: Run tests
91+
run: |
92+
pytest --cov=captionalchemy -v
93+
94+
publish:
95+
needs: build_and_test
96+
if: startsWith(github.ref, 'refs/tags/v')
97+
runs-on: ubuntu-latest
98+
permissions:
99+
id-token: write
100+
environment:
101+
name: pypi
102+
url: https://pypi.org/project/captionalchemy
103+
steps:
104+
- name: Checkout code
105+
uses: actions/checkout@v4
106+
107+
- name: Set up Python
108+
uses: actions/setup-python@v4
109+
with:
110+
python-version: "3.11"
111+
112+
- name: Build distributions
113+
run: |
114+
python -m pip install --upgrade pip build
115+
python -m build
116+
117+
- name: Publish to PyPI
118+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
venv
22
.venv
33
__pycache__
4+
.mypy_cache
5+
captionalchemy.egg-info
6+
.pytest_cache
47

58
*.env
6-
9+
.env
710

811
# Whisper
912
whisper.cpp
1013
/whisper.cpp
14+
15+
# Coverage
16+
.coverage
17+
.coverage.*

CLAUDE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
CaptionAlchemy is a Python package for creating closed captions with face detection and recognition. It combines audio transcription, speaker diarization, and facial recognition to generate accurate subtitles with speaker identification.
8+
9+
## Architecture
10+
11+
The package follows a modular structure under `src/captionalchemy/`:
12+
13+
- **Main Pipeline**: `caption.py` - Core orchestration of the caption generation process
14+
- **Audio Analysis**: `tools/audio_analysis/` - Voice activity detection, speaker diarization, and non-speech detection
15+
- **Captioning**: `tools/captioning/` - Whisper transcription, timing analysis, and output writers (SRT, VTT, SAMI)
16+
- **Computer Vision**: `tools/cv/` - Face embedding and recognition for speaker identification
17+
- **Media Utils**: `tools/media_utils/` - Video download and audio extraction utilities
18+
19+
## Key Components
20+
21+
### Core Pipeline Flow
22+
23+
1. Embed known faces from JSON configuration
24+
2. Download/extract audio from video
25+
3. Run Voice Activity Detection (VAD) and speaker diarization
26+
4. Transcribe audio segments with Whisper
27+
5. Identify speakers using facial recognition
28+
6. Generate timestamped captions in chosen format
29+
30+
### Dependencies
31+
32+
- **Audio Processing**: pyannote.audio, pydub, librosa, openai-whisper
33+
- **Computer Vision**: opencv-python, insightface, onnxruntime
34+
- **Deep Learning**: Uses CUDA when available, falls back to CPU
35+
36+
## Development Commands
37+
38+
### Installation
39+
40+
```bash
41+
pip install -e .
42+
```
43+
44+
### Testing
45+
46+
```bash
47+
pytest
48+
```
49+
50+
### Linting
51+
52+
```bash
53+
flake8
54+
mypy src/
55+
```
56+
57+
### Running the Package
58+
59+
```bash
60+
captionalchemy <video_path_or_url> -f srt -o output_captions
61+
```
62+
63+
## Configuration
64+
65+
- **Environment**: Uses `.env` file for configuration (HF_AUTH_TOKEN for Hugging Face models)
66+
- **Face Recognition**: Requires `known_faces.json`. `embed_faces.json` is an artifact generated.
67+
- **Whisper**: Integrates with whisper.cpp for transcription (requires models in `whisper.cpp/models/`)
68+
69+
## External Dependencies
70+
71+
- Whisper.cpp integration for transcription
72+
- Hugging Face models for audio analysis
73+
- ONNX runtime for face recognition models
74+
75+
## Code Style
76+
77+
- Line length: 110 characters (flake8 configured)
78+
- Python 3.10+ compatible
79+
- Type hints encouraged

0 commit comments

Comments
 (0)