Don't waste your food again with AiFame
Tags: azuretrialhack, python, azure, docker
Published: 2022-03-08 21:13:14

### Overview of My Submission

How many times did you forget to eat you food before expiring? Not only it is a waste of money, but also a waste of food that you could have eaten, used to prepare a dinner with your friends or gifted to someone.

We built a web application called AiFame made for the Microsoft Azure Trial Hackathon on DEV 2022. Don't waste your food again!

AiFame allows you to:
- Take a picture of your shopping and computer vision algorithms will detect foods automatically
- Manage your food inventory like modifying quantity and expiration date.

Try it live [here](http://aifame.azurewebsites.net)!
Try to manage your inventory or scan foods from a test image.

{% youtube FRcXb6Eim50 %}

### Submission Category: 

We chose to participate in the **Computing Captains** category because the app was deployed using **Azure App Service**. The container image is saved in the **Azure Container Registry**.

### Link to Code on GitHub

{% embed https://github.com/andregri/AiFame %}

### Azure Services we used

![project diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbxjqx2yx9i1yuhqujny.png)

The app deployed with App Service interacts with a SQL database to store user data and a storage blob to store the images uploaded by users.

Whenever an image is pushed to the blob, Azure Computer Vision analyzes it to detect objects bounding box. Then, for each bounding box we used again Computer Vision to obtain the food name of the object.

The CICD pipeline uses both GitHub Actions and Azure App Service.
Every push or pull request on development branch triggers the workflow that builds and tests the application:
```yaml
# This is a basic workflow to help you get started with Actions

name: ci

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main, dev ]
  pull_request:
    branches: [ main, dev ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2.3.1
        with:
          # Version range or exact version of a Python version to use, using SemVer's version range syntax.
          python-version: 3.9
          # The target architecture (x86, x64) of the Python interpreter.
          architecture: x64
          
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
```

Every push on the main branch, the Docker image is built and pushed automatically to the Azure Container Registry:
```yaml
on: [push]
name: cd

jobs:
    build-and-deploy:
        runs-on: ubuntu-latest
        steps:
        # checkout the repo
        - name: 'Checkout GitHub Action'
          uses: actions/checkout@main
          
        - name: 'Login via Azure CLI'
          uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
        
        - name: 'Build and push image'
          uses: azure/docker-login@v1
          with:
            login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
            username: ${{ secrets.REGISTRY_USERNAME }}
            password: ${{ secrets.REGISTRY_PASSWORD }}
        - run: |
            docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/aifame --file Dockerfile.prod
            docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/aifame
```

In addition to that, it is necessary to enable the "Continuous Deployment" option on App Service as show in the image below:

![App Service Continuous Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dy597r9jyg5kuijfzga9.png)

Below there is the list of all resources we used:

![azure resources](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ln9lzdff0dmngrkyesug.png)

### Authors
[andregri](https://github.com/andregri)
[CaptainMich](https://github.com/CaptainMich)
[Dadigno](https://github.com/Dadigno)