1.0.27 • Published 2 months ago

picfinder-sdk v1.0.27

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Picfinder Javascript & Typescript SDK

The SDK is used to run image inference with the PicFinder API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.

Request for API access

You can request for api access and get your API key here

Installation

To install and set up the library, run:

$  npm  install  picfinder-sdk

Or if you prefer using Yarn:

$  yarn  add  picfinder-sdk

Request for API access

You can request for api access and get your API key here

Instantiating the SDK

# For  Client (Javascript, React, Vue  etc) Use
const  picfinder  =  new  Picfinder(ENVIRONMENT , API_KEY);

# For  Server (Nodejs) Use
const  picfinder  =  new  PicfinderServer(ENVIRONMENT , API_KEY);
ParameterTypeUse
ENVIRONMENTstring"PRODUCTION", "DEVELOPMENT"
API_KEYstringThe environment api key

API

Request Image

NB: All errors can be catched in the catch block of each request

const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);
const images = await picfinder.requestImages({
	positivePrompt: string;
	imageSize: number;
	modelId: number;
	numberOfImages?: number;
	negativePrompt?: string;
	useCache?: boolean;
	lora?: ILora[];
	controlNet?: IControlNet[];
	imageInitiator?: File | string;
	imageMaskInitiator?: File | string;
	steps?: number;
	onPartialImages?: (images: IImage[], error: IError) =>  void;
})
console.log(images)

return interface IImage {
	imageSrc: string;
	imageUUID: string;
	taskUUID: string;
	bNSFWContent: boolean;
}[]
Parallel Requests (2 or more requests at the same time)
const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);

const [firstImagesRequest, secondImagesRequest] = await Promise.all([
	picfinder.requestImages({
		positivePrompt: string;
		imageSize: number;
		modelId: number;
		numberOfImages?: number;
		negativePrompt?: string;
		useCache?: boolean;
		onPartialImages?: (images: IImage[], error: IError) =>  void;
	}),
	picfinder.requestImages({
		positivePrompt: string;
		imageSize: number;
		modelId: number;
		numberOfImages?: number;
		negativePrompt?: string;
		useCache?: boolean;
		onPartialImages?: (images: IImage[], error: IError) =>  void;
	})
])

console.log({firstImagesRequest, secondImagesRequest})

return interface IImage {
	imageSrc: string;
	imageUUID: string;
	taskUUID: string;
	bNSFWContent: boolean;
}[]
ParameterTypeUse
positivePromptstringDefines the positive prompt description of the image.
imageSizenumberControls the image size.
modelIdnumberThe model id of the image to be requested.
numberOfImagesnumber: (Optional) (default = 1)(Optional) The number of images to be sent.
useCachestring: (Optional)Should use cached images (for faster response) or generate new images.
loraILora[]: (Optional)If provided it should be an array of objects. Each object must have two attributes: loraCivitaiAIR (string) and weight (float) with values from 0 to 1.
controlNetIControlNet[]: (Optional)If provided, should be an array of objects. Each object must have five attributes:
imageInitiatorstring or File: (Optional)The image requires for the seed image. It can be the UUID of previously generated image or an a file image.
imageMaskInitiatorstring or File: (Optional)The mask image requires for the seed image. It can be the UUID of previously generated image or an a file image.
stepsnumber: (Optional)The steps required to generate the image.
onPartialImagesfunction: (Optional)If you want to receive the images as they are generated instead of waiting for the async request, you get the images as they are generated from this function.
ControlNet Params
ParameterTypeUse
preprocessorstringDefines the positive prompt description of the image.
weightnumberan have values between 0 and 1 and represent the weight of the ControlNet preprocessor in the image.
startStepnumberrepresents the moment in which the ControlNet preprocessor starts to control the inference. It can take values from 0 to the maximum number of steps in the image create request. This can also be replaced with startStepPercentage (float) which represents the same value but in percentages. It takes values from 0 to 1.
numberOfImagesnumber: (Optional) (default = 1)(Optional) The number of images to be sent.
endStepnumbersimilar with startStep but represents the end of the preprocessor control of the image inference. The equivalent of the percentage option is startStepPercentage (float).
guideImagefile or string (Optional)The image requires for the guide image. It can be the UUID of previously generated image or an a file image.
guideImageUnprocessedfile or string (Optional)The image requires for the guide image unprocessed. It can be the UUID of previously generated image or an a file image.

 

