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

FEAT Add skops space creator app #307

Merged
merged 29 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f2e3490
Add skops space creator app
BenjaminBossan Feb 27, 2023
e084670
Explicitly set packages arg in setup
BenjaminBossan Feb 27, 2023
8c5f070
Try setting HF hub token
BenjaminBossan Feb 27, 2023
f17780c
Try to fix missing token
BenjaminBossan Feb 28, 2023
1c81e37
Try to fix missing token #2
BenjaminBossan Feb 28, 2023
48c0a39
Try to fix missing token attempt 3
BenjaminBossan Feb 28, 2023
7157272
Debugging
BenjaminBossan Feb 28, 2023
d71fda8
Try to fix missing token attempt 4
BenjaminBossan Feb 28, 2023
25c7591
testing CI
adrinjalali Mar 3, 2023
2e3c55b
testing imports
adrinjalali Mar 3, 2023
2bf54d3
use cd
adrinjalali Mar 3, 2023
ff4c592
fix ci script
adrinjalali Mar 3, 2023
b060f91
trigger ci
adrinjalali Mar 3, 2023
a9ebd9d
-e
adrinjalali Mar 3, 2023
9b6debb
Merge remote-tracking branch 'upstream/main' into skops-space-creator
adrinjalali Mar 3, 2023
43442f3
run script directly
adrinjalali Mar 3, 2023
8b1d281
Fix directory name
BenjaminBossan Mar 3, 2023
c7d62c0
[WIP] Move space deployment to separate workflow
BenjaminBossan Mar 3, 2023
f20c26b
Add the new workflow file
BenjaminBossan Mar 3, 2023
4bf0818
Rename new workflow (was still pytest from c&p)
BenjaminBossan Mar 3, 2023
6543674
Fix invalid name of workflow
BenjaminBossan Mar 3, 2023
bce8195
Another invalid name...
BenjaminBossan Mar 3, 2023
860dd5a
Set correct secret for deploying to HF sklearn org
BenjaminBossan Mar 3, 2023
84a8eb0
Add missing cat.png
BenjaminBossan Mar 3, 2023
4b490d9
Merge branch 'main' into skops-space-creator
BenjaminBossan Apr 4, 2023
570332c
Update to use latest model card changes
BenjaminBossan Apr 4, 2023
caca0e6
Rename: space creator > model card creator
BenjaminBossan Apr 4, 2023
bb7ffbd
Forgot to rename in GH workflow
BenjaminBossan Apr 4, 2023
8db2ddd
Merge branch 'main' into skops-space-creator
BenjaminBossan Apr 6, 2023
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
46 changes: 46 additions & 0 deletions .github/workflows/deploy-model-card-creator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy-Space-Creator

on:
- push
- pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
deploy-space-creator:
runs-on: "ubuntu-latest"
if: "github.repository == 'skops-dev/skops'"
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: |
pip install -e .[docs,tests]
python --version
pip --version
pip list
shell: bash

- name: Create test skops space creator app
# by default, deploy to skops CI
if: github.ref != 'refs/heads/main'
run: |
python spaces/deploy-skops-model-card-creator.py

- name: Create main skops space creator app
# if HF_HUB_TOKEN_SKLEARN, use that instead of skops CI orga
if: github.ref == 'refs/heads/main'
env:
HF_HUB_TOKEN_SKLEARN: ${{ secrets.HF_HUB_TOKEN_SKLEARN }}
run: |
python spaces/deploy-skops-model-card-creator.py
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ repos:
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
exclude: "spaces/"
additional_dependencies: [types-requests>=2.28.5]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ omit = [
]

[tool.mypy]
exclude = "(\\w+/)*test_\\w+\\.py$|old"
exclude = "(\\w+/)*test_\\w+\\.py$|spaces/skops_model_card_creator|old"
ignore_missing_imports = true
no_implicit_optional = true
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def setup_package():
"rich": min_deps.tag_to_packages["rich"],
},
include_package_data=True,
packages=["skops"],
)

setup(**package_data, **metadata)
Expand Down
3 changes: 3 additions & 0 deletions spaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hugging Face Spaces

Code and script for creating Hugging Face Spaces go here.
49 changes: 49 additions & 0 deletions spaces/deploy-skops-model-card-creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Deploying the app in skops_model_card_creator as a Hugging Face Space requires
# the HF_HUB_TOKEN to be set as environment variable

import os
from pathlib import Path
from uuid import uuid4

from huggingface_hub import HfApi

import skops
import skops.hub_utils
import skops.hub_utils.tests
from skops.hub_utils.tests.common import HF_HUB_TOKEN

token = os.environ.get("HF_HUB_TOKEN_SKLEARN")
if token:
print("Deploying space to sklearn orga")
else:
print("Deploying space to skops CI")
token = HF_HUB_TOKEN

client = HfApi(token=token)
user_name = client.whoami(token=token)["name"]
repo_name = f"skops-model-card-creator-{uuid4()}"
repo_id = f"{user_name}/{repo_name}"
print(f"Creating and pushing to repo: {repo_id}")

space_repo = Path(skops.__path__[0]).parent / "spaces" / "skops_model_card_creator"

client.create_repo(
repo_id=repo_id,
token=token,
repo_type="space",
exist_ok=True,
space_sdk="streamlit",
)
out = client.upload_folder(
repo_id=repo_id,
path_in_repo=".",
folder_path=space_repo,
commit_message="Create skops-model-card-creator space",
token=token,
repo_type="space",
create_pr=False,
)

# link to main app, not to "<url>/tree/main/"
url = out.rsplit("/", 3)[0]
print(f"visit the space at {url}")
Loading