Skip to content

Commit

Permalink
Workflows updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacklyn22 committed May 1, 2024
1 parent d41e8ed commit 34116f0
Show file tree
Hide file tree
Showing 31 changed files with 325 additions and 1,584 deletions.
2 changes: 1 addition & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ FLASK_ENV=development
FLASK_PORT=10000
GITHUB_REPO=https://github.com/your-repository-url # unnecessary for basic operation
GITHUB_SECRET=your_github_secret # unnecessary for basic operation
OCR_API_KEY=your_ocr_api_key # replace with your own OCR API key from mindee
OCR_API_KEY=37bacde1f840522b837426aa425f62db # replace with your own OCR API key from mindee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI / CD
name: ML Service CI

on:
push:
Expand All @@ -13,15 +13,21 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
pip install -r requirements.txt
- name: Test with pytest
run: |
# Run your test commands
pip install pytest
pytest
- name: Build Docker image
run: docker build . --file Dockerfile
44 changes: 44 additions & 0 deletions .github/workflows/web-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Web App CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with pylint
run: |
pip install pylint
pylint --load-plugins=pylint_flask *.py
- name: Run tests
run: |
pip install pytest flask_testing
pytest
- name: Build Docker image
run: docker build . --file Dockerfile

- name: Push Docker image
uses: docker/build-push-action@v2
with:
push: true
tags: user/app:latest
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
# Final Project

[link to our project](http://161.35.189.70:10000)

An exercise to put to practice software development teamwork, subsystem communication, containers, deployment, and CI/CD pipelines. See [instructions](./instructions.md) for details.

# Team Members

[Edison Chen](https://github.com/ebc5802), [Natalie Wu](https://github.com/nawubyte), [Chelsea Li](https://github.com/qiaoxixi1), and [Jacklyn Hu](https://github.com/Jacklyn22)

# How To Run ChequeMate

First, rename the `env.sample` file to `.env` and make any necessary adjustments including changing the OCR API key to a valid API key from mindee.

Next, from the root directory, run `docker compose up --build`

Finally, open `http://localhost:10000/` in your local browser to view our web app.

# Docker Images
- [Docker Hub repo](https://hub.docker.com/repository/docker/sennyy/5-final-project-spring-2024-best-swes/general)
- [Machine Learning Client](https://hub.docker.com/layers/sennyy/5-final-project-spring-2024-best-swes/latest/images/sha256-8e6f5dc5c28f64ee5f8deb15ed03da005c09c8933a5b3f9f6d3aca934774eb17?context=repo)
- [Webapp](https://hub.docker.com/layers/sennyy/5-final-project-spring-2024-best-swes/webapp/images/sha256-a2177768a9c1b34b5995fa325076f42fb24d56aeb087b8824f203efdae94cd96?context=repo)


1 change: 0 additions & 1 deletion data/WiredTiger.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
WiredTiger lock file

2 changes: 1 addition & 1 deletion data/WiredTiger.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ WiredTiger 11.2.0: (November 10, 2022)
WiredTiger version
major=11,minor=2,patch=0
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=0),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.12=(addr="018381e4d2658b3d8481e4922db30e8581e497411dd2808080e2bfc0e22fc0",order=12,time=1714578634,size=24576,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=4,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=32,run_write_gen=28)),checkpoint_backup_info=,checkpoint_lsn=(4,4864)
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=0),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.59=(addr="018381e42c9ad31c8481e467d0d3748581e46d920d70808080e2efc0e22fc0",order=59,time=1714592877,size=24576,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=4,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=165,run_write_gen=161)),checkpoint_backup_info=,checkpoint_lsn=(12,4864)
Binary file modified data/WiredTiger.wt
Binary file not shown.
Binary file modified data/collection-2-8268252114545060607.wt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified data/index-3-8268252114545060607.wt
Binary file not shown.
Binary file not shown.
Binary file modified data/sizeStorer.wt
Binary file not shown.
Binary file removed machine-learning-client/RestaurantReceipt2.jpeg
Binary file not shown.
56 changes: 1 addition & 55 deletions machine-learning-client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from dotenv import load_dotenv
from bson import ObjectId
from mindee import Client, PredictResponse, product # To access mindee OCR API
import uuid

import logging

Expand Down Expand Up @@ -83,7 +82,7 @@ def pretdict_endpoint():
receipt_data = {
'receipt_name': receipt['supplier_name']['raw_value'],
'currency': receipt['locale']['currency'],
'items': [{'description': item['description'], 'amount': item['amount'], '_id': str(uuid.uuid4())} for item in receipt['items']],# generate a unique ID for each item
'items': [{'description': item['description'], 'amount': item['total_amount'], 'quantity': item['quantity']} for item in receipt['line_items']],
'total': receipt['total_amount']['value'],
'tax': receipt['total_tax']['value'],
'tip': receipt['tip']['value'],
Expand Down Expand Up @@ -122,58 +121,5 @@ def perform_ocr(Object_ID):
print("response.text: %s", response.text)
return response.json()

# def perform_ocr(Object_ID):
# logging.debug("starting perform_ocr function with mindee api...") # debug
# # Init a new client
# api_key = os.getenv("OCR_API_KEY") # Get the API key from environment variable
# mindee_client = Client(api_key)

# # Fetch the image data from the database
# image_data = db.receipts.find_one({"_id": Object_ID})['image']
# file_path = f"receipt_{Object_ID}.jpg" # Set the file path to save the image
# logging.debug("file path: %s", file_path) # debug

# # Save the image data to a file
# with open(file_path, "wb") as f:
# f.write(image_data)

# # Load the file
# input_doc = mindee_client.source_from_path(file_path)

# # Parse the file with the Mindee API
# result: PredictResponse = mindee_client.parse(product.ReceiptV5, input_doc)
# logging.debug("result: %s", result.document) # debug

# # Return the result as a JSON response
# return jsonify(result.document)

# def perform_ocr_old_version(Object_ID):
# logging.debug("starting perform_ocr function...") # debug
# url = "https://ocr.asprise.com/api/v1/receipt"
# image_data = db.receipts.find_one({"_id": Object_ID})['image']
# file_path = f"receipt_{Object_ID}.jpg" # Set the file path to save the image
# logging.debug("file path: %s", file_path) # debug
# with open(file_path, "wb") as f:
# f.write(image_data)
# file_path = file_path.replace('\x00', '') # Remove any null bytes from the file path


# # Get response (can only do this a couple times with the test API key)
# res = requests.post(url,
# data = {
# 'api_key': 'TEST',
# 'recognizer': 'auto',
# 'ref_no': 'ocr_python_123'
# },

# files = {
# 'file': open(file_path, "rb")
# })

# with open("response.json", "w") as f:
# f.write(res.text)

# return res.json()

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5002) # Run the app
3 changes: 1 addition & 2 deletions machine-learning-client/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ black
requests
Flask
python-dotenv
mindee
uuid
mindee
Loading

0 comments on commit 34116f0

Please sign in to comment.