diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 0fc7f203ff..ad5a1045b3 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -1,10 +1,23 @@ name: demo on: - push: - branches: main + # Run 'test-demo' on every pull request to the main branch pull_request: - branches: main + branches: [main] + + # Run 'test-demo' on every push to the main branch or both jobs when a new version tag is pushed + push: + branches: + - main + tags: + - 'v*' + + # Run 'sync-to-hub' on a scheduled cron job + schedule: + - cron: '0 2 10 * *' # At 02:00 on day-of-month 10 (every month) + + # Allow manual triggering of the workflow + workflow_dispatch: jobs: test-demo: @@ -69,3 +82,38 @@ jobs: screen -dm streamlit run demo/app.py sleep 10 curl http://localhost:8501/docs + + # This job only runs when a new version tag is pushed or during the cron job or when manually triggered + sync-to-hub: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + needs: test-demo + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python: ["3.9"] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + architecture: x64 + - name: Install huggingface_hub + run: pip install huggingface-hub + - name: Upload folder to Hugging Face + # Only keep the requirements.txt file for the demo (PyTorch) + run: | + mv demo/pt-requirements.txt demo/requirements.txt + rm demo/tf-requirements.txt + + python -c " + from huggingface_hub import HfApi + api = HfApi(token='${{ secrets.HF_TOKEN }}') + repo_id = 'mindee/doctr' + api.upload_folder(repo_id=repo_id, repo_type='space', folder_path='demo/') + api.restart_space(repo_id=repo_id, factory_reboot=True) + " diff --git a/demo/README.md b/demo/README.md new file mode 100644 index 0000000000..ec653d3068 --- /dev/null +++ b/demo/README.md @@ -0,0 +1,47 @@ +--- +title: docTR +emoji: 📑 +colorFrom: purple +colorTo: pink +sdk: streamlit +sdk_version: 1.39.0 +app_file: app.py +pinned: false +license: apache-2.0 +--- + +## Configuration + +`title`: _string_ +Display title for the Space + +`emoji`: _string_ +Space emoji (emoji-only character allowed) + +`colorFrom`: _string_ +Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray) + +`colorTo`: _string_ +Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray) + +`sdk`: _string_ +Can be either `gradio` or `streamlit` + +`sdk_version` : _string_ +Only applicable for `streamlit` SDK. +See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions. + +`app_file`: _string_ +Path to your main application file (which contains either `gradio` or `streamlit` Python code). +Path is relative to the root of the repository. + +`pinned`: _boolean_ +Whether the Space stays on top of your list. + +## Run the demo locally + +```bash +cd demo +pip install -r pt-requirements.txt +streamlit run app.py +``` diff --git a/demo/packages.txt b/demo/packages.txt new file mode 100644 index 0000000000..d0f1245c6f --- /dev/null +++ b/demo/packages.txt @@ -0,0 +1 @@ +python3-opencv