-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
230 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ ui2/.vscode | |
ui2/.pnp.cjs | ||
ui2/.pnp.loader.mjs | ||
ui2/.env.development.local | ||
ui2/public/papermerge-runtime-config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ simplest.yml | |
ui/public/runtime/config.js | ||
.ruff_cache/ | ||
.pytest_cache/ | ||
.enwardrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,14 @@ ENV CORE_APP=/core_app | |
ENV PAPERMERGE__DATABASE__URL=sqlite:////db/db.sqlite3 | ||
ENV PAPERMERGE__AUTH__USERNAME=admin | ||
ENV [email protected] | ||
ENV PAPERMERGE__OCR__DEFAULT_LANGUAGE=deu | ||
ENV PAPERMERGE__MAIN__API_PREFIX="" | ||
ENV PAPERMERGE__OCR__LANG_CODES="deu,eng,ron" | ||
ENV PAPERMERGE__OCR__DEFAULT_LANG_CODE="deu" | ||
ENV PAPERMERGE__OCR__AUTOMATIC="false" | ||
|
||
RUN apk update && apk add linux-headers python3-dev \ | ||
gcc \ | ||
curl \ | ||
libc-dev \ | ||
supervisor \ | ||
imagemagick \ | ||
|
@@ -27,6 +30,7 @@ RUN apk update && apk add linux-headers python3-dev \ | |
poppler-utils | ||
|
||
RUN pip install --upgrade poetry roco==0.4.2 | ||
RUN curl -L -o /bin/env2js https://github.com/papermerge/env2js/releases/download/0.2/env2js.amd64 | ||
|
||
COPY poetry.lock pyproject.toml README.md LICENSE ${CORE_APP}/ | ||
|
||
|
@@ -37,6 +41,7 @@ COPY docker/standard/entrypoint.sh /entrypoint.sh | |
COPY docker/standard/bundles/supervisor/* /etc/papermerge/ | ||
COPY docker/standard/bundles/nginx/* /etc/nginx/ | ||
COPY docker/standard/logging.yaml /etc/papermerge/ | ||
COPY docker/standard/core.js.tmpl /${CORE_APP}/core.js.tmpl | ||
COPY ./papermerge ${CORE_APP}/papermerge/ | ||
COPY alembic.ini ${CORE_APP}/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
window.__PAPERMERGE_RUNTIME_CONFIG__ = { | ||
ocr__lang_codes: "{{ .PAPERMERGE__OCR__LANG_CODES }}", | ||
ocr__default_lang_code: "{{ .PAPERMERGE__OCR__DEFAULT_LANG_CODE }}", | ||
ocr__automatic: {{ .PAPERMERGE__OCR__AUTOMATIC }} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import uuid | ||
import typer | ||
|
||
from papermerge.core.tasks import send_task | ||
from papermerge.core.db.engine import Session | ||
|
||
from papermerge.core import dbapi, constants, types | ||
|
||
|
||
app = typer.Typer(help="OCR tasks") | ||
|
||
|
||
@app.command() | ||
def schedule_ocr(node_id: uuid.UUID, force: bool = False, lang: str | None = None): | ||
"""Schedules OCR for given node ID""" | ||
with Session() as db_session: | ||
node_type: types.CType = dbapi.get_node_type(db_session, node_id) | ||
|
||
if node_type == "document": | ||
if lang is None: | ||
lang = dbapi.get_document_lang(db_session, node_id) | ||
send_task( | ||
constants.WORKER_OCR_DOCUMENT, | ||
kwargs={ | ||
"document_id": str(node_id), | ||
"lang": lang, | ||
}, | ||
route_name="ocr", | ||
) | ||
else: | ||
# get all descendants of node_id | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
window.__PAPERMERGE_RUNTIME_CONFIG__ = { | ||
ocr__lang_codes: "deu,eng,ron, spa, ita, fra", | ||
ocr__default_lang_code: "eng", | ||
ocr__automatic: false | ||
} |
85 changes: 85 additions & 0 deletions
85
ui2/src/components/ScheduleOCRProcessCheckbox/ScheduleOCRProcessCheckbox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {OCR_LANG} from "@/cconstants" | ||
import {useRuntimeConfig} from "@/hooks/runtime_config" | ||
import {OCRCode} from "@/types/ocr" | ||
import {Checkbox, ComboboxData, Select, Stack} from "@mantine/core" | ||
import {useState} from "react" | ||
|
||
interface Args { | ||
initialCheckboxValue: boolean | ||
defaultLang: OCRCode | ||
onLangChange: (newLang: OCRCode) => void | ||
onCheckboxChange: (newValue: boolean) => void | ||
} | ||
|
||
export default function ScheduleOCRProcessCheckbox({ | ||
initialCheckboxValue, | ||
defaultLang, | ||
onCheckboxChange, | ||
onLangChange | ||
}: Args) { | ||
const runtimeConfig = useRuntimeConfig() | ||
const langData = langCodes2ComboboxData(runtimeConfig.ocr__lang_codes) | ||
const [checked, setChecked] = useState<boolean>(initialCheckboxValue) | ||
const [lang, setLang] = useState<OCRCode>(defaultLang) | ||
|
||
const onCheckboxChangeLocal = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const newValue = e.currentTarget.checked | ||
setChecked(newValue) | ||
onCheckboxChange(newValue) | ||
} | ||
const onLangChangeLocal = (value: string | null) => { | ||
if (value) { | ||
setLang(value as OCRCode) | ||
onLangChange(value as OCRCode) | ||
} | ||
} | ||
|
||
return ( | ||
<Stack my={"md"}> | ||
<Checkbox | ||
mt="md" | ||
mb="md" | ||
label="Schedule OCR processing" | ||
checked={checked} | ||
onChange={onCheckboxChangeLocal} | ||
/> | ||
{checked && ( | ||
<Select | ||
searchable | ||
defaultValue={defaultLang} | ||
onChange={onLangChangeLocal} | ||
data={langData} | ||
value={lang} | ||
/> | ||
)} | ||
</Stack> | ||
) | ||
} | ||
|
||
function langCodes2ComboboxData(langCodes: string): ComboboxData { | ||
/* | ||
Input/Output examples: | ||
example 1: | ||
input: "deu,eng,ron" | ||
output: [ | ||
{value: "deu", label: "Deutsch"}, | ||
{value: "eng", label: "English"}, | ||
{value: "ron", label: "Română"} | ||
] | ||
example 2: | ||
input: "fra,spa" | ||
output: [ | ||
{value: "fra", label: "Français"}, | ||
{value: "spa", label: "Español"}, | ||
] | ||
*/ | ||
return langCodes | ||
.split(",") | ||
.map(v => v.trim()) | ||
.map(v => { | ||
return {value: v, label: OCR_LANG[v] || "Unknown Code"} | ||
}) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {RuntimeConfig} from "@/types/runtime_config" | ||
import {useEffect, useState} from "react" | ||
|
||
const RUNTIME_CONFIG_DEFAULT: RuntimeConfig = { | ||
ocr__lang_codes: "deu,eng,ron", | ||
ocr__default_lang_code: "deu", | ||
ocr__automatic: false | ||
} | ||
|
||
export function useRuntimeConfig(): RuntimeConfig { | ||
const [config, setConfig] = useState<RuntimeConfig>(RUNTIME_CONFIG_DEFAULT) | ||
|
||
useEffect(() => { | ||
if (window.hasOwnProperty("__PAPERMERGE_RUNTIME_CONFIG__")) { | ||
setConfig(window.__PAPERMERGE_RUNTIME_CONFIG__) | ||
} | ||
}, [JSON.stringify(window.__PAPERMERGE_RUNTIME_CONFIG__)]) | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {OCRCode} from "@/types" | ||
|
||
export type RuntimeConfig = { | ||
ocr__lang_codes: string | ||
ocr__default_lang_code: OCRCode | ||
ocr__automatic: boolean | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
__PAPERMERGE_RUNTIME_CONFIG__: RuntimeConfig | ||
} | ||
} |