# 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 1. **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 python main.py ``` Or using uvicorn: ```bash uvicorn main:app --reload ``` ## 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 - `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. - `requirements.txt`: Python dependencies. - `.env`: Environment variables (not tracked by git).