Allow async js fn (#1439)

* updated PyPi version to 3.0.10

* updated PyPi version to 3.0.9b10

* fixes

* updated PyPi version to 3.0.9b11

* fix update sript

* changes
This commit is contained in:
aliabid94 2022-06-01 11:34:07 -07:00 committed by GitHub
parent 279df2322d
commit 188d8bc65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: gradio
Version: 3.0.9
Version: 3.0.9b11
Summary: Python library for easily interacting with trained machine learning models
Home-page: https://github.com/gradio-app/gradio
Author: Abubakar Abid, Ali Abid, Ali Abdalla, Dawood Khan, Ahsen Khaliq, Pete Allen, Ömer Faruk Özdemir

View File

@ -1 +1 @@
3.0.9
3.0.9b11

View File

@ -9,7 +9,7 @@ long_description = (this_directory / "README.md").read_text(encoding='utf8')
setup(
name="gradio",
version="3.0.9",
version="3.0.9b11",
include_package_data=True,
description="Python library for easily interacting with trained machine learning models",
long_description=long_description,

View File

@ -62,12 +62,14 @@
let rootNode: Component = { id: layout.id, type: "column", props: {} };
components.push(rootNode);
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
dependencies.forEach((d) => {
if (d.js) {
try {
d.frontend_fn = new Function(
d.frontend_fn = new AsyncFunction(
"__fn_args",
`return ${d.outputs.length} === 1 ? [(${d.js})(...__fn_args)] : (${d.js})(...__fn_args)`
`let result = await (${d.js})(...__fn_args);
return ${d.outputs.length} === 1 ? [result] : result;`
);
} catch (e) {
console.error("Could not parse custom js method.");

View File

@ -68,8 +68,9 @@ export const fn = async (
) => {
const fn_index = payload.fn_index;
console.log(">", frontend_fn);
if (frontend_fn !== undefined) {
payload.data = frontend_fn(payload.data.concat(output_data));
payload.data = await frontend_fn(payload.data.concat(output_data));
}
if (backend_fn == false) {
return payload;