# Gradio app to run fuego.github_run() on Hugging Face Spaces # Hosted at https://hf.co/nateraw/fuego # Github clone mods - https://github.com/AaronCWacker/-Fuego-AutoMagiGit- import gradio as gr import yaml import fuego title="""### 🔥Fuego🔥 💻🌟 AutoMagiGit 🌟💻 - Unleash Power of GitHub!""" description = """ ### 🌟 **Overview** 🌟 - 🚀 Launch GitHub script Run on Spaces Using your [Token!](https://huggingface.co/settings/tokens). - 🧰 Choose [Hardware](https://huggingface.co/pricing#spaces), set the scene, and ignite! - 🔗 Uses 🔥 [Fuego](https://github.com/huggingface/fuego) 🔥. Star it! ⭐ """ additional_info = """ ### 💲 **Pricing Details** 💲 - 🆓 Free on `cpu-basic`. - 💻 Scalable Hardware? - Spaces Hardware Has It All! Check It [Here](https://hf.co/pricing#spaces). ### 🛠️ **How It Works** 🧩 | Step | 🎬 Action | 📖 Description | | ---- | ------ | ----------- | | 1️⃣ | 🌱 Create Repos | Sets up "runner" and "output" repos. | | 2️⃣ | 🚚 Upload Code | Uploads and prepares your script. | | 3️⃣ | 🔥 Execute | Runs your script, tracks logs. | ### ❓ **Quick FAQs** ❓ - 🤷 "No app.py file"? Try a reset in space settings. """ def fuego_github_run_wrapper( token, github_repo_id, github_repo_branch, script, requirements_file, extra_requirements, script_args, output_dirs, private, delete_space_on_completion, downgrade_hardware_on_completion, space_hardware, ): if not token.strip(): return gr.update( value="""## token with write access is required. Get one from here""", visible=True, ) if script_args.strip(): script_args = yaml.safe_load(script_args) if not requirements_file.strip(): requirements_file = None if extra_requirements.strip(): extra_requirements = [x.strip() for x in extra_requirements.split("\n")] else: extra_requirements = None if output_dirs.strip(): output_dirs = [x.strip() for x in output_dirs.split(",")] github_repo_id = github_repo_id.strip() if not github_repo_id: return gr.update(value="## GitHub repo ID is required", visible=True) script = script.strip() if not script: return gr.update(value="## script is required", visible=True) github_repo_branch = github_repo_branch.strip() if not github_repo_branch: return gr.update("## github repo branch is required", visible=True) space_url, dataset_url = fuego.github_run( github_repo_id.strip(), script.strip(), requirements_file, github_repo_branch, space_hardware=space_hardware, private=private, delete_space_on_completion=delete_space_on_completion, downgrade_hardware_on_completion=downgrade_hardware_on_completion, space_output_dirs=output_dirs, extra_requirements=extra_requirements, token=token, **script_args, ) output_message = f""" ## Job launched successfully! 🚀 - Link to Space - Link to Dataset """ return gr.update(value=output_message, visible=True) output_message = gr.Markdown("", visible=False) with gr.Blocks(css="style.css") as demo: gr.Markdown(title) gr.Markdown(description) with gr.Accordion("👀 Details (Hardware, How it Works, FAQ)", open=False): gr.Markdown(additional_info) with gr.Row(): token = gr.Textbox(lines=1, label="Hugging Face token with write access", type="password") with gr.Row(): with gr.Column(): with gr.Box(): gr.Markdown("What script would you like to run? Also, what are its dependencies?") github_repo_id = gr.Textbox(lines=1, label="GitHub repo ID (ex. huggingface/fuego)") github_repo_branch = gr.Textbox( lines=1, label="Branch of GitHub repo (ex. main)", value="main", interactive=True ) script = gr.Textbox(lines=1, label="Path to python script in the GitHub repo") requirements_file = gr.Textbox(lines=1, label="Path to pip requirements file in the repo") extra_requirements = gr.Textbox( lines=5, label="Any extra pip requirements to your script, just as you would write them in requirements.txt", ) with gr.Column(): with gr.Box(): gr.Markdown("How should we run your script?") script_args = gr.Textbox(lines=10, label="Script args to your python file. Input here as YAML.") spaces_output_dirs = gr.Textbox( lines=1, label="Name of output directory to save assets to from within your script. Use commas if you have multiple.", value="./outputs, ./logs", ) private = gr.Checkbox(False, label="Should space/dataset be made as private repos?") delete_space_on_completion = gr.Checkbox(True, label="Delete the space on completion?") downgrade_hardware_on_completion = gr.Checkbox( True, label="Downgrade hardware of the space on completion? Only applicable if not deleting on completion.", ) with gr.Row(): with gr.Column(): spaces_hardware = gr.Dropdown( ["cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large"], label="Spaces Hardware", value="cpu-basic", interactive=True, ) spaces_hardware_msg = gr.Markdown( """ 🔴 **The hardware you chose is not free, and you will be charged for it** 🔴 If you want to run your script for free, please choose `cpu-basic` as your hardware. """, visible=False, ) spaces_hardware.change( lambda x: gr.update(visible=True) if x != "cpu-basic" else gr.update(visible=False), inputs=[spaces_hardware], outputs=[spaces_hardware_msg], ) with gr.Row(): with gr.Accordion("👀 Examples", open=False): gr.Examples( [ [ "pytorch/examples", "main", "vae/main.py", "vae/requirements.txt", "", "epochs: 3", "./results", False, True, True, "cpu-basic", ], [ "huggingface/transformers", "main", "examples/pytorch/text-classification/run_glue.py", "examples/pytorch/text-classification/requirements.txt", "tensorboard\ngit+https://github.com/huggingface/transformers@main#egg=transformers", "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", "./outputs,./logs", False, True, True, "cpu-basic", ], ], inputs=[ github_repo_id, github_repo_branch, script, requirements_file, extra_requirements, script_args, spaces_output_dirs, private, delete_space_on_completion, downgrade_hardware_on_completion, spaces_hardware, ], outputs=[ github_repo_id, github_repo_branch, script, requirements_file, extra_requirements, script_args, spaces_output_dirs, private, delete_space_on_completion, downgrade_hardware_on_completion, spaces_hardware, ], cache_examples=False, ) with gr.Row(): submit = gr.Button("Submit") reset_btn = gr.Button("Reset fields") with gr.Row(): output_message.render() submit.click( fuego_github_run_wrapper, inputs=[ token, github_repo_id, github_repo_branch, script, requirements_file, extra_requirements, script_args, spaces_output_dirs, private, delete_space_on_completion, downgrade_hardware_on_completion, spaces_hardware, ], outputs=[output_message], ) def reset_fields(): return { output_message: gr.update(value="", visible=False), github_repo_id: gr.update(value=""), github_repo_branch: gr.update(value="main"), script: gr.update(value=""), requirements_file: gr.update(value=""), extra_requirements: gr.update(value=""), script_args: gr.update(value=""), spaces_output_dirs: gr.update(value="./outputs, ./logs"), private: gr.update(value=False), delete_space_on_completion: gr.update(value=True), downgrade_hardware_on_completion: gr.update(value=True), spaces_hardware: gr.update(value="cpu-basic"), } reset_btn.click( reset_fields, outputs=[ output_message, github_repo_id, github_repo_branch, script, requirements_file, extra_requirements, script_args, spaces_output_dirs, private, delete_space_on_completion, downgrade_hardware_on_completion, spaces_hardware, ], ) if __name__ == "__main__": demo.launch(debug=True)