| import gradio as gr |
| from huggingface_hub import HfApi |
|
|
| hfapi = HfApi() |
|
|
|
|
| def run(space_id: str, token: str, factory_reboot: bool = False): |
| try: |
| res = hfapi.restart_space( |
| space_id, |
| token=token, |
| factory_reboot=factory_reboot, |
| ) |
| msg = f"Restart space [{space_id}] successfully\n" + res.__str__() |
| print(msg) |
| return True, msg |
| except Exception as e: |
| msg = f"Restart space [{space_id}] failed. {type(e)}: {e}\n" |
| print(msg) |
| return False, msg |
|
|
|
|
| demo = gr.Interface( |
| fn=run, |
| inputs=[ |
| gr.Textbox(placeholder="userid/spaceid", label="Space ID"), |
| gr.Textbox( |
| placeholder="Token with write access", |
| label="Token", |
| ), |
| gr.Checkbox(label="Factory Reboot", value=False), |
| ], |
| outputs=[ |
| gr.Textbox(label="Result"), |
| gr.Textbox(label="Detail"), |
| ], |
| allow_flagging="never", |
| ) |
|
|
| demo.launch() |
|
|