Skip to content

Latest commit

 

History

History
188 lines (116 loc) · 9.17 KB

README.md

File metadata and controls

188 lines (116 loc) · 9.17 KB

Description

License: MIT Twitter: elbruno GitHub: elbruno

TrafficJamAnalyzer is an advanced tool designed to help monitor and analyze traffic conditions by processing images from CCTV cameras around the roads of Tenerife. Tenerife CCTV Cameras Source

By utilizing artificial intelligence (AI) with Semantic Kernel and OpenAI, the application accurately assesses traffic density and identifies locations with potential traffic jams.

Features

GitHub CodeSpaces: This project is designed to be opened in GitHub Codespaces as an easy way for anyone to deploy the solution entirely in the browser.

This is the Camera Traffic Jam Aplication running:

Camera Dashboard

The Aspire Dashboard to check the running services:

Aspire Dashboard to check the running services

There Azure Resource Group with all the deployed services:

Azure Resource Group with all the deployed services

Architecture diagram

Architecture diagram

Getting Started

The solution is in the root folder, the main solution is TrafficJamAnalyzer.sln.

Deploying

Once you've opened the project in Codespaces, or locally, you can deploy it to Azure.

From a Terminal window, open the folder with the clone of this repo and run the following commands.

  1. Login to Azure:

    azd auth login
  2. Provision and deploy all the resources:

    azd up

    It will prompt you to provide an azd environment name (like "trafficjamdev"), select a subscription from your Azure account, and select a location where OpenAI is available (like "eastus2").

  3. When azd has finished deploying, you'll see the list of resources created in Azure and a set of URIs in the command output.

  4. Visit the webfrontend URI, and you should see the Traffic Jam Camera Analyzer app! 🎉

  5. This is an example of the command output:

Deploy Azure Complete

  1. You can check this video with a 5 minutes overview of the deploy process from codespaces: Deploy Your AI Traffic Jam Analyzer to Azure in Minutes! 🚦🚀.

GitHub CodeSpaces

  1. Create a new Codespace using the Code button at the top of the repository.

create Codespace

  1. The Codespace creation process can take a couple of minutes.

  2. Once the Codespace is loaded, it should have all the necessary requirements to deploy the solution.

Run Locally

To run the project locally, you'll need to make sure the following tools are installed:

Run the solution

Follow these steps to run the project, locally or in CodeSpaces:

  • Navigate to the Aspire Host folder project using the command:
cd ./TrafficJamAnalyzer.AppHost/
  • Run the project:
dotnet run
  • You can expect an output similar to this one:

Run solution console output

Local development using an existing gpt-4o model

In order to use an existing gpt-4o model, you need to define the specific connection string in the AIApiService project.

Add a user secret with the configuration:

{
  "ConnectionStrings:openaiTraffic": "Endpoint=https://<endpoint>.openai.azure.com/;Key=<modelkey>;"
}

Otherwise, set openAiClientName to openai, in the program.cs.

var openAiClientName = "openai";
builder.AddAzureOpenAIClient(openAiClientName);

Guidance

Costs

For Azure OpenAI Services, pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. The majority of the Azure resources used in this infrastructure are on usage-based pricing tiers. However, Azure Container Registry has a fixed cost per registry per day.

You can try the Azure pricing calculator for the resources:

  • Azure OpenAI Service: S0 tier, gpt-4o model. Pricing is based on token count. Pricing
  • Azure Container App: Consumption tier with 0.5 CPU, 1GiB memory/storage. Pricing is based on resource allocation, and each month allows for a certain amount of free usage. Pricing
  • Azure Container Registry: Basic tier. Pricing
  • Log analytics: Pay-as-you-go tier. Costs based on data ingested. Pricing

⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running azd down.

Security Guidelines

Samples in this templates uses Azure OpenAI Services with ApiKey and Managed Identity for authenticating to the Azure OpenAI service.

The Main Sample uses Managed Identity](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) for authenticating to the Azure OpenAI service.

Additionally, we have added a GitHub Action that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure continued best practices in your own repository, we recommend that anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled.

You may want to consider additional security measures, such as:

Resources

Video Recordings