当前位置: 首页 > news >正文

一个开源可本地部署的英文翻译服务----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示例

import httpx, json, timetranslate_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_ressentences = ["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)
http://www.lryc.cn/news/460632.html

相关文章:

  • 【unity】编辑器扩展——在OnValidate中创建、删除游戏物体
  • 学习记录:js算法(六十四):最后一块石头的重量
  • 单片机探秘:从理论到应用
  • options妙用
  • UE5 圆周运动、贝塞尔曲线运动、贝塞尔曲线点
  • 线程局部存储(TLS)
  • JavaSE——集合7:Set接口实现类—TreeSet
  • 【idea技巧篇】idea的类注释和方法注释模版自定义设置
  • 【Kubernetes① 基础】一、容器基础
  • 计算机网络第1章(概述)万字笔记详细版
  • 每日一练算法题(堆串的基本操作StrReplace(S, T, V))
  • IRP默认最小流程
  • 【全网最全】AI产品经理面试高频100题答案解析
  • VLLM实现大模型服务的部署
  • Java 基数排序
  • 红帽发送邮件操作
  • 学习记录:js算法(六十一):添加与搜索单词 - 数据结构设计
  • Jetpack-ObservableField实现双向绑定
  • STARnak, LTR 模型笔记
  • 【数据结构】:破译排序算法--数字世界的秩序密码(二)
  • 2024年《生成式ai大模型》都学什么内容呢?
  • kubernetes自定义pod启动用户
  • C4T避风型电动采光排烟天窗(图集09J621-2)
  • 多态常见面试问题
  • 案例-登录认证(上)
  • 对BSV区块链下一代节点Teranode的答疑解惑(上篇)
  • vue父子组件传参的方法
  • 关于this指针
  • 机器学习西瓜书
  • 如何使用 Puppeteer 和 Browserless 运行自动化测试?