Crivella / ocr_translate

Django based web server for running OCR + Translation of incoming images
GNU General Public License v3.0
18 stars 2 forks source link

OCR_translate

This is a Django app for creating back-end server aimed at performing OCR and translation of images received via a POST request.

The OCR and translation is performed using freely available machine learning models and packages (see below for what is currently implemented).

The server is designed to be used together with this browser extension, acting as a front-end providing the images and controlling the model languages and models being used.

For more information, please consult the Full Documentation

Possible problems

Running the server

If you plan to use a different settings (eg. database, or model location), you can either:

You will also have to modify the ALLOWED_HOSTS in case you plan to access the server from somewhere other than localhost.

All the different way to run the server may provide different set of default values (each of them is targeted for a different level of usage).

From Release file (Windows)

(Tested on Windows 11) From the github releases page you can download either:

Usage: Unzip the file and from inside the folder, run the run_server-XXX.exe file (XXX=cpu/gpu)

The server will run with sensible defaults. Most notably the models files and database will be downloaded/created under %userprofile%/.ocr_translate. Also the gpu version will attempt to run on GPU by default, and fall-back to CPU if the former is not available.

For customization, you can set the environment variable yourself:

SuperUser: By default the server will be created with a admin user admin:password (release only). You can login to the admin interface at http://127.0.0.1:4000/admin/ in order to manage the database. The main idea is to use this to manually add new models (with the appropriate entrypoint) if you want to test out, model that are not yet available. (If you find good models, please do share).

NOTE: The server by default is open only to localhost. If you ever plan to change this, make sure to change the admin password.

From Github

The Github repo provides not only the Django app files, but also the already configured project files used to start the server.

Create/Initialize your database by running

python manage.py migrate

inside your project folder.

NOTE: From version 0.3.X model installation and functionalities have been moved to plugins that need to be pip installed separately. See this documentation page for a list of validated plugins.

Run the server using for example one of the following options:

At least for the first time, it is suggested to run the server with the Environment variables AUTOCREATE_LANGUAGES and AUTOCREATE_VALIDATED_MODELS set to "true" to automatically load the validated languages and models provided by the project.

Notes:

SuperUser: You can create a superuser for managing the database via the django-admin interface by running

python manage.py createsuperuser

From PyPI installation

Run the command

pip install django-ocr_translate

By default torch 2.x will come in its CUDA enabled version. While this works also for CPU, it will also install ~1 GB of cuda dependencies. If you wish to run on CPU only, download the file requirements-torch-cpu.txt first and run

pip install -r requirements-torch-cpu.txt

before installing the python package.

When installing the project from PyPI, only the app is available. This will need to be integrated in a Django project in order to be used. These are the minimal instruction for creating a project and start running the server:

From docker image

This section assumes you have docker installed!!!

CPU and CUDA specific images are available on DockerHUB:

Download the image from DockerHUB:

or create it manually create your image:

Run the command:

docker run --name CONTAINER_NAME -v PATH_TO_YOUR_MODEL_DIRECTORY:/models -v PATH_TO_DIR_WITH_SQLITE_FILE:/data --env-file=PATH_TO_AND_ENV_VARIABLE_FILE -p SERVER_PORT:4000 -d ocr_translate

See the Environment variables section for configuring your environment variable file. Additionally the docker image defines several other variables to automatically create an admin user for managing the database via the django-admin interface: