Spaces:
Runtime error
Runtime error
Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
@@ -13,20 +13,21 @@ def fuego_github_run_wrapper(
|
|
13 |
script,
|
14 |
requirements_file,
|
15 |
extra_requirements,
|
16 |
-
output_dirs,
|
17 |
script_args,
|
18 |
-
|
19 |
private,
|
20 |
delete_space_on_completion,
|
21 |
downgrade_hardware_on_completion,
|
22 |
-
|
23 |
):
|
24 |
if not token.strip():
|
25 |
-
return
|
|
|
|
|
|
|
|
|
26 |
if script_args.strip():
|
27 |
script_args = yaml.safe_load(script_args)
|
28 |
-
if extra_run_metadata.strip():
|
29 |
-
extra_run_metadata = yaml.safe_load(extra_run_metadata)
|
30 |
|
31 |
if not requirements_file.strip():
|
32 |
requirements_file = None
|
@@ -41,15 +42,15 @@ def fuego_github_run_wrapper(
|
|
41 |
|
42 |
github_repo_id = github_repo_id.strip()
|
43 |
if not github_repo_id:
|
44 |
-
return "GitHub repo ID is required",
|
45 |
|
46 |
script = script.strip()
|
47 |
if not script:
|
48 |
-
return "script is required",
|
49 |
|
50 |
github_repo_branch = github_repo_branch.strip()
|
51 |
if not github_repo_branch:
|
52 |
-
return "github repo branch is required",
|
53 |
|
54 |
space_url, dataset_url = fuego.github_run(
|
55 |
github_repo_id.strip(),
|
@@ -61,53 +62,27 @@ def fuego_github_run_wrapper(
|
|
61 |
delete_space_on_completion=delete_space_on_completion,
|
62 |
downgrade_hardware_on_completion=downgrade_hardware_on_completion,
|
63 |
space_output_dirs=output_dirs,
|
64 |
-
extra_run_metadata=extra_run_metadata,
|
65 |
extra_requirements=extra_requirements,
|
66 |
token=token,
|
67 |
**script_args,
|
68 |
)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
"vae/main.py",
|
78 |
-
"vae/requirements.txt",
|
79 |
-
"",
|
80 |
-
"./results",
|
81 |
-
"epochs: 3",
|
82 |
-
"cpu-basic",
|
83 |
-
False,
|
84 |
-
True,
|
85 |
-
True,
|
86 |
-
"",
|
87 |
-
],
|
88 |
-
[
|
89 |
-
"",
|
90 |
-
"huggingface/transformers",
|
91 |
-
"main",
|
92 |
-
"examples/pytorch/text-classification/run_glue.py",
|
93 |
-
"examples/pytorch/text-classification/requirements.txt",
|
94 |
-
"tensorboard\ngit+https://github.com/huggingface/transformers@main#egg=transformers",
|
95 |
-
"./outputs,./logs",
|
96 |
-
"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",
|
97 |
-
"cpu-basic",
|
98 |
-
False,
|
99 |
-
True,
|
100 |
-
True,
|
101 |
-
"",
|
102 |
-
],
|
103 |
-
]
|
104 |
description = """
|
105 |
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. 😎
|
106 |
|
107 |
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 🔥.
|
108 |
|
109 |
**Note: You'll need a Hugging Face token with write access, which you can get from [here](https://hf.co/settings/tokens)**
|
|
|
110 |
|
|
|
111 |
## Pricing
|
112 |
|
113 |
Runs using this tool are **free** as long as you use `cpu-basic` hardware. 🔥
|
@@ -121,51 +96,192 @@ Runs using this tool are **free** as long as you use `cpu-basic` hardware. 🔥
|
|
121 |
4. When the script is done, it takes anything saved to the `output_dirs` and uploads the files within to the output dataset repo
|
122 |
5. Deletes the space (or downgrades, or just leaves on). Depends on your choice of `delete_space_on_completion` and `downgrade_hardware_on_completion`.
|
123 |
|
124 |
-
##
|
125 |
|
126 |
- 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.
|
127 |
"""
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
gr.
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
gr.
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
gr.
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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(),
|
|
|
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. 🔥
|
|
|
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)
|
style.css
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
}
|