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

ops/2024/10/9 7:16:58/

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.ppmy.cn/ops/123053.html

相关文章

智能医疗:Spring Boot医院管理系统开发

2相关技术 2.1 MYSQL数据库 MySQL是一个真正的多用户、多线程SQL数据库服务器。 是基于SQL的客户/服务器模式的关系数据库管理系统,它的有点有有功能强大、使用简单、管理方便、安全可靠性高、运行速度快、多线程、跨平台性、完全网络化、稳定性等,非常适…

计算机毕业设计 基于深度学习的短视频内容理解与推荐系统的设计与实现 Python+Django+Vue 前后端分离 附源码 讲解 文档

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点…

前端编程艺术(3)---JavaScript

目录 1.JavaScript 1.输出 2.变量和数据类型 3.运算符 4.数组 5.函数 6.面向对象 7.ES6面向对象 2.BOM 1.document对象 3.DOM 4.JSON 1.JavaScript JavaScript是一种脚本编程语言,通常用于为网页增加交互性和动态效果。它是一种高级语言&#xff…

GO语言中struct{}和struct{}{}区别

定义一个Stu结构体: type Stu struct {Name string }声明一个Stu类型的变量并赋值: var stu Stu stu.Name "小红"声明一个struct类型变量并赋值还有一种方式是使用匿名struct: stu : struct {Name string }{"小红" }…

如何使用GeoIP和ELK(Elasticsearch、Logstash和Kibana)映射用户位置

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。 简介 IP 地理定位是用于确定 IP 地址的物理位置的过程,可以用于各种目的,如内容个性化和流量分析。通过地理位置…

用Spring Boot搭建IT交流与学习平台

1 绪论 1.1 研究背景 在当今的社会,可以说是信息技术的发展时代,在社会的方方面面无不涉及到各种信息的处理。信息是人们对客观世界的具体描述,是人们进行交流与联系的重要途径。人类社会就处在一个对信息进行有效合理的加工中[3]。它将促进整…

【韩顺平Java笔记】第8章:面向对象编程(中级部分)【272-284】

文章目录 272. 包基本介绍272.1 看一个应用场景272.2 包的三大作用272.3 包的基本语法 273. 包原理274. 包快速入门275. 包命名276. 常用的包277. 包的使用细节278. 访问修饰符规则278.1 基本介绍278.2 四种访问修饰符的访问范围 279. 访问修饰符细节280. 封装介绍281. 封装步骤…

nginx-2-配置

准备配置文件 解压后去除多余内容 worker_processes 1; events {worker_connections 1024; } http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name localhost;locatio…