fffiloni commited on
Commit
5bc1fa1
·
verified ·
1 Parent(s): 7ed9e27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -35
app.py CHANGED
@@ -37,16 +37,16 @@ def swap_hardware(hf_token, hardware="cpu-basic"):
37
  requests.post(hardware_url, json = body, headers=headers)
38
 
39
 
40
- global sleep_time
41
 
42
- def swap_sleep_time(hf_token,sleep_time):
 
43
  sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}/sleeptime"
44
  headers = { "authorization" : f"Bearer {hf_token}"}
45
  body = {'seconds':sleep_time}
46
  requests.post(sleep_time_url,json=body,headers=headers)
47
 
48
 
49
- def get_sleep_time(hf_token):
50
  sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}"
51
  headers = { "authorization" : f"Bearer {hf_token}"}
52
  response = requests.get(sleep_time_url,headers=headers)
@@ -54,10 +54,15 @@ def get_sleep_time(hf_token):
54
  gcTimeout = response.json()['runtime']['gcTimeout']
55
  except:
56
  gcTimeout = None
57
- sleep_time = gcTimeout
58
  return gcTimeout
59
 
60
- sleep_time = get_sleep_time(hf_token)
 
 
 
 
 
61
 
62
  def train_dreambooth_blora_sdxl(instance_data_dir, b_lora_trained_folder, instance_prompt, class_prompt, max_train_steps, checkpoint_steps):
63
 
@@ -159,8 +164,8 @@ def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, train
159
 
160
  your_username = api.whoami(token=hf_token)["name"]
161
 
162
- #swap_hardware(hf_token, hardware="cpu-basic")
163
- swap_sleep_time(hf_token, 300)
164
 
165
  return f"Done, your trained model has been stored in your models library: {your_username}/{b_lora_trained_folder}"
166
 
@@ -264,40 +269,29 @@ with gr.Blocks(css=css) as demo:
264
  image = gr.Image(label="Image Reference", sources=["upload"], type="filepath")
265
 
266
  with gr.Column():
267
- current_sleep_time = gr.Number(visible=False)
268
- print(f"loaded demo: {sleep_time}")
269
- if sleep_time is not None and sleep_time > 1:
270
- gr.HTML(f'''
271
- <div class="gr-prose">
272
- <h2>in order to train properly your B-LoRa, you need to set space sleep time to "Don't sleep"</h2>
273
- <p class="actions">
274
- <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">⚡️ &nbsp; Set recommended Sleep Time</a>
275
- </p>
276
- </div>
277
- ''')
278
- training_type = gr.Radio(label="Training type", choices=["style", "concept"], value="style", interactive=False)
279
- b_lora_name = gr.Textbox(label="Name your B-LoRa model", placeholder="b_lora_trained_folder", interactive=False)
280
  with gr.Row():
281
- instance_prompt = gr.Textbox(label="Create instance prompt", placeholder="A [v42] <class_prompt>", interactive=False)
282
- class_prompt = gr.Textbox(label="Specify class prompt", placeholder="style | person | dog ", interactive=False)
283
- training_steps = gr.Number(label="Training steps", value=1000, interactive=False)
284
- checkpoint_step = gr.Number(label="checkpoint step", visible=False, value=500)
285
- else:
286
- training_type = gr.Radio(label="Training type", choices=["style", "concept"], value="style", interactive=True)
287
- b_lora_name = gr.Textbox(label="Name your B-LoRa model", placeholder="b_lora_trained_folder", interactive=True)
288
  with gr.Row():
289
- instance_prompt = gr.Textbox(label="Create instance prompt", placeholder="A [v42] <class_prompt>", interactive=True)
290
- class_prompt = gr.Textbox(label="Specify class prompt", placeholder="style | person | dog ", interactive=True)
291
- training_steps = gr.Number(label="Training steps", value=1000, interactive=False)
292
  checkpoint_step = gr.Number(label="checkpoint step", visible=False, value=500)
293
 
294
 
