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
0561deb1
Unverified
Commit
0561deb1
authored
3 years ago
by
Sébastien Thuret
Browse files
Options
Downloads
Patches
Plain Diff
Save suggestions in a database
parent
c0265898
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
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
app/app.py
+7
-1
7 additions, 1 deletion
app/app.py
app/suggestions.py
+31
-0
31 additions, 0 deletions
app/suggestions.py
with
39 additions
and
1 deletion
.gitignore
+
1
−
0
View file @
0561deb1
...
@@ -131,3 +131,4 @@ installed_models/
...
@@ -131,3 +131,4 @@ installed_models/
# Misc
# Misc
api_keys.db
api_keys.db
suggestions.db
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/app.py
+
7
−
1
View file @
0561deb1
...
@@ -9,6 +9,7 @@ from app import flood
...
@@ -9,6 +9,7 @@ from app import flood
from
app.language
import
detect_languages
,
transliterate
from
app.language
import
detect_languages
,
transliterate
from
.api_keys
import
Database
from
.api_keys
import
Database
from
.suggestions
import
Database
as
SuggestionsDatabase
from
translatehtml
import
translate_html
from
translatehtml
import
translate_html
...
@@ -617,7 +618,12 @@ def create_app(args):
...
@@ -617,7 +618,12 @@ def create_app(args):
@app.route
(
"
/suggest
"
,
methods
=
[
"
POST
"
])
@app.route
(
"
/suggest
"
,
methods
=
[
"
POST
"
])
@limiter.exempt
@limiter.exempt
def
suggest
():
def
suggest
():
# TODO:
q
=
request
.
values
.
get
(
"
q
"
)
s
=
request
.
values
.
get
(
"
s
"
)
source_lang
=
request
.
values
.
get
(
"
source
"
)
target_lang
=
request
.
values
.
get
(
"
target
"
)
SuggestionsDatabase
().
add
(
q
,
s
,
source_lang
,
target_lang
)
return
jsonify
({
"
success
"
:
True
})
return
jsonify
({
"
success
"
:
True
})
SWAGGER_URL
=
"
/docs
"
# URL for exposing Swagger UI (without trailing '/')
SWAGGER_URL
=
"
/docs
"
# URL for exposing Swagger UI (without trailing '/')
...
...
This diff is collapsed.
Click to expand it.
app/suggestions.py
0 → 100644
+
31
−
0
View file @
0561deb1
import
sqlite3
import
uuid
from
expiringdict
import
ExpiringDict
DEFAULT_DB_PATH
=
"
suggestions.db
"
class
Database
:
def
__init__
(
self
,
db_path
=
DEFAULT_DB_PATH
,
max_cache_len
=
1000
,
max_cache_age
=
30
):
self
.
db_path
=
db_path
self
.
cache
=
ExpiringDict
(
max_len
=
max_cache_len
,
max_age_seconds
=
max_cache_age
)
# Make sure to do data synchronization on writes!
self
.
c
=
sqlite3
.
connect
(
db_path
,
check_same_thread
=
False
)
self
.
c
.
execute
(
"""
CREATE TABLE IF NOT EXISTS suggestions (
"
q
"
TEXT NOT NULL,
"
s
"
TEXT NOT NULL,
"
source
"
TEXT NOT NULL,
"
target
"
TEXT NOT NULL
);
"""
)
def
add
(
self
,
q
,
s
,
source
,
target
):
self
.
c
.
execute
(
"
INSERT INTO suggestions (q, s, source, target) VALUES (?, ?, ?, ?)
"
,
(
q
,
s
,
source
,
target
),
)
self
.
c
.
commit
()
return
True
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