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
50cf24a0
Commit
50cf24a0
authored
4 years ago
by
Tobias
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of github.com:Trekky12/LibreTranslate into main
parents
42267eb8
ce0aced4
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
app/__init__.py
+1
-0
1 addition, 0 deletions
app/__init__.py
app/app.py
+80
-0
80 additions, 0 deletions
app/app.py
main.py
+4
-0
4 additions, 0 deletions
main.py
with
88 additions
and
0 deletions
README.md
+
3
−
0
View file @
50cf24a0
...
...
@@ -60,6 +60,9 @@ git clone https://github.com/uav4geo/LibreTranslate
cd
LibreTranslate
pip
install
-e
.
libretranslate
[
args]
# Or
python main.py
[
args]
```
Then open a web browser to http://localhost:5000
...
...
This diff is collapsed.
Click to expand it.
app/__init__.py
+
1
−
0
View file @
50cf24a0
from
.main
import
main
This diff is collapsed.
Click to expand it.
app/app.py
+
80
−
0
View file @
50cf24a0
...
...
@@ -259,6 +259,86 @@ def create_app(char_limit=-1, req_limit=-1, batch_limit=-1, ga_id=None, debug=Fa
except
Exception
as
e
:
abort
(
500
,
description
=
"
Cannot translate text: %s
"
%
str
(
e
))
@app.route
(
"
/detect
"
,
methods
=
[
'
POST
'
])
def
detect
():
"""
Detect the language of a single text
---
tags:
- translate
parameters:
- in: formData
name: q
schema:
type: string
example: Hello world!
required: true
description: Text to detect
responses:
200:
description: Detections
schema:
id: detections
type: array
items:
type: object
properties:
confidence:
type: number
format: float
minimum: 0
maximum: 1
description: Confidence value
example: 0.6
language:
type: string
description: Language code
example: en
400:
description: Invalid request
schema:
id: error-response
type: object
properties:
error:
type: string
description: Error message
500:
description: Detection error
schema:
id: error-response
type: object
properties:
error:
type: string
description: Error message
429:
description: Slow down
schema:
id: error-slow-down
type: object
properties:
error:
type: string
description: Reason for slow down
"""
if
request
.
is_json
:
json
=
request
.
get_json
()
q
=
json
.
get
(
'
q
'
)
else
:
q
=
request
.
values
.
get
(
"
q
"
)
if
not
q
:
abort
(
400
,
description
=
"
Invalid request: missing q parameter
"
)
candidate_langs
=
list
(
filter
(
lambda
l
:
l
.
lang
in
language_map
,
detect_langs
(
q
)))
candidate_langs
.
sort
(
key
=
lambda
l
:
l
.
prob
,
reverse
=
True
)
return
jsonify
([{
'
confidence
'
:
l
.
prob
,
'
language
'
:
l
.
lang
}
for
l
in
candidate_langs
])
@app.route
(
"
/frontend/settings
"
)
def
frontend_settings
():
"""
...
...
This diff is collapsed.
Click to expand it.
main.py
0 → 100644
+
4
−
0
View file @
50cf24a0
from
app
import
main
if
__name__
==
"
__main__
"
:
main
()
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