ClaireOzzz commited on
Commit
034d231
1 Parent(s): d0ea9a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -5,15 +5,22 @@ import shutil
5
  import requests
6
  import subprocess
7
  from subprocess import getoutput
8
- from huggingface_hub import snapshot_download, HfApi, create_repo
9
- api = HfApi()
10
 
11
- hf_token = os.environ.get("HF_TOKEN_WITH_WRITE_PERMISSION")
12
 
13
- is_shared_ui = True if "fffiloni/train-dreambooth-lora-sdxl" in os.environ['SPACE_ID'] else False
14
 
15
  is_gpu_associated = torch.cuda.is_available()
16
 
 
 
 
 
 
 
 
17
  if is_gpu_associated:
18
  gpu_info = getoutput('nvidia-smi')
19
  if("A10G" in gpu_info):
@@ -59,7 +66,7 @@ def load_images_to_dataset(images, dataset_name):
59
  path_to_folder = my_working_directory
60
  your_username = api.whoami(token=hf_token)["name"]
61
  repo_id = f"{your_username}/{dataset_name}"
62
- create_repo(repo_id=repo_id, repo_type="dataset", private=True, token=hf_token)
63
 
64
  api.upload_folder(
65
  folder_path=path_to_folder,
@@ -71,19 +78,19 @@ def load_images_to_dataset(images, dataset_name):
71
  return "Done, your dataset is ready and loaded for the training step!", repo_id
72
 
73
  def swap_hardware(hf_token, hardware="cpu-basic"):
74
- hardware_url = f"https://huggingface.co/spaces/{os.environ['SPACE_ID']}/hardware"
75
  headers = { "authorization" : f"Bearer {hf_token}"}
76
  body = {'flavor': hardware}
77
  requests.post(hardware_url, json = body, headers=headers)
78
 
79
  def swap_sleep_time(hf_token,sleep_time):
80
- sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}/sleeptime"
81
  headers = { "authorization" : f"Bearer {hf_token}"}
82
  body = {'seconds':sleep_time}
83
  requests.post(sleep_time_url,json=body,headers=headers)
84
 
85
  def get_sleep_time(hf_token):
86
- sleep_time_url = f"https://huggingface.co/api/spaces/{os.environ['SPACE_ID']}"
87
  headers = { "authorization" : f"Bearer {hf_token}"}
88
  response = requests.get(sleep_time_url,headers=headers)
89
  try:
@@ -94,7 +101,7 @@ def get_sleep_time(hf_token):
94
 
95
  def write_to_community(title, description,hf_token):
96
 
97
- api.create_discussion(repo_id=os.environ['SPACE_ID'], title=title, description=description,repo_type="space", token=hf_token)
98
 
99
 
100
  def set_accelerate_default_config():
@@ -299,9 +306,7 @@ with gr.Blocks(css=css) as demo:
299
  A T4 costs <strong>US$0.60/h</strong>, so it should cost < US$1 to train most models.
300
  </p>
301
  <p class="actions">
302
- <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
303
- <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
304
- </a>
305
  to start training your own image model
306
  </p>
307
  </div>
@@ -325,7 +330,7 @@ with gr.Blocks(css=css) as demo:
325
  <p>There's only one step left before you can train your model: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a <b>T4-small or A10G-small GPU</b> to it (via the Settings tab)</a> and run the training below.
326
  You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
327
  <p class="actions">
328
- <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">🔥 &nbsp; Set recommended GPU</a>
329
  </p>
330
  </div>
331
  ''', elem_id="warning-setgpu")
@@ -385,4 +390,4 @@ with gr.Blocks(css=css) as demo:
385
  outputs = [train_status]
386
  )
387
 
388
- demo.launch(debug=True)
 
5
  import requests
6
  import subprocess
7
  from subprocess import getoutput
8
+ from huggingface_hub import login, HfFileSystem, snapshot_download, HfApi, create_repo
9
+ #api = HfApi()
10
 
11
+ #hf_token = os.environ.get("HF_TOKEN_WITH_WRITE_PERMISSION")
12
 
13
+ #is_shared_ui = True if "fffiloni/train-dreambooth-lora-sdxl" in os.environ['SPACE_ID'] else False
14
 
15
  is_gpu_associated = torch.cuda.is_available()
16
 
17
+ is_shared_ui = False
18
+
19
+ hf_token = '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'
20
+
21
+ fs = HfFileSystem(token=hf_token)
22
+ api = HfApi()
23
+
24
  if is_gpu_associated:
25
  gpu_info = getoutput('nvidia-smi')
26
  if("A10G" in gpu_info):
 
66
  path_to_folder = my_working_directory
67
  your_username = api.whoami(token=hf_token)["name"]
68
  repo_id = f"{your_username}/{dataset_name}"
69
+ create_repo(repo_id=repo_id, repo_type="dataset", token=hf_token)
70
 
71
  api.upload_folder(
72
  folder_path=path_to_folder,
 
78
  return "Done, your dataset is ready and loaded for the training step!", repo_id
79
 
80
  def swap_hardware(hf_token, hardware="cpu-basic"):
81
+ hardware_url = f"https://huggingface.co/spaces/ClaireOzzz/train-dreambooth-lora-sdxl/hardware"
82
  headers = { "authorization" : f"Bearer {hf_token}"}
83
  body = {'flavor': hardware}
84
  requests.post(hardware_url, json = body, headers=headers)
85
 
86
  def swap_sleep_time(hf_token,sleep_time):
87
+ sleep_time_url = f"https://huggingface.co/api/spaces/ClaireOzzz/train-dreambooth-lora-sdxl/sleeptime"
88
  headers = { "authorization" : f"Bearer {hf_token}"}
89
  body = {'seconds':sleep_time}
90
  requests.post(sleep_time_url,json=body,headers=headers)
91
 
92
  def get_sleep_time(hf_token):
93
+ sleep_time_url = f"https://huggingface.co/api/spaces/ClaireOzzz/train-dreambooth-lora-sdxl"
94
  headers = { "authorization" : f"Bearer {hf_token}"}
95
  response = requests.get(sleep_time_url,headers=headers)
96
  try:
 
101
 
102
  def write_to_community(title, description,hf_token):
103
 
104
+ api.create_discussion(repo_id=os.environ['ClaireOzzz/train-dreambooth-lora-sdxl'], title=title, description=description,repo_type="space", token=hf_token)
105
 
106
 
107
  def set_accelerate_default_config():
 
306
  A T4 costs <strong>US$0.60/h</strong>, so it should cost < US$1 to train most models.
307
  </p>
308
  <p class="actions">
309
+
 
 
310
  to start training your own image model
311
  </p>
312
  </div>
 
330
  <p>There's only one step left before you can train your model: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a <b>T4-small or A10G-small GPU</b> to it (via the Settings tab)</a> and run the training below.
331
  You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
332
  <p class="actions">
333
+ <a href="https://huggingface.co/spaces/ClaireOzzz/train-dreambooth-lora-sdxl/settings">🔥 &nbsp; Set recommended GPU</a>
334
  </p>
335
  </div>
336
  ''', elem_id="warning-setgpu")
 
390
  outputs = [train_status]
391
  )
392
 
393
+ demo.launch(debug=True, share=True)