@@ -2,7 +2,12 @@ import { Client } from "@gradio/client";
22import type { NextApiRequest , NextApiResponse } from "next" ;
33import { getFile } from "../../../backend-utils/getFile" ;
44import { 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" ;
611
712type Data = { data : any } ;
813
@@ -53,11 +58,40 @@ const extractChoicesTuple = ({ choices }: GradioChoices) =>
5358const getChoices = ( result : { data : GradioChoices [ ] } ) =>
5459 extractChoices ( result ?. data [ 0 ] ) ;
5560
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+
5679const 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+ } ) ) ;
5887
5988const 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+ ) ;
6195
6296async function musicgen ( { melody, model, ...params } ) {
6397 const melodyBlob = await getFile ( melody ) ;
@@ -155,11 +189,6 @@ async function bark({
155189 } ;
156190}
157191
158- const reload_old_generation_dropdown = ( ) =>
159- gradioPredict < [ GradioChoices ] > ( "/reload_old_generation_dropdown" ) . then (
160- getChoices
161- ) ;
162-
163192const bark_favorite = async ( { folder_root } ) =>
164193 gradioPredict < [ Object ] > ( "/bark_favorite" , [ folder_root ] ) . then (
165194 ( result ) => result ?. data
@@ -237,15 +266,6 @@ async function tortoise({
237266 return results . slice ( 0 , - 1 ) ;
238267}
239268
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-
249269async function tortoise_apply_model_settings ( {
250270 model, // string (Option from: ['Default']) in 'parameter_2488' Dropdown component
251271 kv_cache, // boolean in 'parameter_2493' Checkbox component
@@ -308,32 +328,6 @@ async function rvc({
308328const delete_generation = ( { folder_root } ) =>
309329 gradioPredict < [ ] > ( "/delete_generation" , [ folder_root ] ) ;
310330
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-
337331async function get_config_bark ( ) {
338332 const result = await gradioPredict <
339333 [
0 commit comments