### Environment Configuration (Bash) Source: https://context7.com/upstash/stylegenie/llms.txt Sets up the application environment by defining necessary API keys and database credentials in a `.env` file. Includes instructions for installing dependencies using `pip` and running the application locally with `uvicorn`. ```Bash # .env file configuration UPSTASH_URL="https://example-vector.upstash.io" UPSTASH_TOKEN="your-upstash-token-here" OPENAI_KEY="sk-your-openai-api-key" # Install dependencies pip install -r requirements.txt # Run locally uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` -------------------------------- ### Generate Product Image using FastAPI and DALL-E Source: https://context7.com/upstash/stylegenie/llms.txt This snippet demonstrates how to use the `/image` API endpoint to generate fashion product images with OpenAI's DALL-E. It shows examples of generating images with and without a fashion model, and includes an option for iterative refinement of the product description. The endpoint expects a JSON payload and returns an image URL upon success. ```python import requests # Generate a product image without model response = requests.post( "https://your-app.fly.dev/image", json={ "gender": "woman", "prompt": "Blue floral summer dress with flowing sleeves", "with_model": False, "revise_list": [] } ) if response.status_code == 200: result = response.json() image_url = result["image_url"] print(f"Generated image: {image_url}") else: print(f"Error: {response.json()['detail']}") # Generate with iterative refinement response = requests.post( "https://your-app.fly.dev/image", json={ "gender": "man", "prompt": "Formal black suit", "with_model": True, "revise_list": ["make it navy blue", "add a subtle pinstripe pattern"] } ) # Expected response: # { # "image_url": "https://oaidalleapiprodscus.blob.core.windows.net/..." # } ``` -------------------------------- ### Test StyleGenie Image Generation Endpoint Source: https://context7.com/upstash/stylegenie/llms.txt An example using curl to send a POST request to the StyleGenie application's image generation endpoint. It includes setting the Content-Type header and providing a JSON payload with image generation parameters. ```bash curl -X POST "https://your-app.fly.dev/image" \ -H "Content-Type: application/json" \ -d '{ "gender": "woman", "prompt": "Elegant red evening gown", "with_model": false }' ``` -------------------------------- ### Deploy StyleGenie to Fly.io Source: https://context7.com/upstash/stylegenie/llms.txt Commands to launch a new application on Fly.io, set essential environment variables for Upstash and OpenAI, and deploy the application. ```bash flyctl launch flyctl secrets set UPSTASH_URL="https://your-db.upstash.io" flyctl secrets set UPSTASH_TOKEN="your-token" flyctl secrets set OPENAI_KEY="sk-your-key" flyctl deploy ``` -------------------------------- ### Merge Prompt History for Query Expansion (Python) Source: https://context7.com/upstash/stylegenie/llms.txt Combines multiple iterative user prompts into a single cohesive prompt suitable for image generation models like DALL-E. Requires the `openai` and `chatgpt` libraries. The output is a refined string describing the product vision. ```Python from openai import OpenAI import chatgpt client = OpenAI(api_key="sk-your-key") # User's iterative refinement process prompt_history = [ "Blue dress", "make the dress longer", "make the dress black", "add lace sleeves" ] # Merge all prompts into final description final_prompt = chatgpt.merge_prompts(client, prompt_history) print(final_prompt) # Output: "Elegant black long dress with lace sleeves" # Use in API workflow revise_list = ["Red sweater", "make it oversized", "add cable knit pattern"] merged = chatgpt.merge_prompts(client, revise_list) # Generate image with merged prompt image_url = image_controller.generate_product_image( client, f"a product photo of a cloth, featuring clean lines and styling. Description: {merged} for woman. Plain white background. Single product." ) ``` -------------------------------- ### Search Similar Products by Image using FastAPI and CLIP Source: https://context7.com/upstash/stylegenie/llms.txt This code demonstrates how to use the `/query` API endpoint for visual similarity search. It shows how to query using a provided image URL or by uploading a local image file. The endpoint returns a list of similar products, including their URLs, brand, category, similarity score, and image URL. Optional gender filtering is also supported. ```python import requests # Query using generated image URL response = requests.post( "https://your-app.fly.dev/query", data={"gender": "woman", "image_url": "https://example.com/dress.jpg"} ) if response.status_code == 200: results = response.json() for item in results["result"]: print(f"Product: {item['metadata']['url']}") print(f"Brand: {item['metadata']['brand']}") print(f"Category: {item['metadata']['category']}") print(f"Similarity Score: {item['score']}") print(f"Image: {item['metadata']['image']}\n") # Query using file upload with open("my_outfit.jpg", "rb") as f: response = requests.post( "https://your-app.fly.dev/query", data={"gender": "man"}, files={"file": ("outfit.jpg", f, "image/jpeg")} ) # Expected response structure: # { # "result": [ # { # "id": "https://store.com/product-123", # "score": 0.95, # "metadata": { # "url": "https://store.com/product-123", # "image": "https://cdn.store.com/image.jpg", # "brand": "Nike", # "category": "sneakers", # "gender": "man" # } # } # ] # } ``` -------------------------------- ### POST /image - Generate Product Image Source: https://context7.com/upstash/stylegenie/llms.txt Generates fashion product images using DALL-E based on text descriptions. It supports generating images with or without fashion models and allows for iterative refinement of the prompt. ```APIDOC ## POST /image ### Description Generates fashion product images using DALL-E based on text descriptions. This endpoint can create images of products alone or on a fashion model, with options for iterative prompt refinement. ### Method POST ### Endpoint /image #### Request Body - **gender** (string) - Required - The gender the product is intended for (e.g., 'woman', 'man'). - **prompt** (string) - Required - A natural language description of the fashion product to generate. - **with_model** (boolean) - Optional - If true, generates the product on a fashion model; otherwise, generates the product alone. Defaults to false. - **revise_list** (array[string]) - Optional - A list of text prompts to iteratively refine the generated image. ### Request Example ```json { "gender": "woman", "prompt": "Blue floral summer dress with flowing sleeves", "with_model": false, "revise_list": [] } ``` ### Response #### Success Response (200) - **image_url** (string) - The URL of the generated fashion product image. #### Response Example ```json { "image_url": "https://oaidalleapiprodscus.blob.core.windows.net/..." } ``` ``` -------------------------------- ### Web Crawler for Product Indexing (Python) Source: https://context7.com/upstash/stylegenie/llms.txt Scrapes fashion retail websites using Selenium to extract product images and links. It generates CLIP embeddings for products and upserts them to an Upstash Vector database with metadata. Requires `transformers`, `crawler.crawler`, and `upstash_vector` libraries. ```Python from transformers import CLIPModel from crawler.crawler import Crawler import upstash_vector as uv # Initialize vector database index = uv.Index(url="https://your-db.upstash.io", token="your-token") # Configure crawler for a specific retailer man_urls = { "sneakers": "https://store.com/mens/sneakers", "jackets": "https://store.com/mens/jackets" } woman_urls = { "dresses": "https://store.com/womens/dresses", "shoes": "https://store.com/womens/shoes" } crawler = Crawler( index=index, man_urls=man_urls, woman_urls=woman_urls, brand="Nike", product_list_type="CLASS_NAME", product_list_locator="product-card", product_link_type="TAG_NAME", product_link_locator="a", product_image_type="TAG_NAME", product_image_locator="img", product_image_src="src", cookie_button_type="ID", cookie_button_locator="accept-cookies" ) # Run crawler crawler.setup_driver() crawler.crawl() crawler.close_driver() # Each product is stored as: # { # "id": "product_url", # "vector": [512-dim CLIP embedding], # "metadata": { # "url": "https://store.com/product", # "image": "https://cdn.store.com/image.jpg", # "brand": "Nike", # "category": "sneakers", # "gender": "man", # "created_at": 1698765432, # "updated_at": 1698765432 # } # } ``` -------------------------------- ### Generate Product Image using OpenAI CLIP Library Source: https://context7.com/upstash/stylegenie/llms.txt This Python function `generate_product_image` utilizes the OpenAI client to create fashion product images via DALL-E 3. It supports generating both standalone product photos and images of fashion models wearing the products. The function takes the OpenAI client object and a detailed prompt as input, returning the URL of the generated image. ```python from openai import OpenAI import image_controller client = OpenAI(api_key="sk-your-key") # Generate standalone product image product_prompt = "a product photo of a cloth, featuring clean lines and styling. Description: Red leather jacket with silver zippers for woman. Plain white background. Single product." image_url = image_controller.generate_product_image(client, product_prompt) print(f"Product image: {image_url}") # Generate with fashion model model_prompt = "Elegant evening gown with sequins, product for gender woman, fashion model wearing it and showing full body of model with a white background." image_url = image_controller.generate_product_image(client, model_prompt) print(f"Model image: {image_url}") # The function returns the URL directly: # "https://oaidalleapiprodscus.blob.core.windows.net/dalle/image.png" ``` -------------------------------- ### Crawler Integration Source: https://context7.com/upstash/stylegenie/llms.txt Information on using the Crawler class to index product catalogs for the StyleGenie system. ```APIDOC ## Crawler Class ### Description The `Crawler` class is designed to index product catalogs from e-commerce platforms, enabling them to be searched and visualized through StyleGenie. ### Usage Instantiate the `Crawler` class and use its methods to add products to the index. This typically involves providing product details such as name, description, image URL, and price. ### Example (Conceptual) ```python from stylegenie import Crawler # Assuming UPSTASH_URL and UPSTASH_TOKEN are set as environment variables crawler = Crawler() product_data = { "name": "Summer Floral Dress", "description": "A light and airy dress with a floral print, perfect for summer.", "price": 75.50, "image_url": "https://example.com/images/floral_dress.jpg", "link": "https://example.com/products/summer-floral-dress", "gender": "woman" } crawler.add_product(product_data) # To index a batch of products: crawler.add_products([product_data_1, product_data_2]) ``` ### Notes - Ensure Upstash credentials are correctly configured. - The `gender` field is optional but recommended for more accurate filtering in searches. ``` -------------------------------- ### POST /query - Search Similar Products Source: https://context7.com/upstash/stylegenie/llms.txt Performs a visual similarity search across indexed fashion products. Users can provide an image URL or upload an image file, optionally filtering results by gender. ```APIDOC ## POST /query ### Description Performs a visual similarity search to find products similar to a given image. The search can be initiated using an image URL or by uploading an image file. Results can be optionally filtered by gender. ### Method POST ### Endpoint /query #### Query Parameters - **gender** (string) - Optional - Filters search results to a specific gender (e.g., 'woman', 'man'). #### Request Body (Either `image_url` or `file` should be provided) - **image_url** (string) - Required if `file` is not provided - The URL of the image to perform the similarity search on. - **file** (file) - Required if `image_url` is not provided - The image file to perform the similarity search on. ### Request Example (URL) ```json { "gender": "woman", "image_url": "https://example.com/dress.jpg" } ``` ### Request Example (File Upload) (This is typically sent as multipart/form-data) ``` --boundary Content-Disposition: form-data; name="gender" man --boundary Content-Disposition: form-data; name="file"; filename="outfit.jpg" Content-Type: image/jpeg [binary image data] --boundary-- ``` ### Response #### Success Response (200) - **result** (array) - A list of the most similar products found. - **id** (string) - Unique identifier for the product. - **score** (float) - The similarity score between the query image and the product image. - **metadata** (object) - Additional details about the product. - **url** (string) - The URL of the product. - **image** (string) - The URL of the product's image. - **brand** (string) - The brand of the product. - **category** (string) - The category of the product. - **gender** (string) - The gender associated with the product. #### Response Example ```json { "result": [ { "id": "https://store.com/product-123", "score": 0.95, "metadata": { "url": "https://store.com/product-123", "image": "https://cdn.store.com/image.jpg", "brand": "Nike", "category": "sneakers", "gender": "man" } } ] } ``` ``` -------------------------------- ### Validate Fashion Prompts with GPT (Python) Source: https://context7.com/upstash/stylegenie/llms.txt Validates if user input is a legitimate fashion product description using GPT-4. Requires the `openai` library and `chatgpt` module. Returns 'True' for valid prompts and 'False' for invalid ones. Can be used to enforce API input constraints. ```Python from openai import OpenAI import chatgpt client = OpenAI(api_key="sk-your-key") # Valid fashion prompts valid_prompt = "Thick woolen sweater in burgundy for a cozy winter" result = chatgpt.is_valid_prompt(client, valid_prompt) print(result) # "True" valid_prompt2 = "Brown cargo pants" result = chatgpt.is_valid_prompt(client, valid_prompt2) print(result) # "True" # Invalid prompts invalid_prompt = "Draw a picture of a cat" result = chatgpt.is_valid_prompt(client, invalid_prompt) print(result) # "False" # Usage in API endpoint if chatgpt.is_valid_prompt(client, user_input) == "False": raise HTTPException(status_code=400, detail="Prompt is not valid.") ``` -------------------------------- ### Transform Image to CLIP Embedding (Python) Source: https://context7.com/upstash/stylegenie/llms.txt Converts images from URLs or uploaded files into 512-dimensional CLIP embeddings. Requires the `transformers` library for the CLIP model and `image_controller` for transformation. Outputs a NumPy array of shape (512,) with float32 values. ```Python from transformers import CLIPModel import image_controller model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") # Transform from URL image_url = "https://example.com/product.jpg" embedding = image_controller.transform_image(model, image_url, isFile=False) print(f"Embedding shape: {embedding.shape}") # (512,) print(f"Embedding type: {embedding.dtype}") # float32 # Transform from uploaded file (FastAPI context) from fastapi import UploadFile async def process_upload(file: UploadFile): embedding = image_controller.transform_image(model, file, isFile=True) # Use embedding for vector search results = index.query(vector=embedding, top_k=6, include_metadata=True) return results ``` -------------------------------- ### Product Search API Source: https://context7.com/upstash/stylegenie/llms.txt Searches for products based on a query, optionally filtering by gender and using vector similarity search. ```APIDOC ## POST /search ### Description Searches for products that semantically match a given query, with optional gender filtering. ### Method POST ### Endpoint /search ### Parameters #### Query Parameters - **query** (string) - Required - The search query (e.g., "blue dress", "summer outfit"). - **gender** (string) - Optional - Filter search results by gender (e.g., "woman", "man"). #### Request Body ```json { "query": "Elegant red evening gown", "gender": "woman" } ``` ### Request Example ```json { "query": "Elegant red evening gown", "gender": "woman" } ``` ### Response #### Success Response (200) - **products** (array) - A list of matching products. - **product_id** (string) - The unique identifier for the product. - **name** (string) - The name of the product. - **description** (string) - A description of the product. - **price** (number) - The price of the product. - **image_url** (string) - The URL of the product image. - **link** (string) - A link to the product page. #### Response Example ```json { "products": [ { "product_id": "prod123", "name": "Scarlet Maxi Dress", "description": "A stunning floor-length red gown perfect for evening events.", "price": 199.99, "image_url": "https://example.com/images/scarlet_dress.jpg", "link": "https://example.com/products/scarlet-maxi-dress" } ] } ``` ``` -------------------------------- ### Send POST Request to /image Endpoint Source: https://github.com/upstash/stylegenie/blob/master/README.md This snippet demonstrates how to send a POST request to the '/image' endpoint for generating fashion product images. It requires a JSON body with product details and optionally supports revision lists and model inclusion. The request is made to a deployed application on Fly.io. ```json { "gender": "woman", "product_description": "Blue dress", "revise_list": ["make the dress longer", "make the dress black"], "with_model": false } ``` -------------------------------- ### Image Generation API Source: https://context7.com/upstash/stylegenie/llms.txt Generates an image based on a textual description of an outfit. Supports filtering by gender and model usage. ```APIDOC ## POST /image ### Description Generates an AI image based on a textual description of an outfit. Allows specifying gender and whether to use a model. ### Method POST ### Endpoint /image ### Parameters #### Query Parameters - **gender** (string) - Optional - The gender to generate the image for (e.g., "woman", "man"). - **prompt** (string) - Required - A textual description of the desired outfit. - **with_model** (boolean) - Optional - Whether to use a specific model for generation. Defaults to false. #### Request Body ```json { "gender": "woman", "prompt": "Elegant red evening gown", "with_model": false } ``` ### Request Example ```json { "gender": "woman", "prompt": "Elegant red evening gown", "with_model": false } ``` ### Response #### Success Response (200) - **image_url** (string) - The URL of the generated image. #### Response Example ```json { "image_url": "https://your-app.fly.dev/images/generated_image.png" } ``` ``` -------------------------------- ### Image Generation Response Source: https://github.com/upstash/stylegenie/blob/master/README.md This snippet shows a sample JSON response from the '/image' endpoint after a successful image generation request. It primarily contains the URL of the generated image, which can then be used for further actions like querying indexed images. ```json { "image_url": "https://oaidalleapiprodscus.blob.core.windows.net/dalle/0d3e3e3e-3e3e-3e3e-3e3e-3e3e3e3e3e3e" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.