@@ -2,7 +2,12 @@ import { Client } from "@gradio/client";
2
2
import type { NextApiRequest , NextApiResponse } from "next" ;
3
3
import { getFile } from "../../../backend-utils/getFile" ;
4
4
import { GradioFile } from "../../../types/GradioFile" ;
5
- import { PayloadMessage , PredictFunction } from "@gradio/client/dist/types" ;
5
+ import {
6
+ GradioEvent ,
7
+ PayloadMessage ,
8
+ PredictFunction ,
9
+ SubmitIterable ,
10
+ } from "@gradio/client/dist/types" ;
6
11
7
12
type Data = { data : any } ;
8
13
@@ -53,11 +58,40 @@ const extractChoicesTuple = ({ choices }: GradioChoices) =>
53
58
const getChoices = ( result : { data : GradioChoices [ ] } ) =>
54
59
extractChoices ( result ?. data [ 0 ] ) ;
55
60
61
+ const proxyGradioFile = ( data : any ) =>
62
+ // typeof data === "object" && data.__type__ === "file"
63
+ // // ? new GradioFile(data.url, data.name)
64
+ // : data;
65
+ data
66
+
67
+ const proxyGradioFiles = ( data : any [ ] ) =>
68
+ Array . isArray ( data )
69
+ ? data . map ( proxyGradioFile )
70
+ : // : typeof data === "object"
71
+ // ? Object.fromEntries(
72
+ // Object.entries(data).map(([key, value]) => [
73
+ // key,
74
+ // proxyGradioFiles(value),
75
+ // ])
76
+ // )
77
+ data ;
78
+
56
79
const gradioPredict = < T extends any [ ] > ( ...args : Parameters < PredictFunction > ) =>
57
- getClient ( ) . then ( ( app ) => app . predict ( ...args ) ) as Promise < { data : T } > ;
80
+ // getClient().then((app) => app.predict(...args)) as Promise<{ data: T }>;
81
+ getClient ( )
82
+ . then ( ( app ) => app . predict ( ...args ) as Promise < { data : T } > )
83
+ . then ( ( result : { data : T } ) => ( {
84
+ ...result ,
85
+ data : proxyGradioFiles ( result ?. data ) as T ,
86
+ } ) ) ;
58
87
59
88
const gradioSubmit = < T extends any [ ] > ( ...args : Parameters < PredictFunction > ) =>
60
- getClient ( ) . then ( ( app ) => app . submit ( ...args ) ) ;
89
+ getClient ( ) . then (
90
+ ( app ) =>
91
+ app . submit ( ...args ) as SubmitIterable <
92
+ ( { data : T } & PayloadMessage ) | GradioEvent
93
+ >
94
+ ) ;
61
95
62
96
async function musicgen ( { melody, model, ...params } ) {
63
97
const melodyBlob = await getFile ( melody ) ;
@@ -155,11 +189,6 @@ async function bark({
155
189
} ;
156
190
}
157
191
158
- const reload_old_generation_dropdown = ( ) =>
159
- gradioPredict < [ GradioChoices ] > ( "/reload_old_generation_dropdown" ) . then (
160
- getChoices
161
- ) ;
162
-
163
192
const bark_favorite = async ( { folder_root } ) =>
164
193
gradioPredict < [ Object ] > ( "/bark_favorite" , [ folder_root ] ) . then (
165
194
( result ) => result ?. data
@@ -237,15 +266,6 @@ async function tortoise({
237
266
return results . slice ( 0 , - 1 ) ;
238
267
}
239
268
240
- const tortoise_refresh_models = ( ) =>
241
- gradioPredict < [ GradioChoices ] > ( "/tortoise_refresh_models" ) . then ( getChoices ) ;
242
-
243
- const tortoise_refresh_voices = ( ) =>
244
- gradioPredict < [ GradioChoices ] > ( "/tortoise_refresh_voices" ) . then ( getChoices ) ;
245
-
246
- const tortoise_open_models = ( ) => gradioPredict < [ ] > ( "/tortoise_open_models" ) ;
247
- const tortoise_open_voices = ( ) => gradioPredict < [ ] > ( "/tortoise_open_voices" ) ;
248
-
249
269
async function tortoise_apply_model_settings ( {
250
270
model, // string (Option from: ['Default']) in 'parameter_2488' Dropdown component
251
271
kv_cache, // boolean in 'parameter_2493' Checkbox component
@@ -308,32 +328,6 @@ async function rvc({
308
328
const delete_generation = ( { folder_root } ) =>
309
329
gradioPredict < [ ] > ( "/delete_generation" , [ folder_root ] ) ;
310
330
311
- const save_to_voices = ( { history_npz } ) =>
312
- gradioPredict < [ Object ] > ( "/save_to_voices" , [ history_npz ] ) ;
313
-
314
- const save_config_bark = ( {
315
- text_use_gpu,
316
- text_use_small,
317
- coarse_use_gpu,
318
- coarse_use_small,
319
- fine_use_gpu,
320
- fine_use_small,
321
- codec_use_gpu,
322
- load_models_on_startup,
323
- } ) =>
324
- gradioPredict < [ string ] > ( "/save_config_bark" , [
325
- text_use_gpu , // boolean in 'Use GPU' Checkbox component
326
- text_use_small , // boolean in 'Use small model' Checkbox component
327
- coarse_use_gpu , // boolean in 'Use GPU' Checkbox component
328
- coarse_use_small , // boolean in 'Use small model' Checkbox component
329
- fine_use_gpu , // boolean in 'Use GPU' Checkbox component
330
- fine_use_small , // boolean in 'Use small model' Checkbox component
331
- codec_use_gpu , // boolean in 'Use GPU for codec' Checkbox component
332
- load_models_on_startup , // boolean in 'Load Bark models on startup' Checkbox component
333
- ] ) . then ( ( result ) => result ?. data [ 0 ] ) ;
334
-
335
- // get_config_bark
336
-
337
331
async function get_config_bark ( ) {
338
332
const result = await gradioPredict <
339
333
[
0 commit comments