coconut-ai

Coconut AI


Keywords
llama2, python-library, stable-diffusion
License
MIT
Install
pip install coconut-ai==1.0.0

Documentation

coconut-ai

About

Coconut AI is a Python library that allows you to use AUTOMATIC1111/Stable Diffusion Web API and LLama 2, to generate images from text, images to images or text to text.

The library is available on PyPy: https://pypi.org/project/coconut-ai/.

Getting Started

Prerequisites

Installation

pipenv install coconut-ai

Stable Diffusion Guide

For a complete example, see the coconut-ai-example repository.

Install Stable Diffusion Web UI

AUTOMATIC1111/Stable Diffusion Web UI installation guide

# Clone the AUTOMATIC1111/Stable Diffusion Web UI repository
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

# Go to AUTOMATIC1111/Stable Diffusion Web UI source code
cd stable-diffusion-webui

# For Windows users, run the following command for starting the server
./webui-user.bat --api --nowebui

# For Linux/MacOS users, run the following command for starting the server
./webui.sh --api --nowebui

Stable Diffusion Usage

Note: Before using the library, you must start the Stable Diffusion Web UI server.

# Go to your Python project/source code
cd ../python-project
pipenv install coconut-ai

Create a file named main.py with the following content (minimal example):

import os

import coconut_ai

if __name__ == '__main__':
    print("Coconut AI")
    output_path = os.path.abspath("output.png")
    os.makedirs(os.path.dirname(output_path), exist_ok=True)
    coconut_ai.text_to_image({
        "input_text": "Coconut",
        "output_path": output_path,
        "steps": 5
    })

Run the script:

pipenv run python main.py

LLama 2 Guide

Install LLama 2 Model

For a complete example, see the coconut-ai-example repository.

Download the model llama-2-7b.Q5_K_M.gguf manually.

All available models can be found on the Hugging Face website.

LLama 2 Usage

# Go to your Python project/source code
cd ../python-project
pipenv install coconut-ai

Create a file named main.py with the following content (minimal example):

import os

import coconut_ai

if __name__ == '__main__':
    print("Coconut AI")
    # Replace with the model path for the llama-2-7b.Q5_K_M.gguf model downloaded manually
    model_path = os.path.abspath("data/llama-2-7b.Q5_K_M.gguf")
    print(coconut_ai.text_to_text({
        'input_text': "Generate a list of 5 funny dog names.",
        'max_tokens': 1000,
        'model_path': model_path
    }))

Run the script:

pipenv run python main.py

💡 Contributing

Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.

The steps to contribute can be found in the CONTRIBUTING.md file.

📄 License

MIT