capradeepgujaran's picture
Update README.md
8fc888c verified
|
raw
history blame
4.01 kB
metadata
license: mit
title: Construction Image Analyzer with Chat
sdk: gradio
emoji: 🏢
colorFrom: blue
colorTo: green
short_description: AI Powered Snaging Tool
sdk_version: 5.1.0

Construction Image Analyzer with Chat

Overview

This project is a web application built using Gradio that allows users to upload construction site images and receive automated analysis and suggestions for improvement. The application utilizes the Groq AI platform to process and interpret the images, providing detailed insights and actionable steps.

Features

  1. Image Upload: Users can upload construction site images directly through the web interface.
  2. Automated Analysis: The application uses advanced machine learning models to identify potential issues within the images, categorize them, and provide descriptions along with step-by-step solutions.
  3. Interactive Chat: Users can ask follow-up questions based on the initial analysis, and receive real-time responses from the AI assistant.
  4. Logging and Error Handling: Comprehensive logging and error handling ensure robust operation and easy troubleshooting.

Installation

To run this application, you need to have Python installed on your system. Follow these steps to install the required dependencies:

pip install gradio pillow base64 io json groq logging

Additionally, you will need to obtain a GROQ_API_KEY from the Groq platform and set it as an environment variable:

export GROQ_API_KEY=your_groq_api_key_here

Usage

  1. Launch the Application: Run the main script to start the Gradio interface:

    python your_script_name.py
    
  2. Access the Interface: Open a web browser and navigate to http://localhost:7860. You should see the Construction Image Analyzer interface.

  3. Upload an Image:

    • Click on the "Upload Construction Image" button.
    • Select or drag-and-drop an image file from your local machine.
  4. Receive Analysis:

    • Once the image is uploaded, click the "Analyze Image" button.
    • The application will display the analyzed results, including identified issues, categories, and suggested steps.
  5. Interact via Chat:

    • Use the text box below the chatbot to ask additional questions related to the image analysis.
    • The AI assistant will respond in real-time with relevant information.

Code Explanation

Imports

The code imports necessary libraries and modules, including Gradio for the web interface, Pillow for image processing, and Groq for AI inference.

Logging Setup

Logging is configured to capture debug and error messages, which helps in monitoring and debugging the application.

Environment Variable Check

The script checks if the GROQ_API_KEY is set in the environment variables. If not, it logs an error and raises a ValueError.

Image Encoding Function

The encode_image function converts an image (either a file path or a PIL Image object) to a Base64-encoded string.

Image Analysis Function

The analyze_construction_image function handles the image analysis process. It encodes the image, sends it to the Groq API for analysis, and processes the response to extract and format the results.

Chat Function

The chat_about_image function enables interactive chatting with the AI assistant. It constructs a conversation history and makes API calls to receive responses.

Gradio Interface

The Gradio interface is created with components for uploading images, displaying analysis results, and interacting via chat. Events are linked to the corresponding functions to handle user actions.

Main Execution

The script launches the Gradio interface when executed directly.

Conclusion

This project provides a powerful tool for construction site managers and inspectors to quickly assess and improve the quality of construction sites. By leveraging AI technology, it simplifies the inspection process and ensures timely resolution of potential issues.