Spaces:
Runtime error
Runtime error
New: Add dev mode and related config/workflow
Browse filesFiles changed (5)
1 unmodified line2345678910118 unmodified lines2021221 unmodified linefrom model import ConfigUserName = Literal["default"]PRODUCTION_SPACE_CONFIG: Dict[UserName, Config] = {"default": {"space_name": "example","space_owner": "jy-raychen","space_readme": {8 unmodified lines},}}1 unmodified line2345678910118 unmodified lines2021222324252627282930313233343536373839404142434445464748495051525354551 unmodified linefrom model import ConfigProductionSpace = Literal["production"]PRODUCTION_SPACE_CONFIG: Dict[ProductionSpace, Config] = {"production": {"space_name": "example","space_owner": "jy-raychen","space_readme": {8 unmodified lines},}}UserName = Literal["default", "jhihruei"]DEV_SPACE_CONFIG: Dict[UserName, Config] = {"default": {"space_name": "dev-space","space_owner": "jy-raychen","space_readme": {"title": "Hugging Face Developing","emoji": "🏢","color_from": "blue","color_to": "indigo","sdk": "gradio","sdk_version": "4.36.0","app_file": "app.py","pinned": False,},},"jhihruei": {"space_name": "personal-dev","space_owner": "jy-raychen","space_readme": {"title": "Personal Developing","emoji": "🏢","color_from": "yellow","color_to": "indigo","sdk": "gradio","sdk_version": "4.21.0","app_file": "app.py","pinned": False,},},}
1 unmodified line234567823 unmodified lines323334353637383940411 unmodified lineimport subprocessimport sysfrom config import PRODUCTION_SPACE_CONFIGfrom model import Space23 unmodified linesparser.add_argument("--branch_name", required=True)parser.add_argument("--username", required=True)parser.add_argument("--user_token", required=True)args = parser.parse_args()# TODO: Use different space config when deploy to dev environment.space = Space(PRODUCTION_SPACE_CONFIG["default"])push_result = force_push_to_remote(space, args.username, args.user_token, args.branch_name1 unmodified line234567823 unmodified lines3233343536373839404142434445464748495051525354551 unmodified lineimport subprocessimport sysfrom config import DEV_SPACE_CONFIG, PRODUCTION_SPACE_CONFIGfrom model import Space23 unmodified linesparser.add_argument("--branch_name", required=True)parser.add_argument("--username", required=True)parser.add_argument("--user_token", required=True)parser.add_argument("--mode", required=True, choices=["prod", "dev"])parser.add_argument("--deployer",help="The actor in Github Actions, it used to choose space config in dev mode.",)args = parser.parse_args()try:if args.mode == "prod":space = Space(PRODUCTION_SPACE_CONFIG["production"])elif args.mode == "dev":space_config = DEV_SPACE_CONFIG.get(args.deployer, DEV_SPACE_CONFIG["default"])space = Space(space_config)except Exception:print("Error: The space is not set correctly!")sys.exit(1)push_result = force_push_to_remote(space, args.username, args.user_token, args.branch_name
12345615 unmodified lines22232425262728import sysfrom config import PRODUCTION_SPACE_CONFIGfrom model import ReadMe, SpaceDEFAULT_USER = "jy-raychen"15 unmodified linesif __name__ == "__main__":space = Space(PRODUCTION_SPACE_CONFIG["default"])readme = readme_template(space.readme)print(readme)123456715 unmodified lines232425262728293031323334353637383940414243444546474849import argparseimport sysfrom config import DEV_SPACE_CONFIG, PRODUCTION_SPACE_CONFIGfrom model import ReadMe, SpaceDEFAULT_USER = "jy-raychen"15 unmodified linesif __name__ == "__main__":parser = argparse.ArgumentParser(description="Generate Hugging Face space config file (i.e. README.md).")parser.add_argument("--mode", required=True, choices=["prod", "dev"])parser.add_argument("--deployer",help="The actor in Github Actions, it used to choose space config in dev mode.",)args = parser.parse_args()try:if args.mode == "prod":space = Space(PRODUCTION_SPACE_CONFIG["production"])elif args.mode == "dev":space_config = DEV_SPACE_CONFIG.get(args.deployer, DEV_SPACE_CONFIG["default"])space = Space(space_config)except Exception:print("Error: The space is not set correctly!")sys.exit(1)readme = readme_template(space.readme)print(readme)
1234567891011121314151617181920212223242526272829303132333435363738394041name: Deploy Dev run-name: Deploy to dev space
on: push: branches: - '**' - '!main'
concurrency: # NOTE: The same actor will deploy to the same space, so we should cancel other earlier jobs. group: ${{ github.workflow }}-${{ github.actor }} cancel-in-progress: true
jobs: run_deploy_tool: runs-on: ubuntu-latest permissions: contents: read steps: - name: Check out repository code uses: actions/checkout@v4 with: fetch-depth: '0' - name: Update Repo README.md run: | python3 .github/tools/generate_readme.py --mode="dev" --deployer="${{ github.actor }}" > README.md git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions[bot]" git add ./README.md if [[ `git status --porcelain` ]]; then git commit -m "[skip ci] update README.md" fi - name: Run deploy tool run: | python3 .github/tools/deploy_to_space.py \ --mode="dev" \ --deployer="${{ github.actor }}" \ --branch_name="${{ github.ref_name }}" \ --username="${{ vars.HF_USERNAME }}" \ --user_token="${{ secrets.HF_TOKEN }}"21 unmodified lines222324252627281 unmodified line3031323321 unmodified linesfetch-depth: '0'- name: Update Repo README.mdrun: |python3 .github/tools/generate_readme.py > README.mdgit config --global user.email "github-actions[bot]@users.noreply.github.com"git config --global user.name "GitHub Actions[bot]"git add ./README.md1 unmodified linegit commit -m "[skip ci] update README.md"fi- name: Run deploy toolrun: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --username="${{ vars.HF_USERNAME }}" --user_token="${{ secrets.HF_TOKEN }}"21 unmodified lines222324252627281 unmodified line30313233343536373821 unmodified linesfetch-depth: '0'- name: Update Repo README.mdrun: |python3 .github/tools/generate_readme.py --mode="prod" > README.mdgit config --global user.email "github-actions[bot]@users.noreply.github.com"git config --global user.name "GitHub Actions[bot]"git add ./README.md1 unmodified linegit commit -m "[skip ci] update README.md"fi- name: Run deploy toolrun: |python3 .github/tools/deploy_to_space.py \--mode="prod" \--branch_name="${{ github.ref_name }}" \--username="${{ vars.HF_USERNAME }}" \--user_token="${{ secrets.HF_TOKEN }}"
.github/tools/config.py+36-3
.github/tools/deploy_to_space.py+17-3
.github/tools/generate_readme.py+23-2
.github/workflows/deploy-to-dev.yamlAdded+41
.github/workflows/deploy-to-production.yaml+7-2