Skip to main content

Transfer Learning API Reference

Transfer Learning can be used not only as a CLI tool but also as a Python library in your own applications. This API reference documents the core components, classes, and functions available for developers.

Installation

To use Transfer Learning as a library, install it using UV:
uv pip install transfer-learning
Or using pip:
pip install transfer-learning

Basic Usage

Here’s a simple example of using Transfer Learning in your Python code:
import asyncio
from transfer_learning.core.video_processor import process_videos_async
from transfer_learning.guide.generator import GuideGenerator

async def process_and_generate():
    # Process a video
    result = await process_videos_async("path/to/video.mp4")
    
    # Generate a guide
    generator = GuideGenerator(result["output_dir"])
    guide = await generator.generate()
    
    print(f"Guide generated: {guide}")

# Run the async function
asyncio.run(process_and_generate())

Core Components

Transfer Learning is organized into several core components:

Video Processing

Audio Processing

Guide Generation

Utilities

Asynchronous API

Most of the Transfer Learning API is asynchronous, using Python’s async/await syntax. This allows for efficient processing of multiple videos or frames concurrently.
import asyncio
from transfer_learning.core.video_processor import process_videos_async

async def process_multiple_videos():
    # Process multiple videos concurrently
    tasks = [
        process_videos_async("video1.mp4"),
        process_videos_async("video2.mp4"),
        process_videos_async("video3.mp4")
    ]
    results = await asyncio.gather(*tasks)
    return results

# Run the async function
results = asyncio.run(process_multiple_videos())

Configuration

You can configure the library using the settings module:
from transfer_learning.config import settings

# Override settings
settings.batch_size = 20
settings.max_concurrent_batches = 8
settings.openai_api_key = "your-api-key"

Error Handling

The library uses custom exceptions for error handling:
from transfer_learning.utils.exceptions import VideoProcessingError, GuideGenerationError

try:
    # Process a video
    result = await process_videos_async("path/to/video.mp4")
except VideoProcessingError as e:
    print(f"Error processing video: {e}")

Next Steps

Explore the API reference for detailed documentation of each component: For CLI usage, refer to the CLI Commands documentation.