Commit
·
3164600
1
Parent(s):
c57b1f6
Update app.py
Browse files
app.py
CHANGED
|
@@ -120,9 +120,9 @@ def train(*inputs):
|
|
| 120 |
os.makedirs('output_model',exist_ok=True)
|
| 121 |
uses_custom = inputs[-1]
|
| 122 |
type_of_thing = inputs[-4]
|
| 123 |
-
|
| 124 |
remove_attribution_after = inputs[-6]
|
| 125 |
-
|
| 126 |
if(uses_custom):
|
| 127 |
Training_Steps = int(inputs[-3])
|
| 128 |
Train_text_encoder_for = int(inputs[-2])
|
|
@@ -176,7 +176,10 @@ def train(*inputs):
|
|
| 176 |
trained_file = open("hastrained.success", "w")
|
| 177 |
trained_file.close()
|
| 178 |
if(remove_attribution_after):
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
| 180 |
hardware_url = f"https://huggingface.co/spaces/{os.environ['SPACE_ID']}/hardware"
|
| 181 |
headers = { "authorization" : f"Bearer {hf_token}"}
|
| 182 |
body = {'flavor': 'cpu-basic'}
|
|
@@ -321,7 +324,7 @@ def check_status(top_description):
|
|
| 321 |
]
|
| 322 |
|
| 323 |
def checkbox_swap(checkbox):
|
| 324 |
-
return [gr.update(visible=checkbox), gr.update(visible=checkbox), gr.update(visible=checkbox)]
|
| 325 |
|
| 326 |
with gr.Blocks(css=css) as demo:
|
| 327 |
with gr.Box():
|
|
@@ -406,6 +409,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 406 |
training_summary_text = gr.HTML("", visible=False, label="Training Summary")
|
| 407 |
training_summary_checkbox = gr.Checkbox(label="Automatically remove paid GPU attribution and upload model to the Hugging Face Hub after training", value=False)
|
| 408 |
training_summary_model_name = gr.Textbox(label="Name of your model", visible=False)
|
|
|
|
| 409 |
training_summary_token_message = gr.Markdown("[A Hugging Face write access token](https://huggingface.co/settings/tokens), go to \"New token\" -> Role : Write. A regular read token won't work here.", visible=False)
|
| 410 |
training_summary_token = gr.Textbox(label="Hugging Face Write Token", type="password", visible=False)
|
| 411 |
|
|
@@ -430,6 +434,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 430 |
where_to_upload = gr.Dropdown(["My personal profile", "Public Library"], label="Upload to")
|
| 431 |
gr.Markdown("[A Hugging Face write access token](https://huggingface.co/settings/tokens), go to \"New token\" -> Role : Write. A regular read token won't work here.")
|
| 432 |
hf_token = gr.Textbox(label="Hugging Face Write Token", type="password")
|
|
|
|
| 433 |
push_button = gr.Button("Push to the Hub")
|
| 434 |
|
| 435 |
result = gr.File(label="Download the uploaded models in the diffusers format", visible=True)
|
|
@@ -446,12 +451,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 446 |
perc_txt_encoder.change(fn=count_files, inputs=file_collection+[type_of_thing]+[steps]+[perc_txt_encoder]+[swap_auto_calculated], outputs=[training_summary, training_summary_text], queue=False)
|
| 447 |
|
| 448 |
#Give more options if the user wants to finish everything after training
|
| 449 |
-
training_summary_checkbox.change(fn=checkbox_swap, inputs=training_summary_checkbox, outputs=[training_summary_token_message, training_summary_token, training_summary_model_name],queue=False, show_progress=False)
|
| 450 |
#Add a message for while it is in training
|
| 451 |
train_btn.click(lambda:gr.update(visible=True), inputs=None, outputs=training_ongoing)
|
| 452 |
|
| 453 |
#The main train function
|
| 454 |
-
train_btn.click(fn=train, inputs=is_visible+concept_collection+file_collection+[training_summary_model_name]+[training_summary_checkbox]+[training_summary_token]+[type_of_thing]+[steps]+[perc_txt_encoder]+[swap_auto_calculated], outputs=[result, try_your_model, push_to_hub, convert_button, training_ongoing, completed_training], queue=False)
|
| 455 |
|
| 456 |
#Button to generate an image from your trained model after training
|
| 457 |
generate_button.click(fn=generate, inputs=prompt, outputs=result_image, queue=False)
|
|
|
|
| 120 |
os.makedirs('output_model',exist_ok=True)
|
| 121 |
uses_custom = inputs[-1]
|
| 122 |
type_of_thing = inputs[-4]
|
| 123 |
+
|
| 124 |
remove_attribution_after = inputs[-6]
|
| 125 |
+
|
| 126 |
if(uses_custom):
|
| 127 |
Training_Steps = int(inputs[-3])
|
| 128 |
Train_text_encoder_for = int(inputs[-2])
|
|
|
|
| 176 |
trained_file = open("hastrained.success", "w")
|
| 177 |
trained_file.close()
|
| 178 |
if(remove_attribution_after):
|
| 179 |
+
hf_token = inputs[-5]
|
| 180 |
+
model_name = inputs[-7]
|
| 181 |
+
where_to_upload = inputs[-8]
|
| 182 |
+
push(model_name, where_to_upload, hf_token, True)
|
| 183 |
hardware_url = f"https://huggingface.co/spaces/{os.environ['SPACE_ID']}/hardware"
|
| 184 |
headers = { "authorization" : f"Bearer {hf_token}"}
|
| 185 |
body = {'flavor': 'cpu-basic'}
|
|
|
|
| 324 |
]
|
| 325 |
|
| 326 |
def checkbox_swap(checkbox):
|
| 327 |
+
return [gr.update(visible=checkbox), gr.update(visible=checkbox), gr.update(visible=checkbox), gr.update(visible=checkbox)]
|
| 328 |
|
| 329 |
with gr.Blocks(css=css) as demo:
|
| 330 |
with gr.Box():
|
|
|
|
| 409 |
training_summary_text = gr.HTML("", visible=False, label="Training Summary")
|
| 410 |
training_summary_checkbox = gr.Checkbox(label="Automatically remove paid GPU attribution and upload model to the Hugging Face Hub after training", value=False)
|
| 411 |
training_summary_model_name = gr.Textbox(label="Name of your model", visible=False)
|
| 412 |
+
training_summary_where_to_upload = gr.Dropdown(["My personal profile", "Public Library"], label="Upload to", visible=False)
|
| 413 |
training_summary_token_message = gr.Markdown("[A Hugging Face write access token](https://huggingface.co/settings/tokens), go to \"New token\" -> Role : Write. A regular read token won't work here.", visible=False)
|
| 414 |
training_summary_token = gr.Textbox(label="Hugging Face Write Token", type="password", visible=False)
|
| 415 |
|
|
|
|
| 434 |
where_to_upload = gr.Dropdown(["My personal profile", "Public Library"], label="Upload to")
|
| 435 |
gr.Markdown("[A Hugging Face write access token](https://huggingface.co/settings/tokens), go to \"New token\" -> Role : Write. A regular read token won't work here.")
|
| 436 |
hf_token = gr.Textbox(label="Hugging Face Write Token", type="password")
|
| 437 |
+
|
| 438 |
push_button = gr.Button("Push to the Hub")
|
| 439 |
|
| 440 |
result = gr.File(label="Download the uploaded models in the diffusers format", visible=True)
|
|
|
|
| 451 |
perc_txt_encoder.change(fn=count_files, inputs=file_collection+[type_of_thing]+[steps]+[perc_txt_encoder]+[swap_auto_calculated], outputs=[training_summary, training_summary_text], queue=False)
|
| 452 |
|
| 453 |
#Give more options if the user wants to finish everything after training
|
| 454 |
+
training_summary_checkbox.change(fn=checkbox_swap, inputs=training_summary_checkbox, outputs=[training_summary_token_message, training_summary_token, training_summary_model_name, training_summary_where_to_upload],queue=False, show_progress=False)
|
| 455 |
#Add a message for while it is in training
|
| 456 |
train_btn.click(lambda:gr.update(visible=True), inputs=None, outputs=training_ongoing)
|
| 457 |
|
| 458 |
#The main train function
|
| 459 |
+
train_btn.click(fn=train, inputs=is_visible+concept_collection+file_collection+[training_summary_where_to_upload]+[training_summary_model_name]+[training_summary_checkbox]+[training_summary_token]+[type_of_thing]+[steps]+[perc_txt_encoder]+[swap_auto_calculated], outputs=[result, try_your_model, push_to_hub, convert_button, training_ongoing, completed_training], queue=False)
|
| 460 |
|
| 461 |
#Button to generate an image from your trained model after training
|
| 462 |
generate_button.click(fn=generate, inputs=prompt, outputs=result_image, queue=False)
|