File size: 971 Bytes
5b710ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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()
|