gradio/ui/packages/client
Freddy Boulton 79a369cc68
Fix loading css and api when mounted in subpath (#3482)
* Implementation

* Lint + CHANGELOG

* Remove log + / typo

* Fix embedding

* Minor fix

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-16 17:33:40 -04:00
..
src Fix loading css and api when mounted in subpath (#3482) 2023-03-16 17:33:40 -04:00
package.json JS client take 2 (#3388) 2023-03-07 16:36:25 +00:00
README.md JS client take 2 (#3388) 2023-03-07 16:36:25 +00:00

@gradio/client

A javascript client to call Gradio APIs.

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);