Add Ollama vision image translation with checkbox option
This commit is contained in:
12
main.py
12
main.py
@@ -111,6 +111,7 @@ async def translate_document(
|
||||
target_language: str = Form(..., description="Target language code (e.g., 'es', 'fr', 'de')"),
|
||||
source_language: str = Form(default="auto", description="Source language code (default: auto-detect)"),
|
||||
provider: str = Form(default="google", description="Translation provider (google, ollama, deepl, libre)"),
|
||||
translate_images: bool = Form(default=False, description="Translate images with Ollama vision (only for Ollama provider)"),
|
||||
cleanup: bool = Form(default=True, description="Delete input file after translation")
|
||||
):
|
||||
"""
|
||||
@@ -153,7 +154,7 @@ async def translate_document(
|
||||
logger.info(f"Saved input file to: {input_path}")
|
||||
|
||||
# Configure translation provider
|
||||
from services.translation_service import TranslationService, GoogleTranslationProvider, DeepLTranslationProvider, LibreTranslationProvider, OllamaTranslationProvider
|
||||
from services.translation_service import GoogleTranslationProvider, DeepLTranslationProvider, LibreTranslationProvider, OllamaTranslationProvider, translation_service
|
||||
|
||||
if provider.lower() == "deepl":
|
||||
if not config.DEEPL_API_KEY:
|
||||
@@ -162,13 +163,16 @@ async def translate_document(
|
||||
elif provider.lower() == "libre":
|
||||
translation_provider = LibreTranslationProvider()
|
||||
elif provider.lower() == "ollama":
|
||||
translation_provider = OllamaTranslationProvider(config.OLLAMA_BASE_URL, config.OLLAMA_MODEL)
|
||||
vision_model = getattr(config, 'OLLAMA_VISION_MODEL', 'llava')
|
||||
translation_provider = OllamaTranslationProvider(config.OLLAMA_BASE_URL, config.OLLAMA_MODEL, vision_model)
|
||||
else:
|
||||
translation_provider = GoogleTranslationProvider()
|
||||
|
||||
# Update the global translation service
|
||||
from services import translation_service as ts_module
|
||||
ts_module.translation_service.provider = translation_provider
|
||||
translation_service.provider = translation_provider
|
||||
|
||||
# Store translate_images flag for translators to access
|
||||
translation_service.translate_images = translate_images
|
||||
|
||||
# Translate based on file type
|
||||
if file_extension == ".xlsx":
|
||||
|
||||
Reference in New Issue
Block a user