mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-06 21:20:33 +02:00
gnu: Add libretranslate.
* gnu/packages/machine-learning.scm (libretranslate): New variable. * gnu/packages/patches/libretranslate-use-flasgger.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. Change-Id: I82ca207ee8c724e3ee0623768b502512c494e9c1 Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
This commit is contained in:
committed by
Liliana Marie Prikler
parent
881cfbba6d
commit
c483315faf
@@ -1707,6 +1707,7 @@ dist_patch_DATA = \
|
||||
%D%/packages/patches/libretro-dolphin-emu-gc-font-tool.patch \
|
||||
%D%/packages/patches/libretro-dolphin-emu-libusb-assert.patch \
|
||||
%D%/packages/patches/libretro-dolphin-emu-vulkan-headers.patch \
|
||||
%D%/packages/patches/libretranslate-use-flasgger.patch \
|
||||
%D%/packages/patches/librewolf-add-store-to-rdd-allowlist.patch \
|
||||
%D%/packages/patches/librewolf-compare-paths.patch \
|
||||
%D%/packages/patches/librewolf-neuter-locale-download.patch \
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
#:use-module (gnu packages llvm)
|
||||
#:use-module (gnu packages logging)
|
||||
#:use-module (gnu packages maths)
|
||||
#:use-module (gnu packages monitoring)
|
||||
#:use-module (gnu packages mpi)
|
||||
#:use-module (gnu packages ninja)
|
||||
#:use-module (gnu packages ocaml)
|
||||
@@ -6344,6 +6345,64 @@ a Qt interface for Argos Translate.")
|
||||
for translating plain- and rich-text documents with Argos Translate.")
|
||||
(license license:agpl3)))
|
||||
|
||||
(define-public libretranslate
|
||||
(package
|
||||
(name "libretranslate")
|
||||
(version "1.9.3")
|
||||
(source
|
||||
(origin
|
||||
(method git-fetch)
|
||||
(uri (git-reference
|
||||
(url "https://github.com/LibreTranslate/LibreTranslate")
|
||||
(commit (string-append "v" version))))
|
||||
(file-name (git-file-name name version))
|
||||
(sha256 (base32 "14zdcknv7bra41ananqz6b9dmyq46cmbd8a8s00grzli4qkv5xn1"))
|
||||
(patches (search-patches "libretranslate-use-flasgger.patch"))))
|
||||
(build-system pyproject-build-system)
|
||||
(arguments
|
||||
(list
|
||||
#:tests? #f ;all tests depend on Argos models
|
||||
#:phases
|
||||
#~(modify-phases %standard-phases
|
||||
(add-after 'unpack 'unpin-dependencies
|
||||
(lambda _
|
||||
(substitute* "pyproject.toml"
|
||||
;; Unpin numpy for transitive dependencies.
|
||||
(("^ \"numpy .+") "")
|
||||
;; Unpin dependencies.
|
||||
(("^( \"[[:alnum:]-]+) ==.+((;.+)?\",)" all left right)
|
||||
(string-append left right))
|
||||
(("argos-translate-lt") "argostranslate"))))
|
||||
(add-before 'build 'set-home-env
|
||||
(lambda _
|
||||
(setenv "HOME" "/tmp"))))))
|
||||
(inputs (list python-apscheduler
|
||||
python-argostranslate
|
||||
python-argos-translate-files
|
||||
python-expiringdict
|
||||
python-flasgger
|
||||
python-flask
|
||||
python-flask-babel
|
||||
python-flask-limiter
|
||||
python-flask-session
|
||||
python-itsdangerous
|
||||
python-langdetect
|
||||
python-lexilang
|
||||
python-packaging
|
||||
python-polib
|
||||
python-prometheus-client
|
||||
python-redis
|
||||
python-requests
|
||||
python-waitress
|
||||
python-werkzeug))
|
||||
(native-inputs (list python-hatchling))
|
||||
(home-page "https://docs.libretranslate.com")
|
||||
(synopsis "Machine translation API and web interface")
|
||||
(description
|
||||
"LibreTranslate is a machine translation API and web interface,
|
||||
powered by the Argos Translate library.")
|
||||
(license license:agpl3)))
|
||||
|
||||
(define-public python-hmmlearn
|
||||
(package
|
||||
(name "python-hmmlearn")
|
||||
|
||||
79
gnu/packages/patches/libretranslate-use-flasgger.patch
Normal file
79
gnu/packages/patches/libretranslate-use-flasgger.patch
Normal file
@@ -0,0 +1,79 @@
|
||||
Migrate to Flasgger, as flask-swagger is no longer maintained
|
||||
|
||||
Upstream-Status: https://github.com/LibreTranslate/LibreTranslate/pull/943
|
||||
|
||||
diff --git a/libretranslate/app.py b/libretranslate/app.py
|
||||
index 9793a918b971..9511f2ceea80 100644
|
||||
--- a/libretranslate/app.py
|
||||
+++ b/libretranslate/app.py
|
||||
@@ -15,8 +15,7 @@ import argostranslatefiles
|
||||
from argostranslatefiles import get_supported_formats
|
||||
from flask import Blueprint, Flask, Response, abort, jsonify, render_template, request, send_file, url_for, make_response
|
||||
from flask_babel import Babel
|
||||
-from flask_swagger import swagger
|
||||
-from flask_swagger_ui import get_swaggerui_blueprint
|
||||
+from flasgger import Swagger
|
||||
from argostranslatefiles.translatehtml import translate_html
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from werkzeug.http import http_date
|
||||
@@ -1310,17 +1309,25 @@ def create_app(args):
|
||||
|
||||
limiter.init_app(app)
|
||||
|
||||
- swag = swagger(app)
|
||||
- swag["basePath"] = args.url_prefix if args.url_prefix != "" else "/"
|
||||
- swag["info"]["version"] = get_version()
|
||||
- swag["info"]["title"] = "LibreTranslate"
|
||||
- swag["info"]["description"] = "Free and Open Source Machine Translation API."
|
||||
- swag["info"]["license"] = {"name": "AGPL-3.0"}
|
||||
+ swagger_config = Swagger.DEFAULT_CONFIG | {
|
||||
+ "specs": [{"endpoint": "spec", "route": api_url}],
|
||||
+ "specs_route": "/docs/",
|
||||
+ }
|
||||
+ swagger_template = {
|
||||
+ "basePath": args.url_prefix if args.url_prefix != "" else "/",
|
||||
+ "info": {
|
||||
+ "version": get_version(),
|
||||
+ "title": "LibreTranslate",
|
||||
+ "description": "Free and Open Source Machine Translation API.",
|
||||
+ "license": {"name": "AGPL-3.0"},
|
||||
+ },
|
||||
+ }
|
||||
+ swag = Swagger(app, config=swagger_config, template=swagger_template)
|
||||
|
||||
@app.route(api_url)
|
||||
@limiter.exempt
|
||||
def spec():
|
||||
- return jsonify(lazy_swag(swag))
|
||||
+ return jsonify(lazy_swag(swag.get_apispecs()))
|
||||
|
||||
app.config["BABEL_TRANSLATION_DIRECTORIES"] = 'locales'
|
||||
|
||||
@@ -1343,12 +1350,6 @@ def create_app(args):
|
||||
|
||||
app.jinja_env.globals.update(_e=gettext_escaped, _h=gettext_html)
|
||||
|
||||
- # Call factory function to create our blueprint
|
||||
- # The Blueprint is not using url_for which means the middleware does not work properly and we need to manually fix things
|
||||
- swaggerui_blueprint = get_swaggerui_blueprint(swagger_url, args.url_prefix + api_url)
|
||||
- swaggerui_blueprint.url_prefix = "/docs"
|
||||
- app.register_blueprint(swaggerui_blueprint)
|
||||
-
|
||||
if os.environ.get("LT_POWERCYCLE") is not None:
|
||||
print("Power cycling...")
|
||||
sys.exit(0)
|
||||
diff --git a/pyproject.toml b/pyproject.toml
|
||||
index ff1a0a4be8a4..f5f18207365d 100644
|
||||
--- a/pyproject.toml
|
||||
+++ b/pyproject.toml
|
||||
@@ -37,9 +37,8 @@ dynamic = ["version"]
|
||||
|
||||
dependencies = [
|
||||
"argos-translate-lt ==1.12.1",
|
||||
+ "flasgger ==0.9.7.1",
|
||||
"Flask ==2.2.5",
|
||||
- "flask-swagger ==0.2.14",
|
||||
- "flask-swagger-ui ==4.11.1",
|
||||
"Flask-Limiter ==2.6.3",
|
||||
"Flask-Babel ==3.1.0",
|
||||
"waitress ==2.1.2",
|
||||
Reference in New Issue
Block a user