LibreTranslate/main.py

45 lines
2.5 KiB
Python
Raw Normal View History

2020-12-19 22:40:37 +00:00
import argparse
2020-12-20 20:05:22 +00:00
from app.app import create_app
2020-12-19 22:40:37 +00:00
parser = argparse.ArgumentParser(description='LibreTranslate - Free and Open Source Translation API')
2020-12-20 19:03:53 +00:00
parser.add_argument('--host', type=str,
help='Hostname (%(default)s)', default="127.0.0.1")
parser.add_argument('--port', type=int,
help='Port (%(default)s)', default=5000)
2020-12-20 21:57:31 +00:00
parser.add_argument('--char-limit', default=-1, type=int, metavar="<number of characters>",
2020-12-20 19:03:53 +00:00
help='Set character limit (%(default)s)')
2020-12-20 20:05:22 +00:00
parser.add_argument('--req-limit', default=-1, type=int, metavar="<number>",
help='Set maximum number of requests per minute per client (%(default)s)')
2021-01-19 17:53:53 +00:00
parser.add_argument('--batch-limit', default=-1, type=int, metavar="<number of texts>",
help='Set maximum number of texts to translate in a batch request (%(default)s)')
2020-12-20 20:52:02 +00:00
parser.add_argument('--ga-id', type=str, default=None, metavar="<GA ID>",
2020-12-20 19:03:53 +00:00
help='Enable Google Analytics on the API client page by providing an ID (%(default)s)')
2020-12-20 20:05:22 +00:00
parser.add_argument('--debug', default=False, action="store_true",
help="Enable debug environment")
parser.add_argument('--ssl', default=None, action="store_true",
help="Whether to enable SSL")
parser.add_argument('--frontend-language-source', type=str, default="en", metavar="<language code>",
help='Set frontend default language - source (%(default)s)')
parser.add_argument('--frontend-language-target', type=str, default="es", metavar="<language code>",
2021-01-19 21:49:50 +00:00
help='Set frontend default language - target (%(default)s)')
parser.add_argument('--frontend-timeout', type=int, default=500, metavar="<milliseconds>",
help='Set frontend translation timeout (%(default)s)')
2020-12-20 19:03:53 +00:00
2020-12-19 22:40:37 +00:00
args = parser.parse_args()
if __name__ == "__main__":
2021-01-19 17:53:53 +00:00
app = create_app(char_limit=args.char_limit,
2020-12-20 20:05:22 +00:00
req_limit=args.req_limit,
2021-01-19 17:53:53 +00:00
batch_limit=args.batch_limit,
2020-12-20 20:52:02 +00:00
ga_id=args.ga_id,
debug=args.debug,
frontend_language_source=args.frontend_language_source,
frontend_language_target=args.frontend_language_target,
frontend_timeout=args.frontend_timeout)
2020-12-20 20:05:22 +00:00
if args.debug:
app.run(host=args.host, port=args.port)
else:
from waitress import serve
2021-01-19 21:49:50 +00:00
serve(app, host=args.host, port=args.port, url_scheme='https' if args.ssl else 'http')