forked from mirrors/LibreTranslate
Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
753a33e7c5 | |||
e559f899b8 | |||
01b892b96a | |||
282737519c | |||
5a2e0fe656 | |||
11324ab1f5 | |||
91ae57ad6c | |||
72aaa41d8f | |||
b407ffee3c | |||
f2d6800f4c | |||
959f4638cc | |||
5285697203 | |||
10f82d9a3e | |||
c4d1b05b27 | |||
034407ee15 | |||
b55d150f9c | |||
cdfeb6d8fc | |||
34fceaacc7 | |||
c9ccbf6a25 |
|
@ -24,7 +24,7 @@ FROM python:3.8.14-slim-bullseye
|
|||
ARG with_models=false
|
||||
ARG models=
|
||||
|
||||
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate
|
||||
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate && mkdir -p /home/libretranslate/.local && chown -R libretranslate:libretranslate /home/libretranslate/.local
|
||||
USER libretranslate
|
||||
|
||||
COPY --from=builder --chown=1032:1032 /app /app
|
||||
|
|
42
README.md
42
README.md
|
@ -110,12 +110,8 @@ libretranslate [args]
|
|||
|
||||
Then open a web browser to http://localhost:5000
|
||||
|
||||
If you're on Windows, we recommend you [Run with Docker](#run-with-docker) instead.
|
||||
|
||||
On Ubuntu 20.04 you can also use the install script available at https://github.com/argosopentech/LibreTranslate-init
|
||||
|
||||
If you would rather run it natively, you can follow the guide [here](https://github.com/nuttolum/LibreOnWindows).
|
||||
|
||||
## Build and Run
|
||||
|
||||
If you want to make changes to the code, you can build from source, and run the API:
|
||||
|
@ -134,14 +130,12 @@ Then open a web browser to http://localhost:5000
|
|||
|
||||
### Run with Docker
|
||||
|
||||
Simply run:
|
||||
|
||||
```bash
|
||||
docker run -ti --rm -p 5000:5000 libretranslate/libretranslate
|
||||
```
|
||||
Linux/MacOS: `./run.sh [args]`
|
||||
Windows: `run.bat [args]`
|
||||
|
||||
Then open a web browser to http://localhost:5000
|
||||
|
||||
|
||||
### Build with Docker
|
||||
|
||||
```bash
|
||||
|
@ -164,7 +158,7 @@ docker-compose up -d --build
|
|||
|
||||
> Feel free to change the [`docker-compose.yml`](https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml) file to adapt it to your deployment needs, or use an extra `docker-compose.prod.yml` file for your deployment configuration.
|
||||
|
||||
> The models are stored inside the container under `/root/.local/share` and `/root/.local/cache`. Feel free to use volumes if you do not want to redownload the models when the container is destroyed. Be aware that this will prevent the models from being updated!
|
||||
> The models are stored inside the container under `/home/libretranslate/.local/share` and `/home/libretranslate/.local/cache`. Feel free to use volumes if you do not want to redownload the models when the container is destroyed. To update the models, use the `--update-models` argument.
|
||||
|
||||
### CUDA
|
||||
|
||||
|
@ -193,7 +187,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build
|
|||
| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET |
|
||||
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
||||
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
||||
| --api-keys-db-path | Use a specific path inside the container for the local database. Can be absolute or relative | `api_keys.db` | LT_API_KEYS_DB_PATH |
|
||||
| --api-keys-db-path | Use a specific path inside the container for the local database. Can be absolute or relative | `db/api_keys.db` | LT_API_KEYS_DB_PATH |
|
||||
| --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Use local API key database` | LT_API_KEYS_REMOTE |
|
||||
| --get-api-key-link | Show a link in the UI where to direct users to get an API key | `Don't show a link` | LT_GET_API_KEY_LINK |
|
||||
| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN |
|
||||
|
@ -202,9 +196,28 @@ docker-compose -f docker-compose.cuda.yml up -d --build
|
|||
| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS |
|
||||
| --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION |
|
||||
| --disable-web-ui | Disable web ui | `false` | LT_DISABLE_WEB_UI |
|
||||
| --update-models | Update language models at startup | `false` | LT_UPDATE_MODELS |
|
||||
|
||||
Note that each argument has an equivalent environment variable that can be used instead. The env. variables overwrite the default values but have lower priority than the command arguments and are particularly useful if used with Docker. The environment variable names are the upper-snake-case of the equivalent command argument's name with a `LT` prefix.
|
||||
|
||||
## Update
|
||||
|
||||
### Software
|
||||
|
||||
If you installed with pip:
|
||||
|
||||
`pip install -U libretranslate`
|
||||
|
||||
If you're using docker:
|
||||
|
||||
`docker pull libretranslate/libretranslate`
|
||||
|
||||
### Language Models
|
||||
|
||||
Start the program with the `--update-models` argument. For example: `libretranslate --update-models` or `./run.sh --update-models`.
|
||||
|
||||
Alternatively you can also run the `install_models.py` script.
|
||||
|
||||
## Run with WSGI and Gunicorn
|
||||
|
||||
```
|
||||
|
@ -268,7 +281,8 @@ You can use the LibreTranslate API using the following bindings:
|
|||
- Swift: https://github.com/wacumov/libretranslate
|
||||
- Unix: https://github.com/argosopentech/LibreTranslate-sh
|
||||
- Shell: https://github.com/Hayao0819/Hayao-Tools/tree/master/libretranslate-sh
|
||||
|
||||
- Java: https://github.com/suuft/libretranslate-java
|
||||
-
|
||||
## Discourse Plugin
|
||||
|
||||
You can use this [discourse translator plugin](https://github.com/LibreTranslate/discourse-translator) to translate [Discourse](https://discourse.org) topics. To install it simply modify `/var/discourse/containers/app.yml`:
|
||||
|
@ -303,7 +317,7 @@ This is a list of public LibreTranslate instances, some require an API key. If y
|
|||
|
||||
URL |API Key Required | Links
|
||||
--- | --- | ---
|
||||
[libretranslate.com](https://libretranslate.com)|:heavy_check_mark:|[Get API Key](https://buy.stripe.com/3cs4j3a4u4c8d3i289)
|
||||
[libretranslate.com](https://libretranslate.com)|:heavy_check_mark:|[Get API Key](https://portal.libretranslate.com)
|
||||
[libretranslate.de](https://libretranslate.de)|-
|
||||
[translate.argosopentech.com](https://translate.argosopentech.com/)|-
|
||||
[translate.api.skitzen.com](https://translate.api.skitzen.com/)|-
|
||||
|
@ -339,7 +353,7 @@ Help us by opening a pull request!
|
|||
|
||||
### Can I use your API server at libretranslate.com for my application in production?
|
||||
|
||||
In short, no. [You need to buy an API key](https://buy.stripe.com/3cs4j3a4u4c8d3i289). You can always run LibreTranslate for free on your own server of course.
|
||||
In short, no. [You need to buy an API key](https://portal.libretranslate.com). You can always run LibreTranslate for free on your own server of course.
|
||||
|
||||
### Can I use LibreTranslate behind a reverse proxy, like Apache2 or Caddy?
|
||||
|
||||
|
|
|
@ -10,6 +10,14 @@ DEFAULT_DB_PATH = DEFARGS['API_KEYS_DB_PATH']
|
|||
|
||||
class Database:
|
||||
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
||||
# Legacy check - this can be removed at some point in the near future
|
||||
if os.path.isfile("api_keys.db") and not os.path.isfile("db/api_keys.db"):
|
||||
print("Migrating %s to %s" % ("api_keys.db", "db/api_keys.db"))
|
||||
try:
|
||||
os.rename("api_keys.db", "db/api_keys.db")
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
db_dir = os.path.dirname(db_path)
|
||||
if not db_dir == "" and not os.path.exists(db_dir):
|
||||
os.makedirs(db_dir)
|
||||
|
|
|
@ -100,7 +100,7 @@ def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db):
|
|||
def create_app(args):
|
||||
from app.init import boot
|
||||
|
||||
boot(args.load_only)
|
||||
boot(args.load_only, args.update_models)
|
||||
|
||||
from app.language import load_languages
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ _default_options_objects = [
|
|||
},
|
||||
{
|
||||
'name': 'API_KEYS_DB_PATH',
|
||||
'default_value': 'api_keys.db',
|
||||
'default_value': 'db/api_keys.db',
|
||||
'value_type': 'str'
|
||||
},
|
||||
{
|
||||
|
@ -156,6 +156,11 @@ _default_options_objects = [
|
|||
'default_value': False,
|
||||
'value_type': 'bool'
|
||||
},
|
||||
{
|
||||
'name': 'UPDATE_MODELS',
|
||||
'default_value': False,
|
||||
'value_type': 'bool'
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ from argostranslate import package, translate
|
|||
import app.language
|
||||
|
||||
|
||||
def boot(load_only=None):
|
||||
def boot(load_only=None, update_models=False):
|
||||
try:
|
||||
check_and_install_models(load_only_lang_codes=load_only)
|
||||
check_and_install_models(force=update_models, load_only_lang_codes=load_only)
|
||||
except Exception as e:
|
||||
print("Cannot update models (normal if you're offline): %s" % str(e))
|
||||
|
||||
|
|
|
@ -144,7 +144,9 @@ def get_args():
|
|||
parser.add_argument(
|
||||
"--disable-web-ui", default=DEFARGS['DISABLE_WEB_UI'], action="store_true", help="Disable web ui"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--update-models", default=DEFARGS['UPDATE_MODELS'], action="store_true", help="Update language models at startup"
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
langsRequest.send();
|
||||
},
|
||||
updated: function(){
|
||||
if (this.isSuggesting) return;
|
||||
|
||||
M.FormSelect.init(this.$refs.sourceLangDropdown);
|
||||
M.FormSelect.init(this.$refs.targetLangDropdown);
|
||||
|
||||
|
@ -283,11 +285,14 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
this.savedTanslatedText = this.translatedText
|
||||
|
||||
this.isSuggesting = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs.translatedTextarea.focus();
|
||||
});
|
||||
},
|
||||
closeSuggestTranslation: function(e) {
|
||||
if(this.isSuggesting) {
|
||||
e.preventDefault();
|
||||
this.translatedText = this.savedTanslatedText
|
||||
// this.translatedText = this.savedTanslatedText
|
||||
}
|
||||
|
||||
this.isSuggesting = false;
|
||||
|
@ -312,7 +317,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
try{
|
||||
var res = JSON.parse(this.response);
|
||||
if (res.success){
|
||||
M.toast({html: 'Thanks for your correction.'})
|
||||
M.toast({html: 'Thanks for your correction. Note the suggestion will not take effect right away.'})
|
||||
self.closeSuggestTranslation(e)
|
||||
}else{
|
||||
throw new Error(res.error || "Unknown error");
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
import sqlite3
|
||||
import os
|
||||
|
||||
from expiringdict import ExpiringDict
|
||||
|
||||
DEFAULT_DB_PATH = "suggestions.db"
|
||||
DEFAULT_DB_PATH = "db/suggestions.db"
|
||||
|
||||
|
||||
class Database:
|
||||
def __init__(self, db_path=DEFAULT_DB_PATH, max_cache_len=1000, max_cache_age=30):
|
||||
# Legacy check - this can be removed at some point in the near future
|
||||
if os.path.isfile("suggestions.db") and not os.path.isfile("db/suggestions.db"):
|
||||
print("Migrating %s to %s" % ("suggestions.db", "db/suggestions.db"))
|
||||
try:
|
||||
os.rename("suggestions.db", "db/suggestions.db")
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
self.db_path = db_path
|
||||
self.cache = ExpiringDict(max_len=max_cache_len, max_age_seconds=max_cache_age)
|
||||
|
||||
|
|
0
db/.gitignore
vendored
Normal file
0
db/.gitignore
vendored
Normal file
41
run.bat
Normal file
41
run.bat
Normal file
|
@ -0,0 +1,41 @@
|
|||
@ECHO OFF
|
||||
|
||||
SETLOCAL
|
||||
|
||||
SET LT_PORT=5000
|
||||
|
||||
:loop
|
||||
IF NOT "%1"=="" (
|
||||
IF "%1"=="--port" (
|
||||
SET LT_PORT=%2
|
||||
SHIFT
|
||||
)
|
||||
IF "%1"=="--help" (
|
||||
echo Usage: run.bat [--port N]
|
||||
echo:
|
||||
echo Run LibreTranslate using docker.
|
||||
echo:
|
||||
GOTO :done
|
||||
)
|
||||
IF "%1"=="--api-keys" (
|
||||
SET DB_VOLUME=-v lt-db:/app/db
|
||||
SHIFT
|
||||
)
|
||||
SHIFT
|
||||
GOTO :loop
|
||||
)
|
||||
|
||||
WHERE /Q docker
|
||||
IF %ERRORLEVEL% NEQ 0 GOTO :install_docker
|
||||
|
||||
docker run -ti --rm -p %LT_PORT%:%LT_PORT% %DB_VOLUME% -v lt-local:/home/libretranslate/.local libretranslate/libretranslate %*
|
||||
|
||||
GOTO :done
|
||||
|
||||
:install_docker
|
||||
ECHO Cannot find docker! Go to https://docs.docker.com/desktop/install/windows-install/ and install docker before running this script (pressing Enter will open the page)
|
||||
pause
|
||||
start "" https://docs.docker.com/desktop/install/windows-install/
|
||||
GOTO :done
|
||||
|
||||
:done
|
89
run.sh
Executable file
89
run.sh
Executable file
|
@ -0,0 +1,89 @@
|
|||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
__dirname=$(cd "$(dirname "$0")"; pwd -P)
|
||||
cd "${__dirname}"
|
||||
|
||||
platform="Linux" # Assumed
|
||||
uname=$(uname)
|
||||
case $uname in
|
||||
"Darwin")
|
||||
platform="MacOS / OSX"
|
||||
;;
|
||||
MINGW*)
|
||||
platform="Windows"
|
||||
;;
|
||||
esac
|
||||
|
||||
usage(){
|
||||
echo "Usage: $0 [--port N]"
|
||||
echo
|
||||
echo "Run LibreTranslate using docker."
|
||||
echo
|
||||
exit
|
||||
}
|
||||
|
||||
export LT_PORT=5000
|
||||
|
||||
# Parse args for overrides
|
||||
ARGS=()
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case $key in
|
||||
--port)
|
||||
export LT_PORT="$2"
|
||||
ARGS+=("$1")
|
||||
ARGS+=("$2") # save it in an array for later
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
--debug)
|
||||
export LT_DEBUG=YES
|
||||
ARGS+=("$1")
|
||||
shift # past argument
|
||||
;;
|
||||
--api-keys)
|
||||
export DB_VOLUME="-v lt-db:/app/db"
|
||||
ARGS+=("$1")
|
||||
shift # past argument
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*) # unknown option
|
||||
ARGS+=("$1")
|
||||
shift # past argument
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# $1 = command | $2 = help_text | $3 = install_command (optional)
|
||||
check_command(){
|
||||
hash "$1" 2>/dev/null || not_found=true
|
||||
if [[ $not_found ]]; then
|
||||
check_msg_prefix="Checking for $1... "
|
||||
|
||||
# Can we attempt to install it?
|
||||
if [[ -n "$3" ]]; then
|
||||
echo -e "$check_msg_prefix \033[93mnot found, we'll attempt to install\033[39m"
|
||||
$3 || sudo $3
|
||||
|
||||
# Recurse, but don't pass the install command
|
||||
check_command "$1" "$2"
|
||||
else
|
||||
check_msg_result="\033[91m can't find $1! Check that the program is installed and that you have added the proper path to the program to your PATH environment variable before launching WebODM. If you change your PATH environment variable, remember to close and reopen your terminal. $2\033[39m"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "$check_msg_prefix $check_msg_result"
|
||||
if [[ $not_found ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
environment_check(){
|
||||
check_command "docker" "https://www.docker.com/"
|
||||
}
|
||||
|
||||
environment_check
|
||||
docker run -ti --rm -p $LT_PORT:$LT_PORT $DB_VOLUME -v lt-local:/home/libretranslate/.local libretranslate/libretranslate ${ARGS[@]}
|
Loading…
Reference in a new issue