This project provides an AI-powered assistant for Korean Personal Color Analysis (PCA). It analyzes an image of a person using Google's Gemini 1.5 Flash model, determines their most suitable PCA seasonal palette (Spring, Summer, Autumn, Winter, with subtypes), and generates a visual color palette based on the recommendations.
- Detailed Image Analysis: Utilizes Gemini 1.5 Flash to extract comprehensive visual details from an input image, including skin tone, undertone, facial features, hair, clothing, and background.
- Korean PCA Determination: Based on the detailed analysis, the AI model recommends the most suitable Korean PCA seasonal palette.
- Specific Color Recommendations: Provides concrete color suggestions for makeup, clothing, and accessories relevant to the determined palette.
- Visual Color Palette Generation: Automatically creates a
.pngimage showcasing the recommended colors, saved locally. - LangChain & LangGraph Integration: Leverages LangChain for model interaction and LangGraph for orchestrating the multi-step PCA workflow.
- Interactive CLI: A simple command-line interface for easy interaction.
The application uses a multi-step workflow orchestrated by langgraph:
- User Input: The user provides a command
analyze <image_path>. - Image Loading: The
load_image_as_bytesfunction reads the specified image file and converts it into a byte stream suitable for API submission. - Detailed Image Analysis (
analyze_image_detailed):- The
ChatGoogleGenerativeAImodel (Gemini 1.5 Flash) receives the image bytes and a prompt asking for a detailed analysis of the person and their features, including skin tone, hair, clothing, etc. - The model returns the analysis in a structured JSON format.
- The
- PCA Prompt Generation (
generate_pca_prompt):- The raw analysis content is parsed.
- A specific prompt tailored for Korean Personal Color Analysis is constructed, incorporating all relevant details from the image analysis.
- PCA Result Generation (
generate_pca_result):- The
ChatGoogleGenerativeAImodel receives the PCA-specific prompt. - It processes the prompt and generates a PCA report, including the recommended palette, an explanation, and a list of specific color names, all in JSON format.
- The
- Color Palette Image Generation (
generate_color_palette_image):- The list of recommended color names is extracted from the PCA result.
- Using the
Pillow(PIL) library, a visual representation of these colors is created as acolor_palette.pngimage, with each color represented by a swatch. - Note: The current implementation has a predefined
color_mapto convert color names to RGB values. For colors not in this map, a default grey is used. You might need to expand this map for more diverse recommendations.
- Response: The final PCA report (text) and the path to the generated color palette image are displayed to the user in the console.
- Python 3.9+
You need to set your GOOGLE_API_KEY as an environment variable.
- Obtain API Key: Get your Google API Key from Google AI Studio or Google Cloud.
- Create
.envfile: In the root directory of your project, create a file named.envand add your API key:GOOGLE_API_KEY="your_google_api_key_here"
-
Clone the repository (if you haven't already).
-
Navigate to the project directory.
-
Install the required Python packages:
pip install langchain==0.3.0 langgraph==0.4.8 langchain-google-genai==2.1.5 pillow==11.2.1 python-dotenv==1.0.1 pydantic==2.9.2 typing-extensions==4.12.2
(Or, if you create a
requirements.txtfile from the above list, usepip install -r requirements.txt)
-
Ensure you have followed the
Setupinstructions and your.envfile is correctly configured. -
Run the Python script from your terminal:
python your_script_name.py
(Replace
your_script_name.pywith the actual name of your Python file, e.g.,pca_analyzer.py) -
The program will prompt you to enter a command. To perform PCA, use the format:
Enter 'analyze <image_path>' or 'quit' to exit: analyze /path/to/your/image.jpgReplace
/path/to/your/image.jpgwith the actual path to an image file on your system (e.g.,images/my_profile.png). -
The assistant will process the image and print the PCA report in the console. A
color_palette.pngfile will also be generated in the same directory where you run the script. -
To exit the program, type
quitorexit.
