(Le français est disponible au bas de la page)
FertiScan helps inspectors analyze and process fertilizer labels by extracting text and generating structured forms.
This repository contains the backend for FertiScan, a FastAPI-based server designed to work with the frontend. It handles image uploads, document analysis using OCR, and form generation using an LLM.
- Python 3.11+
- pip
- virtualenv
- Azure Document Intelligence and OpenAI API keys
-
Clone the repository:
git clone https://github.com/ai-cfia/fertiscan-backend.git cd fertiscan-backend
-
Install dependencies:
pip install -r requirements.txt
-
Start the server in development mode:
fastapi dev app/main.py --port 5000
-
Build the Docker image:
docker build -t fertiscan-backend .
-
Run the Docker container:
docker run -p 5000:5000 --env-file .env.secrets fertiscan-backend
-
Create a
.env.secrets
file from .env.secrets.template. Include the following environment variables:DB_USER=postgres DB_PASSWORD=postgres DB_HOST=postgres DB_PORT=5432 DB_NAME=fertiscan BB_URL=bytebase_url BB_SERVICE_ACCOUNT=your-bytebase-sa@service.bytebase.com BB_SERVICE_KEY=your-bytebase-sa-key BB_INSTANCE_ID=your-bytebase-instance-id BB_DATABASE_ID=your-bytebase-database-id
You can find their values in our vault under fertiscan-dev.
-
Start the Docker container:
docker-compose up --build
Side note: If you are on an ARM-based machine, you will need to build the image with the
docker-compose build --build-arg TARGETARCH=arm64
command.
The application will be available at http://localhost:80
. The database should
be dynamically built based on the latest schema from Bytebase.
To use pgAdmin, navigate to http://localhost:5050
and log in with
admin@example.com
and admin
. You can then register a new server with the
following details:
- Host:
postgres
- Port:
5432
- Username:
postgres
- Password:
postgres
- Database:
fertiscan
Create a .env.secrets
file from .env.secrets.template.
AZURE_API_ENDPOINT=your_azure_form_recognizer_endpoint
AZURE_API_KEY=your_azure_form_recognizer_key
AZURE_OPENAI_API_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_API_KEY=your_azure_openai_key
AZURE_OPENAI_DEPLOYMENT=your_azure_openai_deployment
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=your_db_port
DB_NAME=your_db_name
FERTISCAN_SCHEMA=your_fertiscan_schema
UPLOAD_PATH=path/to/file
ALLOWED_ORIGINS=["http://url.to_frontend/"]
The Swagger UI for the API of FertiScan
is available at /docs
.
More details in the developer documentation.
FertiScan aide les inspecteurs à analyser et traiter les étiquettes d'engrais en extrayant du texte et en générant des formulaires structurés.
Ce dépôt contient le backend de FertiScan, un serveur basé sur FastAPI conçu pour fonctionner avec le frontend. Il gère les téléversements d'images, l'analyse de documents à l'aide de l'OCR et la génération de formulaires à l'aide d'un LLM.
- Python 3.11+
- pip
- virtualenv
- Clés API Azure Document Intelligence et OpenAI
-
Clonez le dépôt :
git clone https://github.com/ai-cfia/fertiscan-backend.git cd fertiscan-backend
-
Installez les dépendances :
pip install -r requirements.txt
-
Démarrez le serveur en mode développement :
fastapi dev app/main.py --port 5000
-
Construisez l'image Docker :
docker build -t fertiscan-backend \ --build-arg ARG_AZURE_API_ENDPOINT=your_azure_form_recognizer_endpoint \ --build-arg ARG_AZURE_API_KEY=your_azure_form_recognizer_key \ --build-arg ARG_AZURE_OPENAI_DEPLOYMENT=your_azure_openai_deployment \ --build-arg ARG_AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint \ --build-arg ARG_AZURE_OPENAI_KEY=your_azure_openai_key \ --build-arg ARG_FERTISCAN_STORAGE_URL=your_fertiscan_storage_url \ --build-arg ARG_FERTISCAN_DB_URL=your_fertiscan_db_url \ --build-arg ARG_FERTISCAN_SCHEMA=your_fertiscan_schema \ --build-arg ARG_ALLOWED_ORIGINS=["http://url.to_frontend/"] \ --build-arg OTEL_EXPORTER_OTLP_ENDPOINT=your_phoenix_endpoint \ --build-arg ARG_PROMPT_PATH=path/to/file \ --build-arg ARG_UPLOAD_PATH=path/to/file \ .
-
Lancez le conteneur Docker :
docker run -p 5000:5000 fertiscan-backend
-
Créez un fichier
.env
à partir du fichier .env.secrets.template. Incluez les variables d'environnement suivantes :FERTISCAN_DB_URL=postgresql://postgres:postgres@postgres:5432/fertiscan BB_URL=bytebase_url BB_SERVICE_ACCOUNT=your-bytebase-sa@service.bytebase.com BB_SERVICE_KEY=your-bytebase-sa-key BB_INSTANCE_ID=your-bytebase-instance-id BB_DATABASE_ID=your-bytebase-database-id
Vous pouvez trouver leurs valeurs dans notre coffre-fort sous fertiscan-dev.
-
Lancez le conteneur Docker :
docker-compose up --build
Note : Si vous êtes sur une machine ARM, vous devrez construire l'image avec la commande
docker-compose build --build-arg TARGETARCH=arm64
.
L'application sera disponible sur http://localhost:80
. La base de données sera
construite dynamiquement en fonction du dernier schéma depuis Bytebase.
Pour utiliser pgAdmin, accédez à http://localhost:5050
et connectez-vous avec
admin@example.com
et admin
. Vous pourrez alors enregistrer un nouveau
serveur avec les détails suivants :
- Hôte :
postgres
- Port :
5432
- Utilisateur :
postgres
- Mot de passe :
postgres
- Base de données :
fertiscan
Créez un fichier .env
à partir du fichier .env.secrets.template.
AZURE_API_ENDPOINT=your_azure_form_recognizer_endpoint
AZURE_API_KEY=your_azure_form_recognizer_key
AZURE_OPENAI_API_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_API_KEY=your_azure_openai_key
AZURE_OPENAI_DEPLOYMENT=your_azure_openai_deployment
FERTISCAN_DB_URL=your_fertiscan_db_url
FERTISCAN_SCHEMA=your_fertiscan_schema
UPLOAD_PATH=path/to/file
ALLOWED_ORIGINS=["http://url.to_frontend/"]
L'interface Swagger UI pour l'API de
FertiScan est disponible à l'adresse /docs
.
Pour plus de détails, consultez la documentation pour les développeurs.