Skip to content

Commit

Permalink
added jupyter notebook example
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Nov 2, 2022
1 parent 0febc5c commit 110c00c
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
151 changes: 151 additions & 0 deletions jupyter_example/oscar_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: oscar-python in /home/caterina/.local/lib/python3.9/site-packages (1.0.1b2)\n",
"Requirement already satisfied: webdavclient3==3.14.6 in /home/caterina/.local/lib/python3.9/site-packages (from oscar-python) (3.14.6)\n",
"Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from oscar-python) (2.25.1)\n",
"Requirement already satisfied: boto3 in /home/caterina/.local/lib/python3.9/site-packages (from oscar-python) (1.24.0)\n",
"Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from oscar-python) (5.3.1)\n",
"Requirement already satisfied: setuptools>=40.8.0 in /usr/lib/python3/dist-packages (from oscar-python) (52.0.0)\n",
"Requirement already satisfied: aiohttp in /home/caterina/.local/lib/python3.9/site-packages (from oscar-python) (3.8.1)\n",
"Requirement already satisfied: python-dateutil in /home/caterina/.local/lib/python3.9/site-packages (from webdavclient3==3.14.6->oscar-python) (2.8.2)\n",
"Requirement already satisfied: lxml in /home/caterina/.local/lib/python3.9/site-packages (from webdavclient3==3.14.6->oscar-python) (4.9.0)\n",
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.9/dist-packages (from aiohttp->oscar-python) (21.4.0)\n",
"Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (2.1.1)\n",
"Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (4.0.2)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (1.2.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (6.0.2)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (1.3.1)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /home/caterina/.local/lib/python3.9/site-packages (from aiohttp->oscar-python) (1.8.1)\n",
"Requirement already satisfied: idna>=2.0 in /usr/lib/python3/dist-packages (from yarl<2.0,>=1.0->aiohttp->oscar-python) (2.10)\n",
"Requirement already satisfied: botocore<1.28.0,>=1.27.0 in /home/caterina/.local/lib/python3.9/site-packages (from boto3->oscar-python) (1.27.28)\n",
"Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in /home/caterina/.local/lib/python3.9/site-packages (from boto3->oscar-python) (0.6.0)\n",
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/caterina/.local/lib/python3.9/site-packages (from boto3->oscar-python) (1.0.0)\n",
"Requirement already satisfied: urllib3<1.27,>=1.25.4 in /usr/lib/python3/dist-packages (from botocore<1.28.0,>=1.27.0->boto3->oscar-python) (1.26.5)\n",
"Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil->webdavclient3==3.14.6->oscar-python) (1.16.0)\n"
]
}
],
"source": [
"# Install a pip package in the current Jupyter kernel\n",
"import sys\n",
"!{sys.executable} -m pip install oscar-python"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from oscar_python.client import Client\n",
"\n",
"client = Client(\"cluster-id\",\"https://your-cluster-endpoint.net\", \"user\", \"password\", True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Service created!\n"
]
}
],
"source": [
"err = client.create_service(\"services/cowsay_example/cowsay.yaml\")\n",
"if not err:\n",
" print(\"Service created!\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" __________\n",
"< Hi there >\n",
" ----------\n",
" \\ ^__^\n",
" \\ (oo)\\_______\n",
" (__)\\ )\\/\\\n",
" ||----w |\n",
" || ||\n",
"\n",
"\n"
]
}
],
"source": [
"res = client.run_service(\"cowsay\", input = '{\"message\": \"Hi there\"}')\n",
"if res.status_code == 200:\n",
" print(res.text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
12 changes: 12 additions & 0 deletions jupyter_example/services/cowsay_example/cowsay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
functions:
oscar:
- oscar-gpu-cluster:
name: cowsay
cpu: 1.0
memory: 1Gi
image: ghcr.io/grycap/cowsay
script: services/cowsay_example/script.sh
log_level: CRITICAL # To avoid supervisor logs in response
environment:
Variables:
INPUT_TYPE: json # Comment to set input string encoded in base64
8 changes: 8 additions & 0 deletions jupyter_example/services/cowsay_example/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

if [ "$INPUT_TYPE" = "json" ]
then
jq '.message' "$INPUT_FILE_PATH" -r | /usr/games/cowsay
else
cat "$INPUT_FILE_PATH" | /usr/games/cowsay
fi

0 comments on commit 110c00c

Please sign in to comment.