Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibreTranslate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riße, Matthias
LibreTranslate
Commits
8761af71
Commit
8761af71
authored
4 years ago
by
Claas Augner
Browse files
Options
Downloads
Patches
Plain Diff
feat(batch): add --batch-limit
parent
2c5eba14
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
app/app.py
+6
-1
6 additions, 1 deletion
app/app.py
main.py
+4
-1
4 additions, 1 deletion
main.py
with
11 additions
and
2 deletions
README.md
+
1
−
0
View file @
8761af71
...
...
@@ -92,6 +92,7 @@ docker-compose up -d --build
| --port | Set port to bind the server to |
`5000`
|
| --char-limit | Set character limit |
`No limit`
|
| --req-limit | Set maximum number of requests per minute per client |
`No limit`
|
| --batch-limit | Set maximum number of texts to translate in a batch request |
`No limit`
|
| --ga-id | Enable Google Analytics on the API client page by providing an ID |
`No tracking`
|
| --debug | Enable debug environment |
`False`
|
| --ssl | Whether to enable SSL |
`False`
|
...
...
This diff is collapsed.
Click to expand it.
app/app.py
+
6
−
1
View file @
8761af71
...
...
@@ -13,7 +13,7 @@ def get_remote_address():
return
ip
def
create_app
(
char_limit
=-
1
,
req_limit
=-
1
,
ga_id
=
None
,
debug
=
False
,
frontend_language_source
=
"
en
"
,
frontend_language_target
=
"
en
"
):
def
create_app
(
char_limit
=-
1
,
req_limit
=-
1
,
batch_limit
=-
1
,
ga_id
=
None
,
debug
=
False
,
frontend_language_source
=
"
en
"
,
frontend_language_target
=
"
en
"
):
from
app.init
import
boot
boot
()
...
...
@@ -207,6 +207,11 @@ def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False, frontend_la
batch
=
isinstance
(
q
,
list
)
if
batch
and
batch_limit
!=
-
1
:
batch_size
=
len
(
q
)
if
batch_limit
<
batch_size
:
abort
(
400
,
description
=
"
Invalid request: Request (%d) exceeds text limit (%d)
"
%
(
batch_size
,
batch_limit
))
if
char_limit
!=
-
1
:
if
batch
:
chars
=
sum
([
len
(
text
)
for
text
in
q
])
...
...
This diff is collapsed.
Click to expand it.
main.py
+
4
−
1
View file @
8761af71
...
...
@@ -10,6 +10,8 @@ parser.add_argument('--char-limit', default=-1, type=int, metavar="<number of ch
help
=
'
Set character limit (%(default)s)
'
)
parser
.
add_argument
(
'
--req-limit
'
,
default
=-
1
,
type
=
int
,
metavar
=
"
<number>
"
,
help
=
'
Set maximum number of requests per minute per client (%(default)s)
'
)
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)
'
)
parser
.
add_argument
(
'
--ga-id
'
,
type
=
str
,
default
=
None
,
metavar
=
"
<GA ID>
"
,
help
=
'
Enable Google Analytics on the API client page by providing an ID (%(default)s)
'
)
parser
.
add_argument
(
'
--debug
'
,
default
=
False
,
action
=
"
store_true
"
,
...
...
@@ -25,8 +27,9 @@ args = parser.parse_args()
if
__name__
==
"
__main__
"
:
app
=
create_app
(
char_limit
=
args
.
char_limit
,
app
=
create_app
(
char_limit
=
args
.
char_limit
,
req_limit
=
args
.
req_limit
,
batch_limit
=
args
.
batch_limit
,
ga_id
=
args
.
ga_id
,
debug
=
args
.
debug
,
frontend_language_source
=
args
.
frontend_language_source
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment