一个开源可本地部署的英文翻译服务----EnToZhAPI

EnToZhAPI项目简介

项目背景

提供本地化的英文翻译服务API。支持单句翻译请求或者批量翻译请求。支持建立查询词汇表。

项目架构

前端:使用原生js,使用MDB作为CSS框架。django模板引擎渲染可视化界面。

后端:使用waitress作为后端服务器。django作为web应用框架。

翻译模型:Helsinki-NLP/opus-mt-en-zh

ps: 有效果更好的模型欢迎留言。

API:使用django-ninjaAPI实现RESTFUL API服务以及API文档。

数据库:默认使用sqlite。

缓存:使用redis进行缓存数据管理。

异步任务队列:使用celery进行异步任务处理。

反向代理:使用Nginx处理用户请求并完成分发。

项目构建:使用docker进行项目开发部署以及项目生产部署。

项目开源地址

https://gitee.com/chaofanat/EnToZhAPI

在线测试地址http://api.chaofan.online/

轻量服务器计算性能有限,翻译速度较慢。翻译效果取决于翻译的模型。

python调用API示例

python 复制代码
import httpx, json, time

translate_api = "http://api.chaofan.online/api/translate"

def batchtranslate(texts : list[str]):
    
    payload = {"text": texts}
    payload = json.dumps(payload)
    r = httpx.post(url = "http://api.chaofan.online/api/translate/batch/", data = payload).json()
    task_ids = r["task_ids"]
    print("已经获取任务ID:")
    print(task_ids)
    print("可以通过url:"+translate_api+"/{task_id} 获取任务执行结果。")
    print("任务执行中,等待获取结果(默认等待1分钟后获取任务结果)。。。")
    time.sleep(1*60)
    
    translate_res = []
    for task_id in task_ids: 
        res = httpx.get(url = f"{translate_api}/{task_id}").json()
        translate_res = translate_res+res["result"]

    print("获取任务结果成功:")
    print("##################")
    for res in translate_res:
        print(res)
    return translate_res


sentences = [
    "The quick brown fox jumps over the lazy dog.",
    "Every moment is a fresh beginning.",
    "Life is what happens when you're busy making other plans.",
    "Stars can't shine without darkness.",
    "Believe in yourself and all that you are.",
    "Success is not final, failure is not fatal: it is the courage to continue that counts.",
    "The best way to predict your future is to create it.",
    "Smile, because it confuses people.",
    "Dream big and dare to fail.",
    "Happiness is a direction, not a destination.",
    "You miss 100% of the shots you don't take.",
    "The only way to do great work is to love what you do.",
    "The future belongs to those who believe in the beauty of their dreams.",
    "Be the change you wish to see in the world.",
    "If you want to go fast, go alone. If you want to go far, go together.",
    "The only limit to our realization of tomorrow will be our doubts of today.",
    "The greatest glory in living lies not in never falling, but in rising every time we fall.",
    "Opportunity is missed by most people because it is dressed in overalls and looks like work.",
    "Life is 10% what happens to us and 90% how we react to it.",
    "The best time to plant a tree was 20 years ago. The second best time is now."
]

translate_res = batchtranslate(sentences)


for i in translate_res:
    print(i)
相关推荐
斯普信专业组4 分钟前
构建基于MCP的MySQL智能运维平台:从开源服务端到交互式AI助手
运维·mysql·开源·mcp
B站_计算机毕业设计之家7 分钟前
豆瓣电影推荐系统 | Python Django Echarts构建个性化影视推荐平台 大数据 毕业设计源码 (建议收藏)✅
大数据·python·机器学习·django·毕业设计·echarts·推荐算法
旺仔Sec14 分钟前
一文带你看懂免费开源 WAF 天花板!雷池 (SafeLine) 部署与实战全解析
web安全·网络安全·开源·waf
心疼你的一切17 分钟前
语音革命:CANN驱动实时语音合成的技术突破
数据仓库·开源·aigc·cann
开源能源管理系统32 分钟前
MyEMS开源能源管理系统:赋能废旧金属回收加工行业绿色转型与降本增效
开源·能源·能源管理系统·零碳工厂
廖松洋(Alina)1 小时前
【收尾以及复盘】flutter开发鸿蒙APP之成就徽章页面
flutter·华为·开源·harmonyos·鸿蒙
廖松洋(Alina)2 小时前
【收尾以及复盘】flutter开发鸿蒙APP之打卡日历页面
flutter·华为·开源·harmonyos·鸿蒙
廖松洋(Alina)2 小时前
【收尾以及复盘】flutter开发鸿蒙APP之本月数据统计页面
flutter·华为·开源·harmonyos·鸿蒙
晚霞的不甘4 小时前
CANN 支持多模态大模型:Qwen-VL 与 LLaVA 的端侧部署实战
人工智能·神经网络·架构·开源·音视频
拾荒的小海螺13 小时前
开源项目:LTX2 高效可控的开源视频生成模型
开源·音视频