This project is a FastAPI-based web application that allows you to upload receipt images, processes them using Google Cloud Storage and Vertex AI, and returns structured receipt details in JSON format.
- Image Upload: Upload receipt images to Google Cloud Storage.
- Image Processing: Process uploaded images using Vertex AI to extract receipt details.
- List Bucket Contents: List the contents of the Google Cloud Storage bucket.
- Python 3.7+
- Google Cloud SDK
- FastAPI
- Uvicorn
python-dotenvgoogle-cloud-storagevertexai- Service account with the necessary permissions
-
Clone the Repository:
git clone https://your-repository-url.git cd your-repository-directory -
Create and Activate a Virtual Environment:
python3 -m venv venv source venv/bin/activate -
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
Create a
.envfile in the root of the project with the following content:GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service-account-file.json PROJECT_ID=your-google-cloud-project-id LOCATION=your-vertex-ai-location GCS_BUCKET_NAME=your-gcs-bucket-name
-
Run the Application:
uvicorn main:app --host 0.0.0.0 --port 8000
-
URL:
/process-image/ -
Method: POST
-
Description: Uploads an image to GCS and processes it with Vertex AI.
-
Request:
- file: The image file to be uploaded and processed.
-
Response:
- status: "SUCCESS" if the file was successfully read, otherwise "FAILED".
- reason: Detailed message.
- read: The extracted receipt details in JSON format.
- URL:
/list-gcs-bucket/ - Method: GET
- Description: Lists the contents of the specified GCS bucket.
- Response:
- contents: A list of objects in the GCS bucket.
- error: Error message, if any.
Use curl to upload an image and process it:
curl -X POST "http://127.0.0.1:8000/process-image/" -F "file=@/path/to/your/image.png"