Hugging Face Hosted Inference API

Test and evaluate, for free, over 150,000 publicly accessible machine learning models, or your own private models, via simple HTTP requests, with fast inference hosted on Hugging Face shared infrastructure.

A wrapper package around HuggingFace's free Hosted Inference API.

This package is not affiliated or endorsed by HuggingFace, nor any of the models it hosts. Always check the license of the model you're using.

Features

This package supports text-to-text, text-to-image, image-to-image, and possibly other types of models. If you encounter a model that doesn't work, please open an issue.

Usage

GPT-2 (text-to-text)

Hugging Face's example is using gpt2, and this is its analogue in this package:

final api = HFApi(
  model: 'gpt2',
  outputType: HFOutputType.string,
  apiToken: 'hf_xxxxx',
);
final result = await api.run<String>('Can you please let us know more details about your ');

Cartoonizer (image-to-image)

final api = HFApi(
  model: 'instruction-tuning-sd/cartoonizer',
  outputType: HFOutputType.bytes,
  apiToken: 'hf_xxxxx',
);
final inputImage = await File('input.jpg').readAsBytes();
final result = await api.run<Uint8List>(inputImage);
await File('output.jpg').writeAsBytes(result);

Note that some models seem to require the input to be a jpeg (i.e. not a png). Otherwise, you'll get a HuggingFaceUnknownError with a message like {"error":"cannot identify image file <_io.BytesIO object at 0x7f416c25bdb0>"}.