-
Notifications
You must be signed in to change notification settings - Fork 453
119 lines (110 loc) · 3.82 KB
/
demo.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: demo
on:
# Run 'test-demo' on every pull request to the main branch
pull_request:
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:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: ["3.10"]
framework: [tensorflow, pytorch]
steps:
- if: matrix.os == 'macos-latest'
name: Install MacOS prerequisites
run: brew install cairo pango gdk-pixbuf libffi
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: x64
- if: matrix.framework == 'tensorflow'
name: Cache python modules (TF)
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('demo/tf-requirements.txt') }}
- if: matrix.framework == 'pytorch'
name: Cache python modules (PT)
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('demo/pt-requirements.txt') }}
- if: matrix.framework == 'tensorflow'
name: Install dependencies (TF)
run: |
python -m pip install --upgrade pip
pip install -e .[tf,viz,html] --upgrade
pip install -r demo/tf-requirements.txt
- if: matrix.framework == 'pytorch'
name: Install dependencies (PT)
run: |
python -m pip install --upgrade pip
pip install -e .[torch,viz,html] --upgrade
pip install -r demo/pt-requirements.txt
- if: matrix.framework == 'tensorflow'
name: Run demo (TF)
env:
USE_TF: 1
run: |
streamlit --version
screen -dm streamlit run demo/app.py
sleep 10
curl http://localhost:8501/docs
- if: matrix.framework == 'pytorch'
name: Run demo (PT)
env:
USE_TORCH: 1
run: |
streamlit --version
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.10"]
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)
"