AI Module

This module contains AI-powered features for video processing.

Detection

Tracking

Speech Recognition

Translation

Translation module for FMUS-VID.

This module provides classes for translating text using local LLMs like Ollama.

class fmusvid.ai.translation.LLMTranslator(model='ollama:mistral', target_languages=None, source_language='en', host='http://localhost:11434', prompt_template=None, temperature=0.3, context_window=8192, max_length=200, batch_size=1, timeout=10.0, throttle_time=0.1, cache_size=1000)[source]

Translate text using local large language models.

This class provides translation capabilities using local LLMs like Ollama.

__init__(model='ollama:mistral', target_languages=None, source_language='en', host='http://localhost:11434', prompt_template=None, temperature=0.3, context_window=8192, max_length=200, batch_size=1, timeout=10.0, throttle_time=0.1, cache_size=1000)[source]

Initialize the LLM translator.

Parameters:
  • model (str) – LLM model identifier (e.g., ‘ollama:mistral’, ‘ollama:llama2’)

  • target_languages (Optional[List[str]]) – List of target language codes (ISO 639-1)

  • source_language (str) – Source language code (ISO 639-1)

  • host (str) – Host URL for the LLM service

  • prompt_template (Optional[str]) – Custom prompt template (None for default)

  • temperature (float) – Sampling temperature (0.0 to 1.0)

  • context_window (int) – Maximum context window size in tokens

  • max_length (int) – Maximum length of translation in tokens

  • batch_size (int) – Number of translations to process in a batch

  • timeout (float) – Timeout for translation requests in seconds

  • throttle_time (float) – Time to wait between translation requests

  • cache_size (int) – Size of translation cache

translate(text, target_languages=None)[source]

Translate text to multiple languages.

Parameters:
  • text (str) – Text to translate

  • target_languages (Optional[List[str]]) – List of target language codes (None for default languages)

Return type:

Dict[str, str]

Returns:

Dictionary mapping language codes to translated text

async translate_async(text, target_languages=None)[source]

Translate text to multiple languages asynchronously.

Parameters:
  • text (str) – Text to translate

  • target_languages (Optional[List[str]]) – List of target language codes (None for default languages)

Return type:

Dict[str, str]

Returns:

Dictionary mapping language codes to translated text

start_batch_translation()[source]

Start background thread for batch translation.

stop_batch_translation()[source]

Stop background thread for batch translation.

batch_translate(text, target_languages=None)[source]

Submit text for batch translation.

Parameters:
  • text (str) – Text to translate

  • target_languages (Optional[List[str]]) – List of target language codes (None for default languages)

Return type:

Dict[str, str]

Returns:

Dictionary mapping language codes to translated text

__del__()[source]

Clean up resources when the object is garbage collected.

Background Removal

Cropping