295
- if sleep_time is not None and sleep_time > 1:
296
- train_btn = gr.Button("Train B-LoRa", visible=False)
297
- else:
298
- train_btn = gr.Button("Train B-LoRa", visible=True)
299
  status = gr.Textbox(label="status")
300
 
 
 
 
 
 
301
 
302
  training_type.change(
303
  fn = change_training_setup,
@@ -310,5 +304,5 @@ with gr.Blocks(css=css) as demo:
310
  inputs = [image, b_lora_name, instance_prompt, class_prompt, training_type, training_steps],
311
  outputs = [status]
312
  )
313
- demo.load(fn=get_sleep_time, inputs=None, outputs=[current_sleep_time])
314
  demo.launch(debug=True)
 
37
  requests.post(hardware_url, json = body, headers=headers)
38
 
39
 
 
40
 
41
+
42
+ def swap_sleep_time(sleep_time):
43
  sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}/sleeptime"
44
  headers = { "authorization" : f"Bearer {hf_token}"}
45
  body = {'seconds':sleep_time}
46
  requests.post(sleep_time_url,json=body,headers=headers)
47
 
48
 
49
+ def get_sleep_time():
50
  sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}"
51
  headers = { "authorization" : f"Bearer {hf_token}"}
52
  response = requests.get(sleep_time_url,headers=headers)
 
54
  gcTimeout = response.json()['runtime']['gcTimeout']
55
  except:
56
  gcTimeout = None
57
+
58
  return gcTimeout
59
 
60
+ def check_sleep_time():
61
+ sleep_time = get_sleep_time()
62
+ if sleep_time is None :
63
+ return sleep_time, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
64
+ else :
65
+ return sleep_time, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
66
 
67
  def train_dreambooth_blora_sdxl(instance_data_dir, b_lora_trained_folder, instance_prompt, class_prompt, max_train_steps, checkpoint_steps):
68
 
 
164
 
165
  your_username = api.whoami(token=hf_token)["name"]
166
 
167
+ #swap_hardware(hardware="cpu-basic")
168
+ swap_sleep_time(300)
169
 
170
  return f"Done, your trained model has been stored in your models library: {your_username}/{b_lora_trained_folder}"
171
 
 
269
  image = gr.Image(label="Image Reference", sources=["upload"], type="filepath")
270
 
271
  with gr.Column():
272
+
 
 
 
 
 
 
 
 
 
 
 
 
273
  with gr.Row():
274
+ current_sleep_time = gr.Textbox(label="current space sleep time")
275
+ check_sleep_time_btn = gr.Button("check", scale=1)
276
+ training_type = gr.Radio(label="Training type", choices=["style", "concept"], value="style", visible=False)
277
+ b_lora_name = gr.Textbox(label="Name your B-LoRa model", placeholder="b_lora_trained_folder", visible=False)
 
 
 
278
  with gr.Row():
279
+ instance_prompt = gr.Textbox(label="Create instance prompt", placeholder="A [v42] <class_prompt>", visible=False)
280
+ class_prompt = gr.Textbox(label="Specify class prompt", placeholder="style | person | dog ", visible=False)
281
+ training_steps = gr.Number(label="Training steps", value=1000, interactive=False, visible=False)
282
  checkpoint_step = gr.Number(label="checkpoint step", visible=False, value=500)
283
 
284
 
285
+
286
+ train_btn = gr.Button("Train B-LoRa", visible=False)
287
+
 
288
  status = gr.Textbox(label="status")
289
 
290
+ check_sleep_time_btn.click(
291
+ fn = check_sleep_time,
292
+ inputs = None,
293
+ outputs = [current_sleep_time, b_lora_name, instance_prompt, class_prompt, training_type, training_steps, train_btn]
294
+ )
295
 
296
  training_type.change(
297
  fn = change_training_setup,
 
304
  inputs = [image, b_lora_name, instance_prompt, class_prompt, training_type, training_steps],
305
  outputs = [status]
306
  )
307
+
308
  demo.launch(debug=True)