Vi-Tons Imagen is an AI-powered virtual try-on application that allows users to generate realistic human models or edit reference images with customized clothing and accessories. The application leverages Imagen 3 model and integrates with Google Cloud Storage for seamless image processing and storage.
- Generate Human Models: Create realistic human models based on user-provided attributes like gender, ethnicity, age, body type, and clothing preferences.
- Reference Image Editing: Upload a reference image to apply custom clothing and accessories.
- Dynamic Prompt Refinement: Refine user inputs into AI-ready prompts for generating or editing images.
- Google Cloud Storage Integration: Store and retrieve generated images securely using Google Cloud Storage.
- Image Download: Serve generated images directly for download.
The repository is organized as follows:
vi-tons_imagen/
├── app.py # Main FastAPI application file
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── app.yaml # Configuration file for Google App Engine deployment
├── .env # Environment variables (not included in the repo)
├── prompts/ # Directory for prompt templates
│ └── prompt_templates.py # Predefined templates for AI prompts
├── utils/ # Utility functions
│ ├── helper_functions.py # Helper functions for AI model interactions and image processing
│ ├── constants.py # Constants and configuration variables
- Python 3.8 or higher
- Google Cloud account with access to Google Cloud Storage
- Google Cloud SDK installed
- A Google Cloud Storage bucket for storing generated images
-
Clone the repository:
git clone https://github.com/yourusername/vi-tons_imagen.git cd vi-tons_imagen -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.envfile in the root directory and add the following variables:GOOGLE_PROJECT_ID=your-google-project-id GCP_BUCKET_NAME=your-google-cloud-storage-bucket-name -
Authenticate with Google Cloud:
gcloud auth application-default login
-
Start the FastAPI server:
uvicorn app:app --reload
-
Open your browser and navigate to
http://127.0.0.1:8000/docsto access the Swagger UI and test the API endpoints.
Generate a try-on image based on user input or a reference image.
-
Request Parameters:
user_request(Form): JSON string containing user input attributes.reference_image(File, optional): Reference image with a full-body pose.
-
Response:
- If a reference image is provided: Returns the URL of the edited image.
- If no reference image is provided: Returns the URL of the generated human model.
Download a generated image from Google Cloud Storage.
-
Request Parameters:
image_url(Query): The GCS URL of the image to download.
-
Response:
- Returns the image file for download.
curl -X 'POST' \
'http://127.0.0.1:8000/generate_tryon' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'user_request={
"user_input": {
"gender": "male",
"ethnicity": "Indian",
"age": "30",
"body_type": "athletic",
"mood": "confident",
"style": "casual",
"top": {"color": "yellow", "type": "t-shirt"},
"bottom": {"color": "black", "type": "jeans"},
"footwear": {"color": "yellow", "type": "sneakers"},
"accessories": {"colour": black", "type": "watch"}
}
}'curl -X 'POST' \
'http://127.0.0.1:8000/generate_tryon' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'user_request={
"user_input": {
"style": "formal",
"top": {"color": "black", "type": "blazer"},
"bottom": {"color": "black", "type": "trousers"}
}
}' \
-F 'reference_image=@path_to_your_image.jpg'curl -X 'GET' \
'http://127.0.0.1:8000/download_image?image_url=gs://your-bucket-name/path-to-image.jpg' \
-H 'accept: application/json'-
Create an
app.yamlfile in the root directory with the following content:runtime: python39 entrypoint: uvicorn app:app --host 0.0.0.0 --port $PORT env_variables: GOOGLE_PROJECT_ID: your-google-project-id GCP_BUCKET_NAME: your-google-cloud-storage-bucket-name handlers: - url: /.* script: auto
-
Deploy the application:
gcloud app deploy
-
Access the deployed application at the URL provided by Google App Engine.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.