This project implement a generative AI-based solution for classifying customer complaints. The project involves various steps such as transcribing customer audio complaints, generating images, describing and annotating those images, and finally classifying the complaints into appropriate categories.
-
Transcribing Customer Audio Complaint:
- The first step is to convert the customer's audio complaint into text using a speech-to-text model. This involves using the
whisper.pymodule.
- The first step is to convert the customer's audio complaint into text using a speech-to-text model. This involves using the
-
Create Prompt from Transcription:
- Once the audio is transcribed, a prompt is created from the transcription that will be used to generate a visual representation of the complaint.
-
Generate Image Representing the Issue:
- Using the prompt created from the transcription, an image is generated to visually represent the customer complaint. This is managed by the
dalle.pymodule.
- Using the prompt created from the transcription, an image is generated to visually represent the customer complaint. This is managed by the
-
Describe the Generated Image:
- The generated image is then analyzed to provide a description of its contents, using the
vision.pymodule. This helps identify the key elements related to the issue.
- The generated image is then analyzed to provide a description of its contents, using the
-
Annotate the Reported Issue in the Image:
- The key reported issue in the image is highlighted through annotation, which includes identifying specific objects or areas related to the complaint.
-
Classify Complaint into Category/Subcategory Pair:
- Use the generated image description and the catalog metadata to classify the complaint into a category and subcategory. This is handled by the
gpt.pymodule.
- Use the generated image description and the catalog metadata to classify the complaint into a category and subcategory. This is handled by the
customer-complaint-classification/
│
├── main.py # Main orchestrator for the project workflow
├── whisper.py # Module for audio transcription
├── dalle.py # Module for image generation
├── vision.py # Module for image description and annotation
├── gpt.py # Module for complaint classification
├── categories.json # File containing category and subcategory metadata
├── audio/ # Directory for input audio files
├── dev/ # demo code for how to interact with different models and how to use azure openai service
├── imgs/ # Images used in Readme file
└── output/ # Directory for storing intermediate results and log file.
-
whisper.py:- This file contains a function to transcribe audio complaints into text using the Whisper model.
-
dalle.py:- Contains the function
generate_image()to create an image representing the issue.
- Contains the function
-
vision.py:- This file contains a function to describe the generated image and annotate it with the key elements identified.
-
gpt.py:- Contains a function
classify_with_gpt()that takes in an image description and classifies the complaint into an appropriate category/subcategory.
- Contains a function
-
main.py:- Orchestrates the entire workflow, calling each of the modules in sequence.
-
Azure OpenAI Service:
- Deployments for
Whisper,DALL-E, andGPTmodels are necessary. - Obtain API keys and set up the endpoint URL in the Azure portal.
- Deployments for
-
Azure Resource Group:
- Create a resource group in your Azure account for managing related resources (e.g.,
OpenAI services).
- Create a resource group in your Azure account for managing related resources (e.g.,
-
Set up environment variables for secure access to Azure services:
- Create a
.envfile in the root directory of the project. - Add the following environment variables to the
.envfile (for method how to get below information, see How to deploy models on azure:AZURE_OPENAI_API_KEY=your_api_key_here AZURE_OPENAI_ENDPOINT=your_endpoint_url_here WHISPER_DEPLOYMENT=your_whisper_deployment_name WHISPER_VERSION=your_whisper_api_version GPT_DEPLOYMENT=your_gpt_deployment_name GPT_VERSION=your_gpt_api_version DALLE_DEPLOYMENT=your_dalle_deployment_name DALLE_VERSION=your_dalle_api_version
Replace the placeholders with your actual values from the Azure portal. If you use different regions in your models, make sure differentiate the version of the API for each model by name.
- Ensure that the
.envfile is added to your.gitignoreto prevent sensitive information from being committed to version control.
- Create a
- Input:
- Audio files: Supported formats include
MP3andWAVfor transcription.
- Audio files: Supported formats include
- Output (see details for each sample in
outputfolder):- Text files for transcription (
transcription.txt). - PNG images for visual representations (
generated_image.png,annotated_image.png). - Text files for image descriptions and classifications (
image_description.txt,classification.txt). output.log: Log file for tracking the execution of the project.
- Text files for transcription (
- Other files:
categories.json: Contains the category and subcategory metadata for classification.prediction.json: Contains the final classification results in JSON format.labels.json: Contains the labels used for classification, corresponding withaudiofolder.
-
Clone the repository to your local machine:
git clone https://github.com/deepbiolab/customer-complaint-classification.git
-
Navigate into the project folder:
cd customer-complaint-classification -
Ensure
Python 3.12is installed on your system- If not, using
condacreate a virtual environment(recommend)conda create -n complaint_clf python=3.12 conda activate complaint_clf
- If not, using
-
Install dependencies:
pip install -r requirements.txt
python main.pyThe project is a sequential execution of below tasks:
- Run
main.pyto initiate the process. - Transcription via
whisper.pyprocesses audio file inaudiofolder and returns text. - Prompt generation in
main.pyfeeds intodalle.pyfor image creation. - Image analysis and annotation are performed in
vision.py. - Classification is finalized in
gpt.pybased on text and image outputs.
