使用 Google Gemini AI 模型和 Aspose.Words for Python via .NET 自动化文档翻译。将 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 文件翻译成 300 多种语言,同时保留原始布局和格式。基于 AI 的引擎会自动检测源语言——即使在多语言文档中——并仅对无法识别的片段保持未翻译状态。
身份验证需要 Google API 密钥。有关支持的 AI 模型完整列表,请参阅 API Reference。
立即在 Python 开始翻译文档——尝试上方的实时演示。
pip install aspose-words
复制
doc = aw.Document("Document.docx")
api_key = os.getenv("API_KEY")
# 使用 Google 生成式语言模型。
model = aw.ai.AiModel.create(aw.ai.AiModelType.GEMINI_FLASH_LATEST).with_api_key(api_key)
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
doc = aw.Document("Document.docx")
# Pass an empty string if the self-hosted model does not require an API key.
model = CustomAiModel("my-model-24b", "https://your-server.com/v1").with_api_key("")
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
class CustomAiModel(aw.ai.OpenAiModel):
def __init__(self, name, url):
super().__init__(name)
self._url = url
@property
def url(self):
return self._url
我们在PyPi存储库中托管我们的 Python 请按照有关如何 "Aspose.Words for Python via .NET" 安装到您的开发人员环境的分步说明进行操作。
这个包与 Python ≥3.5 和 <3.12 兼容。如果您为 Linux 开发软件,请查看产品文档中对 gcc 和 libpython 的附加要求。