Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,34 @@ if is_gpu_associated:
|
|
20 |
else:
|
21 |
which_gpu = "CPU"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def set_accelerate_default_config():
|
24 |
try:
|
25 |
subprocess.run(["accelerate", "config", "default"], check=True)
|
@@ -84,6 +112,13 @@ def main(dataset_id,
|
|
84 |
checkpoint_steps,
|
85 |
remove_gpu):
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
if dataset_id == "":
|
88 |
raise gr.Error("You forgot to specify an image dataset")
|
89 |
|
@@ -92,12 +127,10 @@ def main(dataset_id,
|
|
92 |
|
93 |
if lora_trained_xl_folder == "":
|
94 |
raise gr.Error("You forgot to name the output folder for your model")
|
95 |
-
|
96 |
-
if is_shared_ui:
|
97 |
-
raise gr.Error("This Space only works in duplicated instances")
|
98 |
|
99 |
-
|
100 |
-
|
|
|
101 |
|
102 |
gr.Warning("Training is ongoing ⌛... You can close this tab if you like or just wait.")
|
103 |
gr.Warning("If you did not check the `Remove GPU After training`, don't forget to remove the GPU attribution after you are done. ")
|
|
|
20 |
else:
|
21 |
which_gpu = "CPU"
|
22 |
|
23 |
+
def swap_hardware(hf_token, hardware="cpu-basic"):
|
24 |
+
hardware_url = f"https://huggingface.co/spaces/{os.environ['SPACE_ID']}/hardware"
|
25 |
+
headers = { "authorization" : f"Bearer {hf_token}"}
|
26 |
+
body = {'flavor': hardware}
|
27 |
+
requests.post(hardware_url, json = body, headers=headers)
|
28 |
+
|
29 |
+
def swap_sleep_time(hf_token,sleep_time):
|
30 |
+
sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}/sleeptime"
|
31 |
+
headers = { "authorization" : f"Bearer {hf_token}"}
|
32 |
+
body = {'seconds':sleep_time}
|
33 |
+
requests.post(sleep_time_url,json=body,headers=headers)
|
34 |
+
|
35 |
+
def get_sleep_time(hf_token):
|
36 |
+
sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}"
|
37 |
+
headers = { "authorization" : f"Bearer {hf_token}"}
|
38 |
+
response = requests.get(sleep_time_url,headers=headers)
|
39 |
+
try:
|
40 |
+
gcTimeout = response.json()['runtime']['gcTimeout']
|
41 |
+
except:
|
42 |
+
gcTimeout = None
|
43 |
+
return gcTimeout
|
44 |
+
|
45 |
+
def write_to_community(title, description,hf_token):
|
46 |
+
from huggingface_hub import HfApi
|
47 |
+
api = HfApi()
|
48 |
+
api.create_discussion(repo_id=os.environ['SPACE_ID'], title=title, description=description,repo_type="space", token=hf_token)
|
49 |
+
|
50 |
+
|
51 |
def set_accelerate_default_config():
|
52 |
try:
|
53 |
subprocess.run(["accelerate", "config", "default"], check=True)
|
|
|
112 |
checkpoint_steps,
|
113 |
remove_gpu):
|
114 |
|
115 |
+
|
116 |
+
if is_shared_ui:
|
117 |
+
raise gr.Error("This Space only works in duplicated instances")
|
118 |
+
|
119 |
+
if not is_gpu_associated:
|
120 |
+
raise gr.Error("Please associate a T4 or A10G GPU for this Space")
|
121 |
+
|
122 |
if dataset_id == "":
|
123 |
raise gr.Error("You forgot to specify an image dataset")
|
124 |
|
|
|
127 |
|
128 |
if lora_trained_xl_folder == "":
|
129 |
raise gr.Error("You forgot to name the output folder for your model")
|
|
|
|
|
|
|
130 |
|
131 |
+
sleep_time = get_sleep_time(hf_token)
|
132 |
+
if sleep_time:
|
133 |
+
swap_sleep_time(hf_token, -1)
|
134 |
|
135 |
gr.Warning("Training is ongoing ⌛... You can close this tab if you like or just wait.")
|
136 |
gr.Warning("If you did not check the `Remove GPU After training`, don't forget to remove the GPU attribution after you are done. ")
|