Add system prompt, glossary, presets for Ollama/WebLLM, image translation support
This commit is contained in:
17
main.py
17
main.py
@@ -111,7 +111,9 @@ 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)"),
|
||||
translate_images: bool = Form(default=False, description="Translate images with multimodal Ollama model"),
|
||||
ollama_model: str = Form(default="", description="Ollama model to use (also used for vision if multimodal)"),
|
||||
system_prompt: str = Form(default="", description="Custom system prompt with context, glossary, or instructions for LLM translation"),
|
||||
cleanup: bool = Form(default=True, description="Delete input file after translation")
|
||||
):
|
||||
"""
|
||||
@@ -154,7 +156,7 @@ async def translate_document(
|
||||
logger.info(f"Saved input file to: {input_path}")
|
||||
|
||||
# Configure translation provider
|
||||
from services.translation_service import GoogleTranslationProvider, DeepLTranslationProvider, LibreTranslationProvider, OllamaTranslationProvider, WebLLMTranslationProvider, translation_service
|
||||
from services.translation_service import GoogleTranslationProvider, DeepLTranslationProvider, LibreTranslationProvider, OllamaTranslationProvider, translation_service
|
||||
|
||||
if provider.lower() == "deepl":
|
||||
if not config.DEEPL_API_KEY:
|
||||
@@ -163,10 +165,13 @@ async def translate_document(
|
||||
elif provider.lower() == "libre":
|
||||
translation_provider = LibreTranslationProvider()
|
||||
elif provider.lower() == "ollama":
|
||||
vision_model = getattr(config, 'OLLAMA_VISION_MODEL', 'llava')
|
||||
translation_provider = OllamaTranslationProvider(config.OLLAMA_BASE_URL, config.OLLAMA_MODEL, vision_model)
|
||||
elif provider.lower() == "webllm":
|
||||
translation_provider = WebLLMTranslationProvider()
|
||||
# Use the same model for text and vision (multimodal models like gemma3, qwen3-vl)
|
||||
model_to_use = ollama_model.strip() if ollama_model else config.OLLAMA_MODEL
|
||||
custom_prompt = system_prompt.strip() if system_prompt else ""
|
||||
logger.info(f"Using Ollama model: {model_to_use} (text + vision)")
|
||||
if custom_prompt:
|
||||
logger.info(f"Custom system prompt provided ({len(custom_prompt)} chars)")
|
||||
translation_provider = OllamaTranslationProvider(config.OLLAMA_BASE_URL, model_to_use, model_to_use, custom_prompt)
|
||||
else:
|
||||
translation_provider = GoogleTranslationProvider()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user