Skip to main content

Omniinfer SDK for Python

Project description

Omniinfer Python SDK

Thanks to the initial contribution of @shanginn, we have made the decision to create this SDK.

this SDK is based on the official API documentation

join our discord server for help

Installation

pip install omniinfer-client

Quick Start

Get api key refer to https://docs.omniinfer.io/get-started

import os
from omniinfer_client import OmniClient, Txt2ImgRequest, Samplers, ModelType, save_image

client = OmniClient(os.getenv('OMNI_API_KEY'))

req = Txt2ImgRequest(
    model_name='sd_xl_base_1.0.safetensors',
    prompt='a dog flying in the sky',
    batch_size=1,
    cfg_scale=7.5,
    height=1024,
    width=1024,
    sampler_name=Samplers.EULER_A,
)
save_image(client.sync_txt2img(req).data.imgs_bytes[0], 'output.png')

Examples

txt2img_with_lora.py

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
from omniinfer_client import OmniClient, Txt2ImgRequest, Samplers, ProgressResponseStatusCode, ModelType, add_lora_to_prompt, save_image


client = OmniClient(os.getenv('OMNI_API_KEY'))
models = client.models()

# Anything V5/Ink, https://civitai.com/models/9409/or-anything-v5ink
checkpoint_model = models.filter_by_type(ModelType.CHECKPOINT).get_by_civitai_version_id(90854)

# Detail Tweaker LoRA, https://civitai.com/models/58390/detail-tweaker-lora-lora
lora_model = models.filter_by_type(ModelType.LORA).get_by_civitai_version_id(62833)

prompt = add_lora_to_prompt('a dog flying in the sky', lora_model.sd_name, "0.8")

res = client.sync_txt2img(Txt2ImgRequest(
    prompt=prompt,
    batch_size=1,
    cfg_scale=7.5,
    sampler_name=Samplers.EULER_A,
    model_name=checkpoint_model.sd_name,
    seed=103304,
))

if res.data.status != ProgressResponseStatusCode.SUCCESSFUL:
    raise Exception('Failed to generate image with error: ' +
                    res.data.failed_reason)
save_image(res.data.imgs_bytes[0], "test.png")

Model Search

model_search.py

from omniinfer_client import OmniClient, ModelType

client = OmniClient(os.getenv('OMNI_API_KEY'))

# filter by model type
print("lora count", len(client.models().filter_by_type(ModelType.LORA)))
print("checkpoint count", len(client.models().filter_by_type(ModelType.CHECKPOINT)))
print("textinversion count", len(
    client.models().filter_by_type(ModelType.TEXT_INVERSION)))
print("vae count", len(client.models().filter_by_type(ModelType.VAE)))
print("controlnet count", len(client.models().filter_by_type(ModelType.CONTROLNET)))


# filter by civitai tags
client.models().filter_by_civi_tags('anime')

# filter by nsfw
client.models().filter_by_nsfw(False)  # or True

# sort by civitai download
client.models().sort_by_civitai_download()

# chain filters
client.models().\
    filter_by_type(ModelType.CHECKPOINT).\
    filter_by_nsfw(False).\
    filter_by_civitai_tags('anime')

ControlNet QRCode

controlnet_qrcode.py

import os

from omniinfer_client import *

# get your api key refer to https://docs.omniinfer.io/get-started/
client = OmniClient(os.getenv('OMNI_API_KEY'))

controlnet_model = client.models().filter_by_type(ModelType.CONTROLNET).get_by_name("control_v1p_sd15_qrcode_monster_v2")
if controlnet_model is None:
    raise Exception("controlnet model not found")

req = Txt2ImgRequest(
    prompt="a beautify butterfly in the colorful flowers, best quality, best details, masterpiece",
    sampler_name=Samplers.DPMPP_M_KARRAS,
    width=512,
    height=512,
    steps=30,
    controlnet_units=[
        ControlnetUnit(
            input_image=read_image_to_base64(os.path.join(os.path.abspath(os.path.dirname(__file__)), "fixtures/qrcode.png")),
            control_mode=ControlNetMode.BALANCED,
            model=controlnet_model.sd_name,
            module=ControlNetPreprocessor.NULL,
            resize_mode=ControlNetResizeMode.JUST_RESIZE,
            weight=2.0,
        )
    ]
)

res = client.sync_txt2img(req)
if res.data.status != ProgressResponseStatusCode.SUCCESSFUL:
    raise Exception('Failed to generate image with error: ' +
                    res.data.failed_reason)

save_image(res.data.imgs_bytes[0], "qrcode-art.png")

Txt2Img with Hires.Fix

txt2img_with_hiresfix.py

import os

from omniinfer_client import *

client = OmniClient(os.getenv('OMNI_API_KEY'))
req = Txt2ImgRequest(
    model_name='dreamshaper_8_93211.safetensors',
    prompt='a dog flying in the sky',
    width=512,
    height=512,
    batch_size=1,
    cfg_scale=7.5,
    sampler_name=Samplers.EULER_A,
    enable_hr=True,
    hr_scale=2.0
)

res = client.sync_txt2img(req)
if res.data.status != ProgressResponseStatusCode.SUCCESSFUL:
    raise Exception('Failed to generate image with error: ' +
                    res.data.failed_reason)

save_image(res.data.imgs_bytes[0], "txt2img-hiresfix-1024.png")

Testing

export OMNI_API_KEY=<YOUR_API_KEY>

python -m pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omniinfer_client-0.3.3.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omniinfer_client-0.3.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file omniinfer_client-0.3.3.tar.gz.

File metadata

  • Download URL: omniinfer_client-0.3.3.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for omniinfer_client-0.3.3.tar.gz
Algorithm Hash digest
SHA256 2f1895602e35b4acd9c9a198ec63198cb41a350e609659e4a6c2c45aa7a354b3
MD5 0da23886ce62ffa911b6ff0cd8986d49
BLAKE2b-256 f790554340fa5013fccf28696dc93c97d7930fdb0c9812110c0a9f68580054c7

See more details on using hashes here.

File details

Details for the file omniinfer_client-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for omniinfer_client-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 39e1003f13caec9f408e1bb0fe5ef2993a57b121f88b287caf1ff9ce53aa546f
MD5 0442add27462ad81d7599c6a4a25cd73
BLAKE2b-256 2d529a3d37146bd4fabbe9e6a07a3d75728ec47bc8c78e344ace7576b55fd7a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page