Request Image To Text

const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);
const imageToText = await picfinder.requestImageToText({
	imageInitiator: string | File
})
console.log(imageToText)

return interface IImageToText {
	taskUUID: string;
	text: string;
}
ParameterTypeUse
imageInitiatorstring or FileThe image requires for the seed image. It can be the UUID of previously generated image or an a file image.

 

Remove Image Background

const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);
const image = await picfinder.removeImageBackground({
	imageInitiator: string | File
})
console.log(image)
return interface IImage {
	imageSrc: string;
	imageUUID: string;
	taskUUID: string;
	bNSFWContent: boolean;
}[]
ParameterTypeUse
imageInitiatorstring or FileThe image requires for the seed image. It can be the UUID of previously generated image or an a file image.

 

Upscale Image

const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);
const image = await picfinder.upscaleGan({
	imageInitiator: string | File;
	upscaleFactor: number;
})
console.log(image)
return interface IImage {
	imageSrc: string;
	imageUUID: string;
	taskUUID: string;
	bNSFWContent: boolean;
}[]
ParameterTypeUse
imageInitiatorstring or FileThe image requires for the seed image. It can be the UUID of previously generated image or an a file image.
upscaleFactornumberThe number of times to upscale;

 

Enhance Prompt

const  picfinder  =  new  Picfinder(ENVIRONMENT	, API_KEY);
const enhancedPrompt = await picfinder.enhancePrompt({
	prompt: string;
	promptMaxLength?: number;
	promptLanguageId?: number;
	promptVersions?: number;
})
console.log(enhancedPrompt)
return interface IEnhancedPrompt {
	taskUUID: string;
	text: string;
}[]
ParameterTypeUse
promptstringThe prompt that you intend to enhance.
promptMaxLengthnumber: OptionalCharacter count. Represents the maximum length of the prompt that you intend to receive. Can take values between 1 and 380.
promptVersionsnumber: OptionalThe number of prompt versions that will be received. Can take values between 1 and 5.
promptLanguageIdnumber: OptionalThe language prompt text. Can take values between 1 and 298. Default is 1 - English. Options are provided below.

 

Demo

Demo.

Changelog

- v1.0.27

Added or Changed

  • Refactor websocket listeners
  • Allow users to make parallel requests

- v1.0.26

Added or Changed

  • Validate valid UUID as image initiator

- v1.0.25

Added or Changed

  • Add Buffer utils necessary for server ws
  • Return images generated if timeout reached
  • Added support for LoRA
  • Added support for seed

- v1.0.24

Added or Changed

  • Introduce retry for missing images
  • Increase Polling time

- v1.0.23

Added or Changed

  • Fixed Upscalegan to allow imageUUID

- v1.0.22

Added or Changed

  • Fixed bugs

- v1.0.21

Added or Changed

  • Add control mode to control net

- v1.0.20

Added or Changed

  • Ensure connection for non instantiated instance

- v1.0.19

Added or Changed

  • Allow server sdk to reconnect on connection loss
  • Prevent duplicate message in server sdk
  • Modify connected method
  • Reduced polling interval

- v1.0.18

Added or Changed

  • Expose is connected method

- v1.0.17

Added or Changed

  • Minor Fixes

- v1.0.16

Added or Changed

  • Added Release Notes

- v1.0.15

Added or Changed

  • Added Server implementation (Nodejs)
  • Added Errors catching

Contributing

Credits

Resources

API Docs

1.0.27

2 months ago

1.0.26

3 months ago

1.0.25

4 months ago

1.0.24

4 months ago

1.0.23

5 months ago

1.0.22

5 months ago

1.0.21

5 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago