Commit
•
3965ed9
1
Parent(s):
6630ef4
Update app.py
Browse files
app.py
CHANGED
@@ -215,14 +215,9 @@ def start_training(
|
|
215 |
dataloader_num_workers,
|
216 |
local_rank,
|
217 |
dataset_folder,
|
218 |
-
|
219 |
-
oauth_token: gr.OAuthToken | None,
|
220 |
progress = gr.Progress(track_tqdm=True)
|
221 |
):
|
222 |
-
if(oauth_token is None):
|
223 |
-
raise gr.Error("You aren't logged in!")
|
224 |
-
else:
|
225 |
-
token = oauth_token.token
|
226 |
if not lora_name:
|
227 |
raise gr.Error("You forgot to insert your LoRA name! This name has to be unique.")
|
228 |
print("Started training")
|
@@ -338,8 +333,9 @@ def calculate_price(iterations):
|
|
338 |
cost_per_second = 1.05/60/60
|
339 |
cost = round(cost_per_second * total_seconds, 2)
|
340 |
return f'''To train this LoRA, we will duplicate the space and hook an A10G GPU under the hood.
|
341 |
-
## Estimated to cost <b>< US$ {str(cost)}</b> for {round(int(total_seconds)/60, 2)} minutes with your current train settings <small>({int(iterations)} iterations at 3.50s/it)</small>
|
342 |
-
|
|
|
343 |
def start_training_og(
|
344 |
lora_name,
|
345 |
training_option,
|
@@ -484,18 +480,16 @@ def run_captioning(*inputs):
|
|
484 |
final_captions[index] = final_caption
|
485 |
yield final_captions
|
486 |
|
487 |
-
def check_token(
|
488 |
-
token = OAuthToken.token
|
489 |
try:
|
490 |
api = HfApi(token=token)
|
491 |
user_data = api.whoami()
|
492 |
-
print("CanPay", user_data['canPay'])
|
493 |
except Exception as e:
|
494 |
gr.Warning("Invalid user token. Make sure to get your Hugging Face token from the settings page")
|
495 |
return gr.update(visible=False), gr.update(visible=False)
|
496 |
else:
|
497 |
-
if ("write
|
498 |
-
gr.Warning("Ops, you
|
499 |
else:
|
500 |
if user_data['canPay']:
|
501 |
return gr.update(visible=False), gr.update(visible=True)
|
@@ -523,19 +517,19 @@ theme = gr.themes.Monochrome(
|
|
523 |
text_size=gr.themes.Size(lg="18px", md="15px", sm="13px", xl="22px", xs="12px", xxl="24px", xxs="9px"),
|
524 |
font=[gr.themes.GoogleFont('Source Sans Pro'), 'ui-sans-serif', 'system-ui', 'sans-serif'],
|
525 |
)
|
526 |
-
def swap_opacity(token: gr.OAuthToken | None):
|
527 |
-
if token is None:
|
528 |
-
return gr.update(elem_classes=["main_unlogged"], elem_id="login")
|
529 |
-
else:
|
530 |
-
return gr.update(elem_classes=["main_logged"])
|
531 |
|
532 |
with gr.Blocks(css=css, theme=theme) as demo:
|
533 |
dataset_folder = gr.State()
|
534 |
gr.Markdown('''# LoRA Ease 🧞♂️
|
535 |
### Train a high quality SDXL LoRA in a breeze ༄ with state-of-the-art techniques
|
536 |
<small>Dreambooth with Pivotal Tuning, Prodigy and more! Use the trained LoRAs with diffusers, AUTO1111, Comfy. [blog about the training script](#), [Colab Pro](#), [run locally or in a cloud](#)</small>''', elem_id="main_title")
|
537 |
-
gr.LoginButton(elem_classes=["login_logout"])
|
538 |
-
with gr.Column(elem_classes=["
|
539 |
lora_name = gr.Textbox(label="The name of your LoRA", info="This has to be a unique name", placeholder="e.g.: Persian Miniature Painting style, Cat Toy")
|
540 |
training_option = gr.Radio(
|
541 |
label="What are you training?", choices=["object", "style", "character", "face", "custom"]
|
@@ -841,7 +835,7 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
841 |
with gr.Column(visible=False) as cost_estimation:
|
842 |
with gr.Group(elem_id="cost_box"):
|
843 |
training_cost_estimate = gr.Markdown(elem_id="training_cost")
|
844 |
-
|
845 |
with gr.Group(visible=False) as no_payment_method:
|
846 |
with gr.Row():
|
847 |
gr.HTML("<h3 style='margin: 0'>Your Hugging Face account doesn't have a payment method set up. Set one up <a href='https://huggingface.co/settings/billing/payment' target='_blank'>here</a> and come back here to train your LoRA</h3>")
|
@@ -850,15 +844,16 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
850 |
start = gr.Button("Start training", visible=False, interactive=True)
|
851 |
progress_area = gr.Markdown("")
|
852 |
|
853 |
-
gr.LogoutButton(elem_classes=["login_logout"])
|
854 |
output_components.insert(1, advanced)
|
855 |
output_components.insert(1, cost_estimation)
|
856 |
gr.on(
|
857 |
triggers=[
|
858 |
-
|
859 |
payment_setup.click
|
860 |
],
|
861 |
fn=check_token,
|
|
|
862 |
outputs=[no_payment_method, start],
|
863 |
concurrency_limit=50
|
864 |
)
|
@@ -982,7 +977,7 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
982 |
dataloader_num_workers,
|
983 |
local_rank,
|
984 |
dataset_folder,
|
985 |
-
|
986 |
],
|
987 |
outputs = progress_area,
|
988 |
queue=False
|
@@ -991,7 +986,7 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
991 |
do_captioning.click(
|
992 |
fn=run_captioning, inputs=[images] + caption_list + [training_option], outputs=caption_list
|
993 |
)
|
994 |
-
demo.load(fn=swap_opacity, outputs=[main_ui], queue=False, concurrency_limit=50)
|
995 |
if __name__ == "__main__":
|
996 |
demo.queue()
|
997 |
demo.launch(share=True)
|
|
|
215 |
dataloader_num_workers,
|
216 |
local_rank,
|
217 |
dataset_folder,
|
218 |
+
token,
|
|
|
219 |
progress = gr.Progress(track_tqdm=True)
|
220 |
):
|
|
|
|
|
|
|
|
|
221 |
if not lora_name:
|
222 |
raise gr.Error("You forgot to insert your LoRA name! This name has to be unique.")
|
223 |
print("Started training")
|
|
|
333 |
cost_per_second = 1.05/60/60
|
334 |
cost = round(cost_per_second * total_seconds, 2)
|
335 |
return f'''To train this LoRA, we will duplicate the space and hook an A10G GPU under the hood.
|
336 |
+
## Estimated to cost <b>< US$ {str(cost)}</b> for {round(int(total_seconds)/60, 2)} minutes with your current train settings <small>({int(iterations)} iterations at 3.50s/it)</small>
|
337 |
+
#### To continue, grab you <b>write</b> token [here](https://huggingface.co/settings/tokens) and enter it below ↓'''
|
338 |
+
|
339 |
def start_training_og(
|
340 |
lora_name,
|
341 |
training_option,
|
|
|
480 |
final_captions[index] = final_caption
|
481 |
yield final_captions
|
482 |
|
483 |
+
def check_token(token):
|
|
|
484 |
try:
|
485 |
api = HfApi(token=token)
|
486 |
user_data = api.whoami()
|
|
|
487 |
except Exception as e:
|
488 |
gr.Warning("Invalid user token. Make sure to get your Hugging Face token from the settings page")
|
489 |
return gr.update(visible=False), gr.update(visible=False)
|
490 |
else:
|
491 |
+
if (user_data['auth']['accessToken']['role'] != "write"):
|
492 |
+
gr.Warning("Ops, you've uploaded a Read token. You need to use a Write token!")
|
493 |
else:
|
494 |
if user_data['canPay']:
|
495 |
return gr.update(visible=False), gr.update(visible=True)
|
|
|
517 |
text_size=gr.themes.Size(lg="18px", md="15px", sm="13px", xl="22px", xs="12px", xxl="24px", xxs="9px"),
|
518 |
font=[gr.themes.GoogleFont('Source Sans Pro'), 'ui-sans-serif', 'system-ui', 'sans-serif'],
|
519 |
)
|
520 |
+
#def swap_opacity(token: gr.OAuthToken | None):
|
521 |
+
# if token is None:
|
522 |
+
# return gr.update(elem_classes=["main_unlogged"], elem_id="login")
|
523 |
+
# else:
|
524 |
+
# return gr.update(elem_classes=["main_logged"])
|
525 |
|
526 |
with gr.Blocks(css=css, theme=theme) as demo:
|
527 |
dataset_folder = gr.State()
|
528 |
gr.Markdown('''# LoRA Ease 🧞♂️
|
529 |
### Train a high quality SDXL LoRA in a breeze ༄ with state-of-the-art techniques
|
530 |
<small>Dreambooth with Pivotal Tuning, Prodigy and more! Use the trained LoRAs with diffusers, AUTO1111, Comfy. [blog about the training script](#), [Colab Pro](#), [run locally or in a cloud](#)</small>''', elem_id="main_title")
|
531 |
+
#gr.LoginButton(elem_classes=["login_logout"])
|
532 |
+
with gr.Column(elem_classes=["main_logged"]) as main_ui:
|
533 |
lora_name = gr.Textbox(label="The name of your LoRA", info="This has to be a unique name", placeholder="e.g.: Persian Miniature Painting style, Cat Toy")
|
534 |
training_option = gr.Radio(
|
535 |
label="What are you training?", choices=["object", "style", "character", "face", "custom"]
|
|
|
835 |
with gr.Column(visible=False) as cost_estimation:
|
836 |
with gr.Group(elem_id="cost_box"):
|
837 |
training_cost_estimate = gr.Markdown(elem_id="training_cost")
|
838 |
+
token = gr.Textbox(label="Your Hugging Face write token", info="A Hugging Face write token you can obtain on the settings page", type="password", placeholder="hf_OhHiThIsIsNoTaReALToKeNGOoDTry")
|
839 |
with gr.Group(visible=False) as no_payment_method:
|
840 |
with gr.Row():
|
841 |
gr.HTML("<h3 style='margin: 0'>Your Hugging Face account doesn't have a payment method set up. Set one up <a href='https://huggingface.co/settings/billing/payment' target='_blank'>here</a> and come back here to train your LoRA</h3>")
|
|
|
844 |
start = gr.Button("Start training", visible=False, interactive=True)
|
845 |
progress_area = gr.Markdown("")
|
846 |
|
847 |
+
#gr.LogoutButton(elem_classes=["login_logout"])
|
848 |
output_components.insert(1, advanced)
|
849 |
output_components.insert(1, cost_estimation)
|
850 |
gr.on(
|
851 |
triggers=[
|
852 |
+
token.change,
|
853 |
payment_setup.click
|
854 |
],
|
855 |
fn=check_token,
|
856 |
+
inputs=token,
|
857 |
outputs=[no_payment_method, start],
|
858 |
concurrency_limit=50
|
859 |
)
|
|
|
977 |
dataloader_num_workers,
|
978 |
local_rank,
|
979 |
dataset_folder,
|
980 |
+
token
|
981 |
],
|
982 |
outputs = progress_area,
|
983 |
queue=False
|
|
|
986 |
do_captioning.click(
|
987 |
fn=run_captioning, inputs=[images] + caption_list + [training_option], outputs=caption_list
|
988 |
)
|
989 |
+
#demo.load(fn=swap_opacity, outputs=[main_ui], queue=False, concurrency_limit=50)
|
990 |
if __name__ == "__main__":
|
991 |
demo.queue()
|
992 |
demo.launch(share=True)
|