Unsterile nateraw commited on
Commit
a94a734
·
0 Parent(s):

Duplicate from nateraw/fuego

Browse files

Co-authored-by: Nate Raw <nateraw@users.noreply.huggingface.co>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +287 -0
  4. requirements.txt +3 -0
  5. style.css +3 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 🔥Fuego GitHub Script Runner🔥
3
+ emoji: 🔥
4
+ colorFrom: gray
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.17.0
8
+ app_file: app.py
9
+ pinned: true
10
+ license: apache-2.0
11
+ duplicated_from: nateraw/fuego
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gradio app to run fuego.github_run() on Hugging Face Spaces
2
+ # Hosted at https://hf.co/nateraw/fuego
3
+ import gradio as gr
4
+ import yaml
5
+
6
+ import fuego
7
+
8
+
9
+ def fuego_github_run_wrapper(
10
+ token,
11
+ github_repo_id,
12
+ github_repo_branch,
13
+ script,
14
+ requirements_file,
15
+ extra_requirements,
16
+ script_args,
17
+ output_dirs,
18
+ private,
19
+ delete_space_on_completion,
20
+ downgrade_hardware_on_completion,
21
+ space_hardware,
22
+ ):
23
+ if not token.strip():
24
+ return gr.update(
25
+ value="""## token with write access is required. Get one from <a href="https://hf.co/settings/tokens" target="_blank">here</a>""",
26
+ visible=True,
27
+ )
28
+
29
+ if script_args.strip():
30
+ script_args = yaml.safe_load(script_args)
31
+
32
+ if not requirements_file.strip():
33
+ requirements_file = None
34
+
35
+ if extra_requirements.strip():
36
+ extra_requirements = [x.strip() for x in extra_requirements.split("\n")]
37
+ else:
38
+ extra_requirements = None
39
+
40
+ if output_dirs.strip():
41
+ output_dirs = [x.strip() for x in output_dirs.split(",")]
42
+
43
+ github_repo_id = github_repo_id.strip()
44
+ if not github_repo_id:
45
+ return gr.update(value="## GitHub repo ID is required", visible=True)
46
+
47
+ script = script.strip()
48
+ if not script:
49
+ return gr.update(value="## script is required", visible=True)
50
+
51
+ github_repo_branch = github_repo_branch.strip()
52
+ if not github_repo_branch:
53
+ return gr.update("## github repo branch is required", visible=True)
54
+
55
+ space_url, dataset_url = fuego.github_run(
56
+ github_repo_id.strip(),
57
+ script.strip(),
58
+ requirements_file,
59
+ github_repo_branch,
60
+ space_hardware=space_hardware,
61
+ private=private,
62
+ delete_space_on_completion=delete_space_on_completion,
63
+ downgrade_hardware_on_completion=downgrade_hardware_on_completion,
64
+ space_output_dirs=output_dirs,
65
+ extra_requirements=extra_requirements,
66
+ token=token,
67
+ **script_args,
68
+ )
69
+ output_message = f"""
70
+ ## Job launched successfully! 🚀
71
+ - <a href="{space_url}" target="_blank">Link to Space</a>
72
+ - <a href="{dataset_url}" target="_blank">Link to Dataset</a>
73
+ """
74
+ return gr.update(value=output_message, visible=True)
75
+
76
+
77
+ description = """
78
+ This app lets you run scripts from GitHub on Spaces, using any hardware you'd like. Just point to a repo, the script you'd like to run, the dependencies to install, and any args to pass to your script, and watch it go. 😎
79
+
80
+ It uses 🔥[fuego](https://github.com/huggingface/fuego)🔥 under the hood to launch your script in one line of Python code. Give the repo a ⭐️ if you think its 🔥.
81
+
82
+ **Note: You'll need a Hugging Face token with write access, which you can get from [here](https://hf.co/settings/tokens)**
83
+ """
84
+
85
+ additional_info = """
86
+ ## Pricing
87
+
88
+ Runs using this tool are **free** as long as you use `cpu-basic` hardware. 🔥
89
+
90
+ **See pricing for accelerated hardware (anything other than `cpu-basic`) [here](https://hf.co/pricing#spaces)**
91
+
92
+ ## What this space does:
93
+ 1. Spins up 2 new HF repos for you: a "runner" space repo and an "output" dataset repo.
94
+ 2. Uploads your code to the space, as well as some wrapper code that invokes your script.
95
+ 3. Runs your code on the space via the wrapper. Logs should show up in the space.
96
+ 4. When the script is done, it takes anything saved to the `output_dirs` and uploads the files within to the output dataset repo
97
+ 5. Deletes the space (or downgrades, or just leaves on). Depends on your choice of `delete_space_on_completion` and `downgrade_hardware_on_completion`.
98
+
99
+ ## FAQ
100
+
101
+ - If your space ends up having a "no application file" issue, you may need to "factory reset" the space. You can do this from the settings page of the space.
102
+ """
103
+
104
+ output_message = gr.Markdown("", visible=False)
105
+
106
+ with gr.Blocks(css="style.css") as demo:
107
+ gr.Markdown("# 🔥Fuego🔥 GitHub Script Runner")
108
+ gr.Markdown(description)
109
+ with gr.Accordion("👀 More Details (Hardware Pricing, How it Works, and FAQ)", open=False):
110
+ gr.Markdown(additional_info)
111
+
112
+ with gr.Row():
113
+ token = gr.Textbox(lines=1, label="Hugging Face token with write access", type="password")
114
+
115
+ with gr.Row():
116
+ with gr.Column():
117
+ with gr.Box():
118
+ gr.Markdown("What script would you like to run? Also, what are its dependencies?")
119
+ github_repo_id = gr.Textbox(lines=1, label="GitHub repo ID (ex. huggingface/fuego)")
120
+ github_repo_branch = gr.Textbox(
121
+ lines=1, label="Branch of GitHub repo (ex. main)", value="main", interactive=True
122
+ )
123
+ script = gr.Textbox(lines=1, label="Path to python script in the GitHub repo")
124
+ requirements_file = gr.Textbox(lines=1, label="Path to pip requirements file in the repo")
125
+ extra_requirements = gr.Textbox(
126
+ lines=5,
127
+ label="Any extra pip requirements to your script, just as you would write them in requirements.txt",
128
+ )
129
+ with gr.Column():
130
+ with gr.Box():
131
+ gr.Markdown("How should we run your script?")
132
+ script_args = gr.Textbox(lines=10, label="Script args to your python file. Input here as YAML.")
133
+ spaces_output_dirs = gr.Textbox(
134
+ lines=1,
135
+ label="Name of output directory to save assets to from within your script. Use commas if you have multiple.",
136
+ value="./outputs, ./logs",
137
+ )
138
+ private = gr.Checkbox(False, label="Should space/dataset be made as private repos?")
139
+ delete_space_on_completion = gr.Checkbox(True, label="Delete the space on completion?")
140
+ downgrade_hardware_on_completion = gr.Checkbox(
141
+ True,
142
+ label="Downgrade hardware of the space on completion? Only applicable if not deleting on completion.",
143
+ )
144
+ with gr.Row():
145
+ with gr.Column():
146
+ spaces_hardware = gr.Dropdown(
147
+ ["cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large"],
148
+ label="Spaces Hardware",
149
+ value="cpu-basic",
150
+ interactive=True,
151
+ )
152
+ spaces_hardware_msg = gr.Markdown(
153
+ """
154
+ 🔴 **The hardware you chose is not free, and you will be charged for it** 🔴
155
+
156
+ If you want to run your script for free, please choose `cpu-basic` as your hardware.
157
+ """,
158
+ visible=False,
159
+ )
160
+ spaces_hardware.change(
161
+ lambda x: gr.update(visible=True) if x != "cpu-basic" else gr.update(visible=False),
162
+ inputs=[spaces_hardware],
163
+ outputs=[spaces_hardware_msg],
164
+ )
165
+
166
+ with gr.Row():
167
+ with gr.Accordion("👀 Examples", open=False):
168
+ gr.Examples(
169
+ [
170
+ [
171
+ "pytorch/examples",
172
+ "main",
173
+ "vae/main.py",
174
+ "vae/requirements.txt",
175
+ "",
176
+ "epochs: 3",
177
+ "./results",
178
+ False,
179
+ True,
180
+ True,
181
+ "cpu-basic",
182
+ ],
183
+ [
184
+ "huggingface/transformers",
185
+ "main",
186
+ "examples/pytorch/text-classification/run_glue.py",
187
+ "examples/pytorch/text-classification/requirements.txt",
188
+ "tensorboard\ngit+https://github.com/huggingface/transformers@main#egg=transformers",
189
+ "model_name_or_path: bert-base-cased\ntask_name: mrpc\ndo_train: True\ndo_eval: True\nmax_seq_length: 128\nper_device_train_batch_size: 32\nlearning_rate: 2e-5\nnum_train_epochs: 3\noutput_dir: ./outputs\nlogging_dir: ./logs\nlogging_steps: 20\nreport_to: tensorboard",
190
+ "./outputs,./logs",
191
+ False,
192
+ True,
193
+ True,
194
+ "cpu-basic",
195
+ ],
196
+ ],
197
+ inputs=[
198
+ github_repo_id,
199
+ github_repo_branch,
200
+ script,
201
+ requirements_file,
202
+ extra_requirements,
203
+ script_args,
204
+ spaces_output_dirs,
205
+ private,
206
+ delete_space_on_completion,
207
+ downgrade_hardware_on_completion,
208
+ spaces_hardware,
209
+ ],
210
+ outputs=[
211
+ github_repo_id,
212
+ github_repo_branch,
213
+ script,
214
+ requirements_file,
215
+ extra_requirements,
216
+ script_args,
217
+ spaces_output_dirs,
218
+ private,
219
+ delete_space_on_completion,
220
+ downgrade_hardware_on_completion,
221
+ spaces_hardware,
222
+ ],
223
+ cache_examples=False,
224
+ )
225
+
226
+ with gr.Row():
227
+ submit = gr.Button("Submit")
228
+ reset_btn = gr.Button("Reset fields")
229
+
230
+ with gr.Row():
231
+ output_message.render()
232
+
233
+ submit.click(
234
+ fuego_github_run_wrapper,
235
+ inputs=[
236
+ token,
237
+ github_repo_id,
238
+ github_repo_branch,
239
+ script,
240
+ requirements_file,
241
+ extra_requirements,
242
+ script_args,
243
+ spaces_output_dirs,
244
+ private,
245
+ delete_space_on_completion,
246
+ downgrade_hardware_on_completion,
247
+ spaces_hardware,
248
+ ],
249
+ outputs=[output_message],
250
+ )
251
+
252
+ def reset_fields():
253
+ return {
254
+ output_message: gr.update(value="", visible=False),
255
+ github_repo_id: gr.update(value=""),
256
+ github_repo_branch: gr.update(value="main"),
257
+ script: gr.update(value=""),
258
+ requirements_file: gr.update(value=""),
259
+ extra_requirements: gr.update(value=""),
260
+ script_args: gr.update(value=""),
261
+ spaces_output_dirs: gr.update(value="./outputs, ./logs"),
262
+ private: gr.update(value=False),
263
+ delete_space_on_completion: gr.update(value=True),
264
+ downgrade_hardware_on_completion: gr.update(value=True),
265
+ spaces_hardware: gr.update(value="cpu-basic"),
266
+ }
267
+
268
+ reset_btn.click(
269
+ reset_fields,
270
+ outputs=[
271
+ output_message,
272
+ github_repo_id,
273
+ github_repo_branch,
274
+ script,
275
+ requirements_file,
276
+ extra_requirements,
277
+ script_args,
278
+ spaces_output_dirs,
279
+ private,
280
+ delete_space_on_completion,
281
+ downgrade_hardware_on_completion,
282
+ spaces_hardware,
283
+ ],
284
+ )
285
+
286
+ if __name__ == "__main__":
287
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ PyYAML
3
+ fuego==0.0.8
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ }