Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 2.82 KB

File metadata and controls

63 lines (47 loc) · 2.82 KB

Pet Portrait Example - TheDogAPI

This repository provides a concrete example of how to use TheDogAPI portrait-related endpoints to create a pet profile, upload source images, perform physical analyses, and generate artistic portraits.

🚀 Quick Start

1. Prerequisites

2. Setup

  1. Clone this repository.
  2. Install dependencies:
    pip install requests python-dotenv
  3. Create a .env file in the python/ directory:
    API_KEY=your_api_key_here
    API_URL=https://api.thedogapi.com/v1

3. Run the Example

cd python
python3 create-portraits.py

🛠 API Endpoints Used

The follow table summarizes the portrait-related endpoints demonstrated in this repo:

Operation Method URL Description
Create Pet POST /v1/pets Creates a pet record and uploads multiple images in one multipart request.
Analyze POST /v1/pets/{id}/{module} Runs physical analyses (e.g. estimated-age, body-condition-score).
Request Portrait POST /v1/pets/{id}/portrait Triggers the generation of an artistic portrait. Supports styles like studio, pencil_sketch, professional, and oil_painting.
Check Status GET /v1/pets/{id}/portrait/{pid} (Optional) Check the status of a long-running generation.
Get Styles GET /v1/pets/portrait-styles Lists available artistic styles.
Upload Image POST /v1/images/upload-sync Alternative way to upload a single image synchronously.

📂 Project Structure

  • create-portraits.py: The main script that orchestrates the entire workflow.
  • output-data/: Contains subfolders for each pet with raw JSON analysis responses.
  • output-portraits/: Contains subfolders for each pet with generated portrait images.
  • ../test-images/dogs/: Source directory. Each subfolder here is treated as a separate pet.

💡 Workflow Explained

  1. Automatic Discovery: The script scans ../test-images/dogs/ for subfolders. Each folder name is used as the pet_name and sub_id.
  2. Bulk Upload: For each folder, it collects all valid image files and uploads them in a single multipart/form-data request when creating the pet profile.
  3. Organized Outputs: Analysis results and portraits are saved in dedicated subfolders within output-data/ and output-portraits/, matching the source folder name.
  4. Multi-Style Portraits: It generates four artistic styles (studio, pencil_sketch, professional, oil_painting) for every discovered pet.

📧 Support

If you are having issues with specific endpoints, ensure your x-api-key header is correctly set and that you are using the correct PET_ID returned from the /pets endpoint.