This application consists of two parts:
- A Flask backend API server
- A React frontend web application
cur_ocr/
├── app/ # Flask application code
│ ├── controllers/ # Route handlers
│ ├── models/ # Database models (User, OCRResult)
│ ├── static/ # Static files (uploads, etc.)
│ ├── utils/ # Utility functions
│ └── __init__.py # App factory
├── frontend/ # React frontend code
├── instance/ # Instance folder for Flask (config, etc.)
├── uploads/ # Uploaded files (created when needed)
├── app.py # Flask application entry point
├── config.py # Application configuration
├── requirements.txt # Python dependencies
├── .env-example # Example environment variables
└── README.md # Project documentation
Copy .env-example to .env and update the values as needed:
FLASK_APP=app.py
FLASK_ENV=development
SECRET_KEY=your-secret-key-here
DATABASE_URL=sqlite:///ocr_app.db
FLASK_DEBUG=0
pip install -r requirements.txtFirst, activate your Python virtual environment (if you're using one) and start the Flask server:
# From the project root (cur_ocr)
python app.pyThe Flask server will run on http://localhost:5000.
In a separate terminal, navigate to the frontend directory and start the React development server:
# From the project root
cd frontend
npm install # if not already done
npm run devThe React development server will run on http://localhost:3000 or http://localhost:3001.
Open your browser and go to:
- http://localhost:3000 (or 3001) to access the React frontend
FLASK_APP: Entry point for Flask (usuallyapp.py)FLASK_ENV: Flask environment (developmentorproduction)SECRET_KEY: Secret key for session managementDATABASE_URL: Database connection string (default: SQLite)FLASK_DEBUG: Set to1to enable debug mode
SECRET_KEY: Used for session securitySQLALCHEMY_DATABASE_URI: Database URI (default: SQLite)SQLALCHEMY_TRACK_MODIFICATIONS: SQLAlchemy event system (default: False)UPLOAD_FOLDER: Path for uploaded filesMAX_CONTENT_LENGTH: Maximum upload size (default: 16MB)
- Flask==2.3.3
- flask-login==0.6.3
- flask-wtf==1.2.2
- flask-cors==4.0.0
- email-validator==2.1.0
- Werkzeug==3.0.1
- SQLAlchemy==2.0.27
- wtforms==3.0.1
- easyocr==1.7.2
- numpy==1.26.4
- PyMuPDF==1.25.0
- pdf2image==1.17.0
- gunicorn==21.2.0
- python-dotenv==1.0.1
id: Primary keyusername: Unique usernameemail: Unique emailpassword_hash: Hashed passwordocr_results: Relationship to OCR results
id: Primary keyfilename: Name of the uploaded filefile_path: Path to the filetext_content: Extracted texttimestamp: Upload timeuser_id: Foreign key to User
The backend provides the following API endpoints:
POST /api/login- Log in a userPOST /api/logout- Log out a userPOST /api/register- Create a new userGET /api/user- Get current authenticated user
POST /api/ocr- Process a file with OCRGET /api/results- Get a list of OCR resultsGET /api/results/:id- Get details of a specific resultDELETE /api/results/:id- Delete a specific result
If you encounter issues:
- Ensure both servers are running in separate terminals
- Check the browser's console (F12) for any error messages
- Check the terminal running the Flask backend for error logs
- Visit http://localhost:3000/server-help.html for more troubleshooting tips