Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(client): tune gradio import to slove slow import issue #1759

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions client/starwhale/api/_impl/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import functools
from dataclasses import dataclass

import gradio
from gradio.components import Component

from starwhale.utils import in_production

Input = t.Union[Component, t.List[Component]]
Output = t.Union[Component, t.List[Component]]
if t.TYPE_CHECKING:
from gradio import Blocks
from gradio.components import Component

Input = t.Union["Component", t.List["Component"]]
Output = t.Union["Component", t.List["Component"]]
Examples = t.Union[t.List[t.Any], str]


Expand Down Expand Up @@ -78,6 +79,8 @@ def get_openapi_spec(self) -> t.Any:
return server.app.openapi()

def _render_api(self, _api: Api, hijack_submit: bool) -> None:
import gradio

js_func: t.Optional[str] = None
if hijack_submit:
js_func = "async(...x) => { typeof wait === 'function' && await wait(); return x; }"
Expand Down Expand Up @@ -106,7 +109,9 @@ def _render_api(self, _api: Api, hijack_submit: bool) -> None:

def _gen_gradio_server(
self, hijack_submit: bool, title: t.Optional[str] = None
) -> gradio.Blocks:
) -> "Blocks":
import gradio

apis = self.apis.values()
with gradio.Blocks() as app:
with gradio.Tabs():
Expand Down
14 changes: 14 additions & 0 deletions scripts/client_test/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from concurrent.futures._base import Future

from cmds.eval_cmd import Evaluation
from cmds.base.invoke import invoke
from cmds.project_cmd import Project
from cmds.instance_cmd import Instance
from cmds.artifacts_cmd import Model, Dataset, Runtime
Expand Down Expand Up @@ -363,6 +364,17 @@ def debug(self) -> None:
workdir_ = expl["workdir"]
self.build_model(str(workdir_))

def smoke_commands(self) -> None:
commands = [
"timeout 2 swcli --help",
"swcli --version",
]

for cmd in commands:
_code, _err = invoke(cmd.split())
if _code != 0:
raise RuntimeError(f"cmd[{cmd}] run failed, err: {_err}, code: {_code}")


if __name__ == "__main__":
with ThreadPoolExecutor(
Expand All @@ -383,3 +395,5 @@ def debug(self) -> None:
test_cli.debug()
else:
test_cli.test_expl(expl_name=example)

test_cli.smoke_commands()