replicate_json

Last updated:

0 purchases

replicate_json Image
replicate_json Images
Add to Cart

Description:

replicate json

Replicate Dart Package #
A Dart package for interacting with the Replicate API, enabling seamless communication with their prediction service.
Features #

Create Prediction: Generate predictions based on a specified model, API key, and input data.
Get Prediction PNG: Retrieve the prediction in PNG format using the prediction ID and API key.
Create and Get JSON: Create a prediction and continuously check its status until it is completed, returning the result in JSON format.

Installation #
Add the following dependency to your pubspec.yaml file:
dependencies:
replicate_dart: ^1.0.0
copied to clipboard
Usage #
import the package #
import 'package:replicate_dart/replicate_dart.dart';
copied to clipboard
Define the Model, Api key, and desired Inputs #
String apiKey = "your_replicate_api_key";

// Replace with the desired model version
String model = "your_model_version";

// Replace with your input data
Map<String, Object> inputData = {
"feature1": "value1",
// Add more features as needed for your use
};
copied to clipboard
Making the api call #
createAndGetJson() returns a json string, and is async. After the call is made, the json can be decoded and parsed.
try {
String jsonString = await createAndGetJson(
modelVersion,
apiKey,
input,
);

var responseJson = jsonDecode(jsonString); //converts string to json object

// then you can parse the json file to get whatever value you need
// For this example, I want the 'output', which is a png link
String pngLink = responseJson['output'][0];

} catch (error) {
print('Error: $error');
}
copied to clipboard
Note: #

Please replace "your_replicate_api_key" and "your_model_version" with your actual Replicate API key and model version.
The provided usage example demonstrates how to create predictions, retrieve PNG results, and obtain final results in JSON format. This is all done through one function.

Additional information #
Right now, this package in not very flushed out, but hopefully it is able to help at least a couple people out. If you have any questions or suggestions, feel free to email me.
License #
This Replicate Dart package is released under the MIT License. Feel free to contribute and improve the package!

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.