Upload folder using huggingface_hub
Browse files
6.2.1/client/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/client",
|
| 3 |
-
"version": "2.0.
|
| 4 |
"description": "Gradio API client",
|
| 5 |
"type": "module",
|
| 6 |
"main": "dist/index.js",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/client",
|
| 3 |
+
"version": "2.0.2",
|
| 4 |
"description": "Gradio API client",
|
| 5 |
"type": "module",
|
| 6 |
"main": "dist/index.js",
|
6.2.1/client/src/client.ts
CHANGED
|
@@ -175,11 +175,11 @@ export class Client {
|
|
| 175 |
trigger_id?: number | null,
|
| 176 |
all_events?: boolean
|
| 177 |
) => SubmitIterable<GradioEvent>;
|
| 178 |
-
predict: (
|
| 179 |
endpoint: string | number,
|
| 180 |
data: unknown[] | Record<string, unknown> | undefined,
|
| 181 |
event_data?: unknown
|
| 182 |
-
) => Promise<PredictReturn>;
|
| 183 |
open_stream: () => Promise<void>;
|
| 184 |
private resolve_config: (endpoint: string) => Promise<Config | undefined>;
|
| 185 |
private resolve_cookies: () => Promise<void>;
|
|
@@ -200,7 +200,7 @@ export class Client {
|
|
| 200 |
this.handle_blob = handle_blob.bind(this);
|
| 201 |
this.post_data = post_data.bind(this);
|
| 202 |
this.submit = submit.bind(this);
|
| 203 |
-
this.predict = predict.bind(this);
|
| 204 |
this.open_stream = open_stream.bind(this);
|
| 205 |
this.resolve_config = resolve_config.bind(this);
|
| 206 |
this.resolve_cookies = resolve_cookies.bind(this);
|
|
|
|
| 175 |
trigger_id?: number | null,
|
| 176 |
all_events?: boolean
|
| 177 |
) => SubmitIterable<GradioEvent>;
|
| 178 |
+
predict: <T = unknown>(
|
| 179 |
endpoint: string | number,
|
| 180 |
data: unknown[] | Record<string, unknown> | undefined,
|
| 181 |
event_data?: unknown
|
| 182 |
+
) => Promise<PredictReturn<T>>;
|
| 183 |
open_stream: () => Promise<void>;
|
| 184 |
private resolve_config: (endpoint: string) => Promise<Config | undefined>;
|
| 185 |
private resolve_cookies: () => Promise<void>;
|
|
|
|
| 200 |
this.handle_blob = handle_blob.bind(this);
|
| 201 |
this.post_data = post_data.bind(this);
|
| 202 |
this.submit = submit.bind(this);
|
| 203 |
+
this.predict = predict.bind(this) as typeof this.predict;
|
| 204 |
this.open_stream = open_stream.bind(this);
|
| 205 |
this.resolve_config = resolve_config.bind(this);
|
| 206 |
this.resolve_cookies = resolve_cookies.bind(this);
|
6.2.1/client/src/types.ts
CHANGED
|
@@ -83,11 +83,11 @@ export type SubmitFunction = (
|
|
| 83 |
additional_headers?: Record<string, string>
|
| 84 |
) => SubmitIterable<GradioEvent>;
|
| 85 |
|
| 86 |
-
export type PredictFunction = (
|
| 87 |
endpoint: string | number,
|
| 88 |
data?: unknown[] | Record<string, unknown>,
|
| 89 |
event_data?: unknown
|
| 90 |
-
) => Promise<PredictReturn>;
|
| 91 |
|
| 92 |
export type client_return = {
|
| 93 |
config: Config | undefined;
|
|
@@ -102,7 +102,10 @@ export type client_return = {
|
|
| 102 |
};
|
| 103 |
|
| 104 |
export interface SubmitIterable<T> extends AsyncIterable<T> {
|
| 105 |
-
[Symbol.asyncIterator]():
|
|
|
|
|
|
|
|
|
|
| 106 |
cancel: () => Promise<void>;
|
| 107 |
event_id: () => string;
|
| 108 |
send_chunk: (payload: Record<string, unknown>) => void;
|
|
@@ -110,10 +113,10 @@ export interface SubmitIterable<T> extends AsyncIterable<T> {
|
|
| 110 |
close_stream: () => void;
|
| 111 |
}
|
| 112 |
|
| 113 |
-
export type PredictReturn = {
|
| 114 |
type: EventType;
|
| 115 |
time: Date;
|
| 116 |
-
data:
|
| 117 |
endpoint: string;
|
| 118 |
fn_index: number;
|
| 119 |
};
|
|
|
|
| 83 |
additional_headers?: Record<string, string>
|
| 84 |
) => SubmitIterable<GradioEvent>;
|
| 85 |
|
| 86 |
+
export type PredictFunction = <T = unknown>(
|
| 87 |
endpoint: string | number,
|
| 88 |
data?: unknown[] | Record<string, unknown>,
|
| 89 |
event_data?: unknown
|
| 90 |
+
) => Promise<PredictReturn<T>>;
|
| 91 |
|
| 92 |
export type client_return = {
|
| 93 |
config: Config | undefined;
|
|
|
|
| 102 |
};
|
| 103 |
|
| 104 |
export interface SubmitIterable<T> extends AsyncIterable<T> {
|
| 105 |
+
[Symbol.asyncIterator](): SubmitIterable<T>;
|
| 106 |
+
next: () => Promise<IteratorResult<T, unknown>>;
|
| 107 |
+
throw: (value: unknown) => Promise<IteratorResult<T, unknown>>;
|
| 108 |
+
return: () => Promise<IteratorReturnResult<undefined>>;
|
| 109 |
cancel: () => Promise<void>;
|
| 110 |
event_id: () => string;
|
| 111 |
send_chunk: (payload: Record<string, unknown>) => void;
|
|
|
|
| 113 |
close_stream: () => void;
|
| 114 |
}
|
| 115 |
|
| 116 |
+
export type PredictReturn<T = unknown> = {
|
| 117 |
type: EventType;
|
| 118 |
time: Date;
|
| 119 |
+
data: T;
|
| 120 |
endpoint: string;
|
| 121 |
fn_index: number;
|
| 122 |
};
|
6.2.1/client/src/utils/predict.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import { Client } from "../client";
|
| 2 |
import type { Dependency, PredictReturn } from "../types";
|
| 3 |
|
| 4 |
-
export async function predict(
|
| 5 |
this: Client,
|
| 6 |
endpoint: string | number,
|
| 7 |
data: unknown[] | Record<string, unknown> = {}
|
| 8 |
-
): Promise<PredictReturn> {
|
| 9 |
let data_returned = false;
|
| 10 |
let status_complete = false;
|
| 11 |
let dependency: Dependency;
|
|
@@ -30,7 +30,7 @@ export async function predict(
|
|
| 30 |
for await (const message of app) {
|
| 31 |
if (message.type === "data") {
|
| 32 |
if (status_complete) {
|
| 33 |
-
resolve(result as PredictReturn);
|
| 34 |
}
|
| 35 |
data_returned = true;
|
| 36 |
result = message;
|
|
@@ -42,7 +42,7 @@ export async function predict(
|
|
| 42 |
status_complete = true;
|
| 43 |
// if complete message comes after data, resolve here
|
| 44 |
if (data_returned) {
|
| 45 |
-
resolve(result as PredictReturn);
|
| 46 |
}
|
| 47 |
}
|
| 48 |
}
|
|
|
|
| 1 |
import { Client } from "../client";
|
| 2 |
import type { Dependency, PredictReturn } from "../types";
|
| 3 |
|
| 4 |
+
export async function predict<T = unknown>(
|
| 5 |
this: Client,
|
| 6 |
endpoint: string | number,
|
| 7 |
data: unknown[] | Record<string, unknown> = {}
|
| 8 |
+
): Promise<PredictReturn<T>> {
|
| 9 |
let data_returned = false;
|
| 10 |
let status_complete = false;
|
| 11 |
let dependency: Dependency;
|
|
|
|
| 30 |
for await (const message of app) {
|
| 31 |
if (message.type === "data") {
|
| 32 |
if (status_complete) {
|
| 33 |
+
resolve(result as PredictReturn<T>);
|
| 34 |
}
|
| 35 |
data_returned = true;
|
| 36 |
result = message;
|
|
|
|
| 42 |
status_complete = true;
|
| 43 |
// if complete message comes after data, resolve here
|
| 44 |
if (data_returned) {
|
| 45 |
+
resolve(result as PredictReturn<T>);
|
| 46 |
}
|
| 47 |
}
|
| 48 |
}
|
6.2.1/client/src/utils/submit.ts
CHANGED
|
@@ -663,7 +663,7 @@ export function submit(
|
|
| 663 |
return new Promise((resolve) => resolvers.push(resolve));
|
| 664 |
}
|
| 665 |
|
| 666 |
-
const iterator = {
|
| 667 |
[Symbol.asyncIterator]: () => iterator,
|
| 668 |
next,
|
| 669 |
throw: async (value: unknown) => {
|
|
|
|
| 663 |
return new Promise((resolve) => resolvers.push(resolve));
|
| 664 |
}
|
| 665 |
|
| 666 |
+
const iterator: SubmitIterable<GradioEvent> = {
|
| 667 |
[Symbol.asyncIterator]: () => iterator,
|
| 668 |
next,
|
| 669 |
throw: async (value: unknown) => {
|