# AI-Assisted Smart Data Entry Backend This project provides a FastAPI-based backend for extracting structured data from medical receipts using OpenAI's GPT-4o model with structured outputs. ## Features - **FastAPI**: Modern, fast web framework for building APIs. - **Structured Extraction**: Uses OpenAI's `beta.chat.completions.parse` to ensure extracted data adheres to a Pydantic schema. - **CORS Enabled**: Configured to allow access from frontend applications (e.g., Angular). - **Health Check**: Simple endpoint to verify server status. ## Setup ### Backend (FastAPI) 1. **Initialize Virtual Environment**: ```bash # Create environment python -m venv venv # Activate environment (Windows) .\venv\Scripts\activate # Activate environment (Mac/Linux) # source venv/bin/activate ``` 2. **Install Dependencies**: ```bash pip install -r requirements.txt ``` 2. **Configure Environment**: Create a `.env` file in the root directory and add your OpenAI API key: ```env OPENAI_API_KEY=your_api_key_here ``` 3. **Run the Server**: ```bash uvicorn backend.main:app --reload ``` ### Frontend (Angular) 1. **Install Dependencies**: ```bash cd ai-data-entry-ui npm install --legacy-peer-deps ``` 2. **Run the UI**: ```bash npm start ``` ## API Endpoints ### `GET /health` Returns the status of the server. ### `POST /api/v1/extract` Extracts data from a medical receipt image. **Request Body**: - `file`: Multipart image file. - `user_name` (optional): Name of the employee. - `department` (optional): Department of the employee. **Response**: Returns a structured JSON matching the `ExtractionResponse` schema. ## Project Structure - `backend/` - `main.py`: Entry point and API endpoints. - `schemas.py`: Pydantic models for data validation and structured output. - `services/`: - `openai_service.py`: Logic for interacting with OpenAI API. - `ai-data-entry-ui/`: Angular frontend. - `requirements.txt`: Python dependencies. - `.env`: Environment variables (not tracked by git).