Skip to content
Draft
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
193 changes: 193 additions & 0 deletions jupyterhub/Clowder_APIs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6dfcb963-cf69-4505-9871-5cc13471f5dd",
"metadata": {},
"source": [
"## Clowder APIs"
]
},
{
"cell_type": "markdown",
"id": "310051ad-4262-42fc-ac28-911f92842a7e",
"metadata": {},
"source": [
"## Import libraries and setup utility function\n",
"\n",
"We start by importing the rquired libraries, data and setting up some utility functions and variables that we will use below."
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "ffec7cb7-1a82-4148-aad1-bb3b1b19915b",
"metadata": {},
"outputs": [],
"source": [
"import pyclowder\n",
"import json\n",
"import os\n",
"import pandas as pd\n",
"\n",
"import requests\n",
"\n",
"# Function to download the IRIS dataset\n",
"def download_iris_dataset():\n",
" # URL for the Iris dataset hosted by UCI Machine Learning Repository\n",
" url = \"https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data\"\n",
" \n",
" response = requests.get(url)\n",
" \n",
" if response.status_code == 200:\n",
" return response.content\n",
" else:\n",
" print(\"Failed to download the dataset. Status code:\", response.status_code)\n",
"\n",
"\n",
"CLOWDER_URL = \"http://localhost:8000\""
]
},
{
"cell_type": "markdown",
"id": "f8d5c0ae-659b-4a52-a30a-0fa8b7051694",
"metadata": {},
"source": [
"## Token Generation"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "59fca5f8-a5d6-419d-835a-023a73c5a1d7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'token': 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI2dUVlQ0xOc1hTQXZUN1VDek1FRVk2VmI4ajJnY1RhWlFESUpnbnFGSHVJIn0.eyJ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GWdXxpVQUzwBNiXI2SO3FbWNk2uwR_qXL8WHyajHKCXvgHYHUbnAKJ1SRKO0xNfYDDlGKXuEn4fZfVmICq9693Z8emwydlcp8BVOaVuFqbsWwoRmEoSnK4bzLAH-CM-PFESPfbTrnu0Scnnw'}\n"
]
}
],
"source": [
"user_login_json = {\n",
" \"email\": \"[email protected]\",\n",
" \"password\": \"password\"\n",
"}\n",
"login_url = CLOWDER_URL + \"/api/v2/login\"\n",
"response = requests.post(login_url, json = user_login_json)\n",
"token = response.json()[\"token\"]\n",
"headers = {\n",
" 'Authorization': f'Bearer {token}'\n",
"}\n",
"print(response.json())"
]
},
{
"cell_type": "markdown",
"id": "2b273e10-8efc-46a8-b220-b63354735c49",
"metadata": {},
"source": [
"## Creating Dataset"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "91639e11-b553-4b57-a0df-6e91c661662f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'Flower Dataset', 'description': 'Dataset for Flower Data', 'status': 'PRIVATE', 'id': '66840cc55713c91cd9b89483', 'creator': {'email': '[email protected]', 'first_name': 'Vismayak', 'last_name': 'Mohanarajan', 'id': '663a45d5b75ca83d17ac6564', 'admin': True, 'admin_mode': True, 'read_only_user': False}, 'created': '2024-07-02T14:20:53.503934', 'modified': '2024-07-02T14:20:53.503942', 'user_views': 0, 'downloads': 0, 'thumbnail_id': None, 'standard_license': True, 'license_id': 'CC BY'}\n"
]
}
],
"source": [
"dataset_json = {\n",
" \"name\": \"Flower Dataset\",\n",
" \"description\": \"Dataset for Flower Data\",\n",
" \"status\": \"PRIVATE\",\n",
"}\n",
"dataset_params = {\n",
" \"license_id\": \"CC BY\"\n",
"}\n",
"\n",
"\n",
"dataset_url = CLOWDER_URL + \"/api/v2/datasets\"\n",
"response = requests.post(dataset_url, json = dataset_json, headers = headers, params = dataset_params)\n",
"dataset_id = response.json()['id']\n",
"print(response.json())"
]
},
{
"cell_type": "markdown",
"id": "51ad8ad2-bcb6-40d4-9587-44f6a1a7c09d",
"metadata": {},
"source": [
"## Uploading File"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "ed02e036-edd0-403b-8292-9600946bc156",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'file', 'status': 'PRIVATE', 'id': '66840ced5713c91cd9b89485', 'creator': {'email': '[email protected]', 'first_name': 'Vismayak', 'last_name': 'Mohanarajan', 'id': '663a45d5b75ca83d17ac6564', 'admin': True, 'admin_mode': True, 'read_only_user': False}, 'created': '2024-07-02T14:21:33.733027', 'version_id': '2a4bbb53-8149-4384-9d55-2696c9d587ed', 'version_num': 1, 'dataset_id': '66840cc55713c91cd9b89483', 'folder_id': None, 'views': 0, 'downloads': 0, 'bytes': 4551, 'content_type': {'content_type': 'application/octet-stream', 'main_type': 'application'}, 'thumbnail_id': None, 'storage_type': 'minio', 'storage_path': None, 'object_type': 'file'}\n"
]
}
],
"source": [
"\n",
"file = download_iris_dataset()\n",
"file_json = {\n",
" \"file\": file,\n",
" \"mediaType\": 'multipart/form-data'\n",
"}\n",
"save_file_url = CLOWDER_URL + \"/api/v2/datasets/\" + dataset_id + '/files'\n",
"headers = {\n",
" 'Authorization': f'Bearer {token}'\n",
"}\n",
"response = requests.post(save_file_url, files = file_json, headers = headers)\n",
"print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08c6673d-70d2-4879-948f-8db76eda4cde",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
23 changes: 23 additions & 0 deletions jupyterhub/Dockerfile.jupyterlab
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Base Image
FROM quay.io/jupyter/base-notebook:latest

# Install additional packages
USER root
RUN apt-get -qq update && apt-get install -y --no-install-recommends \
curl \
git \
zip unzip \
nano \
vim-tiny \
lsof && \
rm -rf /var/lib/apt/lists/*

USER $NB_USER

COPY Clowder_APIs.ipynb /home/jovyan/work/

# Install Python packages
RUN pip install --no-cache-dir \
requests \
pyclowder \
pandas
5 changes: 5 additions & 0 deletions jupyterhub/jupyterhub_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.


# Configuration file for JupyterHub
import os

Expand Down Expand Up @@ -38,6 +39,7 @@
# We follow the same convention.
notebook_dir = os.environ.get("DOCKER_NOTEBOOK_DIR", "/home/jovyan/work")
c.DockerSpawner.notebook_dir = notebook_dir
c.Spawner.args = ["--NotebookApp.default_url=/notebooks/Welcome.ipynb"]

# Mount the real user's Docker volume on the host to the notebook user's
# notebook directory in the container
Expand Down Expand Up @@ -101,6 +103,9 @@

c.JupyterHub.cookie_secret = os.getenv("JUPYTERHUB_CRYPT_KEY")

# Allow all users to access
c.Authenticator.allow_all = True

# Allowed admins
admin = os.environ.get("JUPYTERHUB_ADMIN")
if admin:
Expand Down