mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-09 02:00:44 +08:00
ae4277a9a8
* move files * commit the rest of the files * fix lockfile * fix workflow * fix type errors * fix tests * only run ci when certain files change * run correct test command in ci * version * fix pypi script --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> |
||
---|---|---|
.. | ||
src | ||
package.json | ||
README.md |
@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);