Skip to content

Repository files navigation

F25-senior-design

Contents

  1. Setup of Local PostgreSQL Database
  2. Set up a Test User on Local Replate Database (before OAuth)
  3. OCR Tesseract Setup

Setup of Local PostgreSQL Database

Follow these steps to set up a local PostgreSQL database for the Django project.

1. Install PostgreSQL

Make sure you have PostgreSQL installed on your system.

Create a PostgreSQL user if you haven’t already:

    CREATE ROLE <YOUR_PSQL_USER> WITH LOGIN CREATEDB PASSWORD 'yourpassword';

2. Create the Database

Enter the psql shell:

    psql postgres

Then create the database:

    CREATE DATABASE replate OWNER <YOUR_PSQL_USER>;

3. Configure Django

Open settings.py and add the following:

    DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'HOST': os.getenv('LOCAL_DB_HOST', 'localhost'),
        'NAME': os.getenv('LOCAL_DB_NAME', 'replate'),
        'USER': os.getenv('LOCAL_DB_USER'),
        'PASSWORD': os.getenv('LOCAL_DB_PASSWORD'),
        'PORT': os.getenv('LOCAL_DB_PORT', '5432'),
        }
    }

4. Set Environment Variables

In your backend .env file (or .env.local), add the following values:

    LOCAL_DB_HOST=localhost
    LOCAL_DB_NAME=replate
    LOCAL_DB_USER=<YOUR_PSQL_USER>
    LOCAL_DB_PASSWORD=<YOUR_PASSWORD>
    LOCAL_DB_PORT=5432
IMPORTANT: Replace <YOUR_PSQL_USER> and <YOUR_PASSWORD> with your PostgreSQL credentials. Make sure .env is NOT committed to Git to keep passwords safe.

5. Apply Migrations

Make sure you've pulled the latest models.py from origin/main first!

Navigate to the Django project root (e.g., /backend) and run:

    python manage.py migrate            # apply migrations to your PostgreSQL database

6. Verify Database Tables

Connect to your database:

    psql -U <YOUR_PSQL_USER> -d replate

If the prompt shows replate=#, you are in the correct database.

List all tables:


    \dt

Type \q to exit the psql shell.

Setup complete! Your local PostgreSQL database is now ready and connected.

Set up a test user on local replate database (before OAuth)

For local testing before implementing OAuth, you can create a test user with the provided script:

Script location: backend/api/utils/create_test_user.py

Run this script to create the test user.

This will create a test user with:

username: test
password: 123

You can verify that the API is working by making a simple GET request to list inventory items of the test user:

curl -u test:123 http://127.0.0.1:8000/api/items/

You should get a JSON response (an empty list [] if no items exist yet)

This confirms that your local Django backend and test user are set up correctly.

OCR Tesseract Setup

The OCR functionality requires both the Tesseract executable and the Python wrapper pytesseract.

  1. Install Tesseract

macOS (using Homebrew):

brew install tesseract

Ubuntu/Debian:

sudo apt update
sudo apt install tesseract-ocr

Windows: Download the installer from Tesseract at UB Mannheim and add the installation directory to your PATH.

Verify installation:

tesseract --version
  1. Install Python Wrapper

Inside your activated virtual environment, install pytesseract (already stated in requirements.txt):

pip install -r requirements.txt
  1. Test OCR Endpoint

After setting up Tesseract, you can test the OCR upload endpoint with a sample image:

curl -u test:123 -X POST http://127.0.0.1:8000/api/ocr/scan/ \
  -F "image=/path/to/expiry_label.jpg"

Expected response: JSON containing the detected date(s) and any extracted text.

About

A cross-platform mobile app to track pantry items and recommend recipes

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages