| 257 | settings[endpoint.name] = buildGradioSettings(endpoint) |
| 258 | } |
| 259 | async function predict(endpoint: GradioManifestEndpoint, args, settings) { |
| 260 | const options = settings._hfToken ? { hf_token: settings._hfToken } : undefined |
| 261 | const app = await GradioClient.connect(manifest.baseUrl, options) |
| 262 | const { data } = await app.predict(endpoint.path, { ...settings[endpoint.name], ...args }) |
| 263 | return await Promise.all(endpoint.outputIdxs.map(async i => { |
| 264 | const d = data[i] |
| 265 | if (typeof d === 'object' && d.url) { |
| 266 | const resp = await fetch(d.url) |
| 267 | const blob = await resp.blob() |
| 268 | return { |
| 269 | type: 'file' as const, |
| 270 | mimeType: blob.type, |
| 271 | contentBuffer: await blob.arrayBuffer(), |
| 272 | name: d.orig_name |
| 273 | } |
| 274 | } |
| 275 | return { |
| 276 | type: 'text' as const, |
| 277 | contentText: d |
| 278 | } |
| 279 | })) |
| 280 | } |
| 281 | const infos: PluginApi[] = manifest.endpoints.filter(e => e.type === 'info').map(e => { |
| 282 | const { name, description, infoType } = e |
| 283 | return { |