gradio/ui/packages/client
2023-03-22 18:07:17 +00:00
..
src Theme+release (#3494) 2023-03-17 07:41:53 -07:00
package.json 3404 publish js client (#3574) 2023-03-22 13:46:23 +00:00
README.md update gradio/client readme (#3584) 2023-03-22 18:07:17 +00:00

@gradio/client

A javascript client to call Gradio APIs.

install it

pnpm add @gradio/client

usage

import { client } from "@gradio/client";

const app = client();

const prediction = app.predict(endpoint, payload);

// listen for predictions
prediction.on("data", (event: { data: Array<unknown>; type: "data" }) => {});

// listen for status updates
prediction.on("status", (event: { data: Status; type: "data" }) => {});

interface Status {
	status: "pending" | "error" | "complete" | "generating";
	size: number;
	position?: number;
	eta?: number;
	message?: string;
	progress?: Array<{
		progress: number | null;
		index: number | null;
		length: number | null;
		unit: string | null;
		desc: string | null;
	}>;
}

// stop listening
prediction.off("data");

// cancel a prediction if it is a generator
prediction.cancel();

// chainable
const prediction_two = app
	.predict(endpoint, payload)
	.on("data", data_callback)
	.on("status", status_callback);