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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gradio app to run fuego.github_run() on Hugging Face Spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import yaml
|
| 4 |
+
|
| 5 |
+
import fuego
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def fuego_github_run_wrapper(
|
| 9 |
+
token,
|
| 10 |
+
github_repo_id,
|
| 11 |
+
github_repo_branch,
|
| 12 |
+
script,
|
| 13 |
+
requirements_file,
|
| 14 |
+
extra_requirements,
|
| 15 |
+
output_dirs,
|
| 16 |
+
script_args,
|
| 17 |
+
space_hardware,
|
| 18 |
+
private,
|
| 19 |
+
delete_space_on_completion,
|
| 20 |
+
downgrade_hardware_on_completion,
|
| 21 |
+
extra_run_metadata,
|
| 22 |
+
):
|
| 23 |
+
if not token.strip():
|
| 24 |
+
return "token with write access is required. Get one from https://hf.co/settings/tokens", "", ""
|
| 25 |
+
if script_args.strip():
|
| 26 |
+
script_args = yaml.safe_load(script_args)
|
| 27 |
+
if extra_run_metadata.strip():
|
| 28 |
+
extra_run_metadata = yaml.safe_load(extra_run_metadata)
|
| 29 |
+
|
| 30 |
+
if not requirements_file.strip():
|
| 31 |
+
requirements_file = None
|
| 32 |
+
|
| 33 |
+
if extra_requirements.strip():
|
| 34 |
+
extra_requirements = [x.strip() for x in extra_requirements.split("\n")]
|
| 35 |
+
else:
|
| 36 |
+
extra_requirements = None
|
| 37 |
+
|
| 38 |
+
if output_dirs.strip():
|
| 39 |
+
output_dirs = [x.strip() for x in output_dirs.split(",")]
|
| 40 |
+
|
| 41 |
+
github_repo_id = github_repo_id.strip()
|
| 42 |
+
if not github_repo_id:
|
| 43 |
+
return "GitHub repo ID is required", "", ""
|
| 44 |
+
|
| 45 |
+
script = script.strip()
|
| 46 |
+
if not script:
|
| 47 |
+
return "script is required", "", ""
|
| 48 |
+
|
| 49 |
+
github_repo_branch = github_repo_branch.strip()
|
| 50 |
+
if not github_repo_branch:
|
| 51 |
+
return "github repo branch is required", "", ""
|
| 52 |
+
|
| 53 |
+
space_url, dataset_url = fuego.github_run(
|
| 54 |
+
github_repo_id.strip(),
|
| 55 |
+
script.strip(),
|
| 56 |
+
requirements_file,
|
| 57 |
+
github_repo_branch,
|
| 58 |
+
space_hardware=space_hardware,
|
| 59 |
+
private=private,
|
| 60 |
+
delete_space_on_completion=delete_space_on_completion,
|
| 61 |
+
downgrade_hardware_on_completion=downgrade_hardware_on_completion,
|
| 62 |
+
space_output_dirs=output_dirs,
|
| 63 |
+
extra_run_metadata=extra_run_metadata,
|
| 64 |
+
extra_requirements=extra_requirements,
|
| 65 |
+
token=token,
|
| 66 |
+
**script_args,
|
| 67 |
+
)
|
| 68 |
+
return "Launched Successfully!", space_url, dataset_url
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
examples = [
|
| 72 |
+
[
|
| 73 |
+
"",
|
| 74 |
+
"pytorch/examples",
|
| 75 |
+
"main",
|
| 76 |
+
"vae/main.py",
|
| 77 |
+
"vae/requirements.txt",
|
| 78 |
+
"",
|
| 79 |
+
"./results",
|
| 80 |
+
"epochs: 3",
|
| 81 |
+
"cpu-basic",
|
| 82 |
+
False,
|
| 83 |
+
True,
|
| 84 |
+
True,
|
| 85 |
+
"",
|
| 86 |
+
],
|
| 87 |
+
[
|
| 88 |
+
"",
|
| 89 |
+
"huggingface/transformers",
|
| 90 |
+
"main",
|
| 91 |
+
"examples/pytorch/text-classification/run_glue.py",
|
| 92 |
+
"examples/pytorch/text-classification/requirements.txt",
|
| 93 |
+
"tensorboard\ngit+https://github.com/huggingface/transformers@main#egg=transformers",
|
| 94 |
+
"./outputs,./logs",
|
| 95 |
+
"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",
|
| 96 |
+
"cpu-basic",
|
| 97 |
+
False,
|
| 98 |
+
True,
|
| 99 |
+
True,
|
| 100 |
+
"",
|
| 101 |
+
],
|
| 102 |
+
]
|
| 103 |
+
description = """
|
| 104 |
+
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. 😎
|
| 105 |
+
|
| 106 |
+
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 🔥.
|
| 107 |
+
|
| 108 |
+
**Note: You'll need a Hugging Face token with write access, which you can get from [here](https://hf.co/settings/tokens)**
|
| 109 |
+
|
| 110 |
+
## Pricing
|
| 111 |
+
|
| 112 |
+
Runs using this tool are **free** as long as you use `cpu-basic` hardware. 🔥
|
| 113 |
+
|
| 114 |
+
**See pricing for accelerated hardware (anything other than `cpu-basic`) [here](https://hf.co/pricing#spaces)**
|
| 115 |
+
|
| 116 |
+
## What this space does:
|
| 117 |
+
1. Spins up 2 new HF repos for you: a "runner" space repo and an "output" dataset repo.
|
| 118 |
+
2. Uploads your code to the space, as well as some wrapper code that invokes your script.
|
| 119 |
+
3. Runs your code on the space via the wrapper. Logs should show up in the space.
|
| 120 |
+
4. When the script is done, it takes anything saved to the `output_dirs` and uploads the files within to the output dataset repo
|
| 121 |
+
5. Deletes the space (or downgrades, or just leaves on). Depends on your choice of `delete_space_on_completion` and `downgrade_hardware_on_completion`.
|
| 122 |
+
|
| 123 |
+
## Notes
|
| 124 |
+
|
| 125 |
+
- 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.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
interface = gr.Interface(
|
| 129 |
+
fuego_github_run_wrapper,
|
| 130 |
+
inputs=[
|
| 131 |
+
gr.Textbox(lines=1, placeholder="Hugging Face token with write access", type="password"),
|
| 132 |
+
gr.Textbox(lines=1, placeholder="Source code GitHub repo ID (ex. huggingface/fuego)"),
|
| 133 |
+
gr.Textbox(lines=1, placeholder="Branch of GitHub repo (ex. main)", value="main"),
|
| 134 |
+
gr.Textbox(lines=1, placeholder="Path to python script in the GitHub repo"),
|
| 135 |
+
gr.Textbox(lines=1, placeholder="Path to pip requirements file in the repo"),
|
| 136 |
+
gr.Textbox(
|
| 137 |
+
lines=5,
|
| 138 |
+
placeholder="Any extra pip requirements to your script, just as you would write them in requirements.txt",
|
| 139 |
+
),
|
| 140 |
+
gr.Textbox(
|
| 141 |
+
lines=1,
|
| 142 |
+
placeholder="Name of output directory to save assets to from within your script. Use commas if you have multiple.",
|
| 143 |
+
value="./outputs, ./logs",
|
| 144 |
+
),
|
| 145 |
+
gr.Textbox(lines=10, placeholder="Script args to your python file. Input here as YAML."),
|
| 146 |
+
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 |
+
),
|
| 151 |
+
gr.Checkbox(False, label="Should space/dataset be made as private repos?"),
|
| 152 |
+
gr.Checkbox(True, label="Delete the space on completion?"),
|
| 153 |
+
gr.Checkbox(
|
| 154 |
+
True, label="Downgrade hardware of the space on completion? Only applicable if not deleting on completion."
|
| 155 |
+
),
|
| 156 |
+
gr.Textbox(
|
| 157 |
+
lines=5,
|
| 158 |
+
placeholder="Any extra metadata (input as YAML) you would like to store within the run's metadata (found in dataset card).",
|
| 159 |
+
),
|
| 160 |
+
],
|
| 161 |
+
outputs=[
|
| 162 |
+
gr.Textbox(label="Message"),
|
| 163 |
+
gr.Textbox(label="Runner Space URL"),
|
| 164 |
+
gr.Textbox(label="Output Dataset URL"),
|
| 165 |
+
],
|
| 166 |
+
title="🔥Fuego🔥 GitHub Script Runner",
|
| 167 |
+
description=description,
|
| 168 |
+
examples=examples,
|
| 169 |
+
cache_examples=False,
|
| 170 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
PyYAML
|
| 3 |
+
git+https://github.com/huggingface/fuego@main#egg=fuego
|