fffiloni commited on
Commit
b6a069c
·
verified ·
1 Parent(s): 5ada086

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -35,6 +35,22 @@ def swap_hardware(hf_token, hardware="cpu-basic"):
35
  headers = { "authorization" : f"Bearer {hf_token}"}
36
  body = {'flavor': hardware}
37
  requests.post(hardware_url, json = body, headers=headers)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  def train_dreambooth_blora_sdxl(instance_data_dir, b_lora_trained_folder, instance_prompt, class_prompt, max_train_steps, checkpoint_steps):
40
 
@@ -91,6 +107,10 @@ def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, train
91
 
92
  if instance_prompt == "":
93
  raise gr.Error("You forgot to specify an instance prompt")
 
 
 
 
94
 
95
  local_dir = "image_to_train"
96
  # Check if the directory exists and create it if necessary
@@ -111,7 +131,8 @@ def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, train
111
 
112
  your_username = api.whoami(token=hf_token)["name"]
113
 
114
- swap_hardware(hf_token, hardware="cpu-basic")
 
115
 
116
  return f"Done, your trained model has been stored in your models library: {your_username}/{b_lora_trained_folder}"
117
 
 
35
  headers = { "authorization" : f"Bearer {hf_token}"}
36
  body = {'flavor': hardware}
37
  requests.post(hardware_url, json = body, headers=headers)
38
+
39
+ def swap_sleep_time(hf_token,sleep_time):
40
+ sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}/sleeptime"
41
+ headers = { "authorization" : f"Bearer {hf_token}"}
42
+ body = {'seconds':sleep_time}
43
+ requests.post(sleep_time_url,json=body,headers=headers)
44
+
45
+ def get_sleep_time(hf_token):
46
+ sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}"
47
+ headers = { "authorization" : f"Bearer {hf_token}"}
48
+ response = requests.get(sleep_time_url,headers=headers)
49
+ try:
50
+ gcTimeout = response.json()['runtime']['gcTimeout']
51
+ except:
52
+ gcTimeout = None
53
+ return gcTimeout
54
 
55
  def train_dreambooth_blora_sdxl(instance_data_dir, b_lora_trained_folder, instance_prompt, class_prompt, max_train_steps, checkpoint_steps):
56
 
 
107
 
108
  if instance_prompt == "":
109
  raise gr.Error("You forgot to specify an instance prompt")
110
+
111
+ sleep_time = get_sleep_time(hf_token)
112
+ if sleep_time:
113
+ swap_sleep_time(hf_token, -1)
114
 
115
  local_dir = "image_to_train"
116
  # Check if the directory exists and create it if necessary
 
131
 
132
  your_username = api.whoami(token=hf_token)["name"]
133
 
134
+ #swap_hardware(hf_token, hardware="cpu-basic")
135
+ swap_sleep_time(hf_token, 300)
136
 
137
  return f"Done, your trained model has been stored in your models library: {your_username}/{b_lora_trained_folder}"
138