Giter Site home page Giter Site logo

stabilityclient.net's Introduction

https://www.nuget.org/packages/StabilityClient.Net/ https://www.nuget.org/packages/StabilityClient.Net/ GitHub issues GitHub 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.
var stability = new StabilityClient();

Optional:

var stability = new StabilityClient("myStabilityApiKey", "myHost");

4. Create request.

Using RequestBuilder:

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

Raw:

var request = new Request {
  Prompt = {
    new Prompt {
      Text = "Chihuahua in sombrero",
      Parameters = new PromptParameters {
        Init = true
      },
    },
  },
  EngineId = "stable-diffusion-512-v2-1",
  Image = new ImageParameters {
    Height = 512,
    Width = 512,
    Steps = 30
  }
};

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

Using SaveImagesToAsync extension method:

// Send request
var response = stabilityClient.Generation.Generate(request);

// Save to file
await response.SaveImagesToAsync("./Images");

Raw:

// Send request
var response = stabilityClient.Generation.Generate(request).ResponseStream;

// Save to file
var source = new CancellationTokenSource();
while (await response.MoveNext(source.Token)) {
  var answer = response.Current;
  foreach (var artifact in answer.Artifacts) {
    if (artifact.Type == ArtifactType.ArtifactImage) {
      var content = artifact.Binary.ToByteArray();
      await File.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.

stabilityclient.net's People

Contributors

actions-user avatar katarzyna-kadziolka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.