File size: 6,438 Bytes
0fc235e
 
 
 
 
 
 
 
 
ac36ca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fc235e
 
a7bfafd
0fc235e
 
 
 
8eab4b3
a7bfafd
 
 
8eab4b3
a7bfafd
de95380
a7bfafd
 
 
 
 
8eab4b3
a7bfafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b50e943
0fc235e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b50e943
0fc235e
 
 
 
 
 
 
 
 
 
de95380
0fc235e
 
 
 
 
 
 
 
 
ac36ca5
 
 
0fc235e
ac36ca5
0fc235e
ac36ca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fc235e
ac36ca5
 
 
0fc235e
 
 
 
ac36ca5
 
 
0fc235e
 
 
 
ac36ca5
0fc235e
 
 
 
 
b50e943
0fc235e
 
 
ac36ca5
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
title: Gradio Space CI
emoji: πŸ€–
colorFrom: gray
colorTo: gray
sdk: gradio
sdk_version: 4.7.1
app_file: app.py
pinned: false
space_ci:
   trusted_authors:
      - clefourrier
      # ^ Only PRs from trusted authors are deployed in an ephemeral Space.
      # Space owners are automatically trusted.
      # It is possible to manually trust other authors by adding them as a list.
   private: auto
      # ^ Can be 'true', 'false' or 'auto'. If 'auto', the ephemeral Spaces will have same
      # visibility as the main Space.
   variables: auto
      # ^ By default ('auto'), all variables from the main Space are copied to the ephemeral Space.
      # Otherwise, you can define a key-value mapping with variables to set.
      # Variables are injected as environment variable in the ephemeral Space and are public for anyone landing on the Space.
   secrets:
      - HF_TOKEN
      # ^ A list of secrets that must be copied from the main Space to the ephemeral Spaces.
      # Secrets are injected as environment variable in the ephemeral Space.
      # Be careful with the 'trusted_authors' list when setting secrets. 
   hardware: cpu-basic
      # ^ Defines which hardware to assign to the ephemeral Space.
      # Can be set to 'auto' to assign the same hardware as the main Space.
      # Defaults to 'cpu-basic' (free).
   storage: null
      # ^ Defines which storage to assign to the ephemeral Space.
      # Can be set to 'auto' to assign the same storage as the main Space.
      # Defaults to no storage (free).
---

# Listen to Pull Requests and start ephemeral Spaces on new PRs! πŸš€

**Gradio Space CI** is a plugin (and package) to create ephemeral Spaces for each PR opened on your Space repo.
The goal is to foster community contributions by making the review process as lean as possible.

## ⚑ Quick start (4 steps)

1. Update your requirements.

```py
# requirements.txt
gradio-space-ci @ git+https://huggingface.co/spaces/Wauplin/gradio-space-ci@0.2.1
```

2. Set `HF_TOKEN` as a Space secret.
3. Configure CI in your `README.md`.

```py
# README.md
title: ...
emoji: ...
sdk: gradio
space_ci:
   trusted_authors:
      - clefourrier
   secrets:
      - HF_TOKEN
   hardware: cpu-basic
   storage: null
```

4. Enable CI in `app.py`.

```py
# app.py
from gradio_space_ci import enable_space_ci

enable_space_ci()
```

And that's it! For more details, check out the [integration](#integration) section.

## ✨ Key features

1. **Listen to Pull Requests**.
2. **Launch ephemeral Spaces** on new PRs.
   1. When a commit is pushed to a PR, the ephemeral Space gets synchronized.
   2. When the PR is closed, the ephemeral Space is deleted.
3. Configure ephemeral Spaces automatically
   1. All **variables** are copied from the main Space.
   2. **Secrets** are copied from the main Space, based on CI configuration.
   3. **Hardware** and **storage** are set, based on CI configuration.
4. Only **trusted authors** are able to access secrets
   1. By default, repo owners are trusted authors
   2. More authors can be added in CI configuration
   3. untrusted authors can start ephemeral Space but without secrets or custom hardware

Want more? Please open an issue in the [Community Tab](https://huggingface.co/spaces/Wauplin/gradio-space-ci/discussions)! This is meant to be a community-driven implementation, enhanced by user feedback and contributions!

## βš™οΈ Integration

Integrate *Gradio Space CI* in just a few steps:

### 1. Update your `requirements.txt`

If you don't have a `requirements.txt` file yet, create one in your Space repo.
Add the following line to it:

```bash
# requirements.txt
gradio-space-ci @ git+https://huggingface.co/spaces/Wauplin/gradio-space-ci@0.2.1
```

### 2. Add a user token as `HF_TOKEN` secret

1. Go to your [user settings page](https://huggingface.co/settings/tokens).
2. Create a new token with **write** permissions.
3. Go to your Space settings page.
4. Add `HF_TOKEN` as a Space secret with your newly created token.

(optional) You can also define a `SPACE_CI_SECRET` secret value that will be used to authenticate webhook calls. If you don't define one, a random secret value will be generated for you.

### 3. Configure CI in `README.md`

Edit the Space metadata in your `README.md` file:

```yaml
title: ...
sdk: gradio
sdk_version: ...
app_file: ...
space_ci:
   trusted_authors:
      - Wauplin
      # ^ Only PRs from trusted authors are deployed in an ephemeral Space.
      # Space owners are automatically trusted.
      # It is possible to manually trust other authors by adding them as a list.
   private: auto
      # ^ Can be 'true', 'false' or 'auto'. If 'auto', the ephemeral Spaces will have same
      # visibility as the main Space.
   variables: auto
      # ^ By default ('auto'), all variables from the main Space are copied to the ephemeral Space.
      # Otherwise, you can define a key-value mapping with variables to set.
      # Variables are injected as environment variable in the ephemeral Space and are public for anyone landing on the Space.
   secrets:
      - HF_TOKEN
      # ^ A list of secrets that must be copied from the main Space to the ephemeral Spaces.
      # Secrets are injected as environment variable in the ephemeral Space.
      # Be careful with the 'trusted_authors' list when setting secrets. 
   hardware: cpu-basic
      # ^ Defines which hardware to assign to the ephemeral Space.
      # Can be set to 'auto' to assign the same hardware as the main Space.
      # Defaults to 'cpu-basic' (free).
   storage: null
      # ^ Defines which storage to assign to the ephemeral Space.
      # Can be set to 'auto' to assign the same storage as the main Space.
      # Defaults to no storage (free).
```

### 4. Enable CI in `app.py`

Call `enable_space_ci` in your `app.py` file:

```py
# app.py
import gradio as gr
from gradio_space_ci import enable_space_ci

enable_space_ci()

# ANY gradio app
with gr.Blocks() as demo:
    ...
demo.launch()
```

And you're done! Ephemeral Spaces will be launched for each and every PR on your repo.


## πŸ”— Useful links

- **Demo:** https://huggingface.co/spaces/Wauplin/gradio-space-ci
- **README:** https://huggingface.co/spaces/Wauplin/gradio-space-ci/blob/main/README.md
- **Questions and feedback:** https://huggingface.co/spaces/Wauplin/gradio-space-ci/discussions
- **Release notes:** https://huggingface.co/spaces/Wauplin/gradio-space-ci/blob/main/RELEASE.md