Skip to content

yotambraun/VisualInsight

Repository files navigation

VisualInsight - App using Google Generative AI (Gemini)

Python 3.9 Streamlit Google Generative AI (Gemini) AWS Services Docker Terraform GitHub Actions

A Streamlit-based web application that analyzes images using Google Generative AI (Gemini) and stores both the original images and analysis in Amazon S3. I have also written a Medium article about this project, detailing its features and implementation.

Table of Contents


Overview

VisualInsight is a simple image-analysis solution that:

  1. Lets you upload an image (JPG/PNG) via the Streamlit interface.
  2. Sends the image to Google Generative AI (Gemini) for an analysis prompt.
  3. Stores the image in an AWS S3 bucket.
  4. Displays the AI-generated analysis to the user.

Architecture

Architecture Diagram

  1. Frontend: Streamlit application (Python).
  2. Backend:
    • AWS S3 for file storage.
    • Google Generative AI for text analysis.
  3. Infrastructure:
    • Terraform for provisioning AWS resources (S3, ECR, ECS, IAM roles/policies, etc.).
  4. Docker: Container image for the Streamlit app.
  5. CI/CD:
    • GitHub Actions workflow to build and push Docker images to ECR, and update the ECS service.

Features

  • Image Upload: Users can upload images (JPEG, PNG, etc.).
  • AI Image Analysis: Using Google Generative AI API (Gemini).
  • S3 Storage: Uploaded images are stored in an S3 bucket.
  • Dockerized: Streamlit application wrapped in a Docker container.
  • Scalable Infrastructure: Terraform-managed infrastructure on AWS.
  • Continuous Deployment: GitHub Actions pipeline automates Docker builds and ECS deployments.

Prerequisites

  1. Python 3.9+ (for local testing).
  2. Docker installed (for containerization).
  3. Terraform installed (if you plan to deploy via Terraform).
  4. AWS Account and credentials with appropriate permissions.
  5. Google Cloud API key for Generative AI (Gemini).
  6. GitHub Actions set up with secrets:
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_REGION (e.g., us-east-1)

Local Development

Environment Variables

Create a .env file in the project root (or set these in your environment) with the following values:

AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"
AWS_REGION="us-east-1"
S3_BUCKET_NAME="YOUR_S3_BUCKET_NAME"
GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"

Running Locally

  1. Install dependencies:
pip install -r requirements.txt
  1. Run the Streamlit app:
streamlit run app/main.py
  1. Access the app by opening your browser to: http://localhost:8501

Docker

Building the Image

  1. Build the Docker image:
docker build -t visualinsight:latest .
  1. Check that the image was built:
docker images

Running the Container

  1. Run the Docker container:
docker run -p 8501:8501 \
    -e AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID" \
    -e AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY" \
    -e AWS_REGION="us-east-1" \
    -e S3_BUCKET_NAME="YOUR_S3_BUCKET_NAME" \
    -e GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY" \
    visualinsight:latest
  1. Open the browser at http://localhost:8501.

Terraform Deployment

This project includes Terraform configurations to create and manage AWS resources (S3 bucket, ECR repository, ECS cluster, etc.).

  1. Initialize Terraform:
cd infrastructure/terraform
terraform init
  1. Validate the configuration:
terraform validate
  1. Preview changes:
terraform plan -var="bucket_name=bucket_name"
  1. Apply the changes:
terraform apply -var="bucket_name=bucket_name"

Once complete, Terraform will:

  • reate an S3 bucket (with the specified name).
  • Create an ECR repository (for the Docker image).
  • Create an ECS cluster, IAM roles, policies, etc.

CI/CD with GitHub Actions

The .github/workflows/deploy.yml file automates:

  1. Checkout of your code.
  2. AWS credentials configuration.
  3. Docker build and push to AWS ECR.
  4. Forcing a new ECS deployment to pull the latest image.

To use this workflow, you need to set the following GitHub Secrets: Go to Settings > Secrets and variables > Actions in your GitHub repository and add:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION
  • S3_BUCKET_NAME
  • GOOGLE_API_KEY

With these secrets configured, any push to the main branch triggers the build-and-deploy workflow.

Screenshots

1. Uploading an Image

App Upload Image

2. Analysis Results

Screenshot Description
Analysis 1 First analysis page demo
Analysis 2 Second analysis page demo
Analysis 3 Third analysis page demo

3. Example Original Image

Original Uploaded Image

4. AWS ECR

ECR Screenshot

5. AWS ECS

ECS Screenshot

6. GitHub Actions

Screenshot Description
GitHub Actions Full Full GitHub Actions workflow
GitHub Actions Partial Partial view of the CI/CD steps

7. S3 Bucket

S3 Bucket Screenshot

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published