Skip to content

Repository files navigation

https://www.nuget.org/packages/StabilityClient.Net/https://www.nuget.org/packages/StabilityClient.Net/GitHub issuesGitHub license

StabilityClient.Net

gRPC client for StabilitySDK written with .Net 6.

Changelog

Features

  • Connect to StabilitySDK using:
    • environment variable STABILITY_KEY (default)
    • host (optional)
    • apiKey (optional)
  • RequestBuilder: fluent builder to easily build requests
  • SaveImagesToAsync: extension method to AsyncServerStreamingCall to easily save images

Usage

1. Add Nuget package from here.

2. Get your Stability API Key.

See here for instruction about how to get Stability API Key.

3. Create your client.

Recommended:

// This will use environment variable STABILITY_KEY as your API key input and https://grpc.stability.ai:443 as your host input.varstability=newStabilityClient();

Optional:

varstability=newStabilityClient("myStabilityApiKey","myHost");

4. Create request.

Using RequestBuilder:

varrequest=newRequestBuilder().SetTextPrompt("Chihuahua in sombrero").SetImageHeight(512)// optional.SetImageWidth(512)// optional.SetImageSteps(30)// optional.SetEngineId("stable-diffusion-512-v2-1")// optional.Build();

Raw:

varrequest=newRequest{Prompt={newPrompt{Text="Chihuahua in sombrero",Parameters=newPromptParameters{Init=true},},},EngineId="stable-diffusion-512-v2-1",Image=newImageParameters{Height=512,Width=512,Steps=30}};

5. Send request and save image from response to file.

Using SaveImagesToAsync extension method:

// Send requestvarresponse=stabilityClient.Generation.Generate(request);// Save to fileawaitresponse.SaveImagesToAsync("./Images");

Raw:

// Send requestvarresponse=stabilityClient.Generation.Generate(request).ResponseStream;// Save to filevarsource=newCancellationTokenSource();while(awaitresponse.MoveNext(source.Token)){varanswer=response.Current;foreach(varartifactinanswer.Artifacts){if(artifact.Type==ArtifactType.ArtifactImage){varcontent=artifact.Binary.ToByteArray();awaitFile.WriteAllBytesAsync("C:/Projects/Images/Image.png",content,source.Token);}}}

6. Enjoy your image :)

29 12 2022 13_40_24-a2089c29-f870-407f-a814-8c5f30796c75

Development

I am happy to accept suggestions for further development. Please feel free to add Issues :)

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages