Skip to content

Commit

Permalink
Merge branch 'main' into services-section
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Sep 29, 2023
2 parents 79646a0 + 1b8db90 commit 28983ef
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ command. Currently, the following frameworks are supported:
- [x] Plotly Dash
- [x] Voila
- [x] Gradio
- [x] JupyterLab
- [x] Generic Python Command

![JHub Apps Demo](https://raw.githubusercontent.com/nebari-dev/jhub-apps/main/demo.gif)

Expand Down
27 changes: 26 additions & 1 deletion jhub_apps/launcher/panel_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import panel as pn

from jhub_apps.launcher.hub_client import HubClient
from jhub_apps.spawner.types import FRAMEWORKS_MAPPING, FrameworkConf, UserOptions
from jhub_apps.spawner.types import (
FRAMEWORKS_MAPPING,
FrameworkConf,
UserOptions,
Framework,
)

EDIT_APP_BTN_TXT = "Edit App"
CREATE_APP_BTN_TXT = "Create App"
Expand Down Expand Up @@ -115,6 +120,7 @@ class InputFormWidget:
filepath_input: Any
thumbnail: Any
description_input: Any
custom_command: Any
spinner: Any
button_widget: Any
framework: Any
Expand Down Expand Up @@ -416,6 +422,9 @@ def get_input_form_widget():
description_input=pn.widgets.TextAreaInput(
name="Description", css_classes=["custom-font"]
),
custom_command=pn.widgets.TextInput(
name="Custom Command", css_classes=["custom-font"], visible=False
),
spinner=pn.indicators.LoadingSpinner(
size=30, value=True, color="secondary", bgcolor="dark", visible=True
),
Expand All @@ -424,14 +433,25 @@ def get_input_form_widget():
name="Framework", options=frameworks_display, css_classes=["custom-font"]
),
)

def framework_handler(selected_framework):
if selected_framework == Framework.generic.value:
input_form_widget.custom_command.visible = True
else:
input_form_widget.custom_command.visible = False

binding = pn.bind(framework_handler, input_form_widget.framework)

input_form = pn.Column(
binding,
heading,
input_form_widget.name_input,
input_form_widget.filepath_input,
pn.pane.Markdown("App Thumbnail", css_classes=["custom-font"]),
input_form_widget.thumbnail,
input_form_widget.description_input,
input_form_widget.framework,
input_form_widget.custom_command,
input_form_widget.button_widget,
width=400,
)
Expand Down Expand Up @@ -499,6 +519,7 @@ def _create_server(event, input_form_widget, input_form, username):
thumbnail=thumbnail_local_filepath,
filepath=filepath,
framework=framework,
custom_command=input_form_widget.custom_command.value,
)
try:
response_status_code, servername = hclient.create_server(
Expand Down Expand Up @@ -575,6 +596,10 @@ def create_app_form_page():
"filepath"
)
input_form_widget.thumbnail.value = server.get("user_options").get("thumbnail")
input_form_widget.framework.value = server.get("user_options").get("framework")
input_form_widget.custom_command.value = server.get("user_options").get(
"custom_command"
)
input_form_widget.button_widget.name = "Edit App"

if not username:
Expand Down
7 changes: 7 additions & 0 deletions jhub_apps/spawner/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def get_substituted_args(self, **kwargs):
]
)

GENERIC_ARGS = [
"--destport=0",
"--ready-check-path=/ready-check",
TString("$python_exec"),
"{-}m",
]

COMMANDS = {
Framework.gradio.value: Command(
args=[
Expand Down
14 changes: 12 additions & 2 deletions jhub_apps/spawner/spawner_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Command,
EXAMPLES_FILE,
DEFAULT_CMD,
GENERIC_ARGS,
)
from jhub_apps.spawner.types import Framework

Expand All @@ -24,15 +25,24 @@ def get_args(self):
jh_service_prefix = env.get("JUPYTERHUB_SERVICE_PREFIX")
framework = self.user_options.get("framework")
app_filepath = None
if framework != Framework.jupyterlab.value:
if framework not in [
Framework.jupyterlab.value,
Framework.generic.value,
]:
app_filepath = filepath or EXAMPLES_DIR / EXAMPLES_FILE.get(
framework
)

if not filepath:
# Saving the examples file path when not provided
self.user_options["filepath"] = str(app_filepath)
command: Command = COMMANDS.get(framework)

custom_cmd = self.user_options.get("custom_command")
if framework == Framework.generic.value:
assert custom_cmd
command = Command(args=GENERIC_ARGS + custom_cmd.split())
else:
command: Command = COMMANDS.get(framework)
command_args = command.get_substituted_args(
python_exec=self.config.JAppsConfig.python_exec,
filepath=app_filepath,
Expand Down
7 changes: 7 additions & 0 deletions jhub_apps/spawner/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class UserOptions:
thumbnail: str
filepath: str
framework: str
custom_command: typing.Optional[str] = None
env: typing.Optional[dict] = None


Expand All @@ -29,6 +30,7 @@ class Framework(Enum):
voila = "voila"
gradio = "gradio"
jupyterlab = "jupyterlab"
generic = "generic"

@classmethod
def values(cls):
Expand Down Expand Up @@ -71,6 +73,11 @@ def values(cls):
display_name="JupyterLab",
logo="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/1200px-Jupyter_logo.svg.png",
),
FrameworkConf(
name=Framework.generic.value,
display_name="Generic",
logo="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/1200px-Jupyter_logo.svg.png",
),
]

FRAMEWORKS_MAPPING = {framework.name: framework for framework in FRAMEWORKS}

0 comments on commit 28983ef

Please sign in to comment.