Skip to content

Commit 59f1c30

Browse files
[demo] Automate doctr demo update via CI job (#1742)
1 parent 90c3fff commit 59f1c30

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

.github/workflows/demo.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
name: demo
22

33
on:
4-
push:
5-
branches: main
4+
# Run 'test-demo' on every pull request to the main branch
65
pull_request:
7-
branches: main
6+
branches: [main]
7+
8+
# Run 'test-demo' on every push to the main branch or both jobs when a new version tag is pushed
9+
push:
10+
branches:
11+
- main
12+
tags:
13+
- 'v*'
14+
15+
# Run 'sync-to-hub' on a scheduled cron job
16+
schedule:
17+
- cron: '0 2 10 * *' # At 02:00 on day-of-month 10 (every month)
18+
19+
# Allow manual triggering of the workflow
20+
workflow_dispatch:
821

922
jobs:
1023
test-demo:
@@ -69,3 +82,38 @@ jobs:
6982
screen -dm streamlit run demo/app.py
7083
sleep 10
7184
curl http://localhost:8501/docs
85+
86+
# This job only runs when a new version tag is pushed or during the cron job or when manually triggered
87+
sync-to-hub:
88+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
89+
needs: test-demo
90+
runs-on: ${{ matrix.os }}
91+
strategy:
92+
fail-fast: false
93+
matrix:
94+
os: [ubuntu-latest]
95+
python: ["3.9"]
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0
100+
- name: Set up Python
101+
uses: actions/setup-python@v5
102+
with:
103+
python-version: ${{ matrix.python }}
104+
architecture: x64
105+
- name: Install huggingface_hub
106+
run: pip install huggingface-hub
107+
- name: Upload folder to Hugging Face
108+
# Only keep the requirements.txt file for the demo (PyTorch)
109+
run: |
110+
mv demo/pt-requirements.txt demo/requirements.txt
111+
rm demo/tf-requirements.txt
112+
113+
python -c "
114+
from huggingface_hub import HfApi
115+
api = HfApi(token='${{ secrets.HF_TOKEN }}')
116+
repo_id = 'mindee/doctr'
117+
api.upload_folder(repo_id=repo_id, repo_type='space', folder_path='demo/')
118+
api.restart_space(repo_id=repo_id, factory_reboot=True)
119+
"

demo/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: docTR
3+
emoji: 📑
4+
colorFrom: purple
5+
colorTo: pink
6+
sdk: streamlit
7+
sdk_version: 1.39.0
8+
app_file: app.py
9+
pinned: false
10+
license: apache-2.0
11+
---
12+
13+
## Configuration
14+
15+
`title`: _string_
16+
Display title for the Space
17+
18+
`emoji`: _string_
19+
Space emoji (emoji-only character allowed)
20+
21+
`colorFrom`: _string_
22+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
23+
24+
`colorTo`: _string_
25+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
26+
27+
`sdk`: _string_
28+
Can be either `gradio` or `streamlit`
29+
30+
`sdk_version` : _string_
31+
Only applicable for `streamlit` SDK.
32+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
33+
34+
`app_file`: _string_
35+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
36+
Path is relative to the root of the repository.
37+
38+
`pinned`: _boolean_
39+
Whether the Space stays on top of your list.
40+
41+
## Run the demo locally
42+
43+
```bash
44+
cd demo
45+
pip install -r pt-requirements.txt
46+
streamlit run app.py
47+
```

demo/packages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python3-opencv

0 commit comments

Comments
 (0)