Configure your LoRA train settings.
""", elem_classes="group_padding") 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", ) concept_sentence = gr.Textbox( elem_id="--concept_sentence", label="Trigger word/sentence", info="Trigger word or sentence to be used", placeholder="uncommon word like p3rs0n or trtcrd, or sentence like 'in the style of CNSTLL'", interactive=True, ) model_names = list(models.keys()) print(f"model_names={model_names}") base_model = gr.Dropdown(label="Base model (edit the models.yaml file to add more to this list)", choices=model_names, value=model_names[0]) vram = gr.Radio(["20G", "16G", "12G" ], value="20G", label="VRAM", interactive=True) num_repeats = gr.Number(value=10, precision=0, label="Repeat trains per image", interactive=True) max_train_epochs = gr.Number(label="Max Train Epochs", value=16, interactive=True) total_steps = gr.Number(0, interactive=False, label="Expected training steps") sample_prompts = gr.Textbox("", lines=5, label="Sample Image Prompts (Separate with new lines)", interactive=True) sample_every_n_steps = gr.Number(0, precision=0, label="Sample Image Every N Steps", interactive=True) resolution = gr.Number(value=512, precision=0, label="Resize dataset images") with gr.Column(): gr.Markdown( """# Step 2. DatasetMake sure the captions include the trigger word.
""", elem_classes="group_padding") with gr.Group(): images = gr.File( file_types=["image", ".txt"], label="Upload your images", #info="If you want, you can also manually upload caption files that match the image names (example: img0.png => img0.txt)", file_count="multiple", interactive=True, visible=True, scale=1, ) with gr.Group(visible=False) as captioning_area: do_captioning = gr.Button("Add AI captions with Florence-2") output_components.append(captioning_area) #output_components = [captioning_area] caption_list = [] for i in range(1, MAX_IMAGES + 1): locals()[f"captioning_row_{i}"] = gr.Row(visible=False) with locals()[f"captioning_row_{i}"]: locals()[f"image_{i}"] = gr.Image( type="filepath", width=111, height=111, min_width=111, interactive=False, scale=2, show_label=False, show_share_button=False, show_download_button=False, ) locals()[f"caption_{i}"] = gr.Textbox( label=f"Caption {i}", scale=15, interactive=True ) output_components.append(locals()[f"captioning_row_{i}"]) output_components.append(locals()[f"image_{i}"]) output_components.append(locals()[f"caption_{i}"]) caption_list.append(locals()[f"caption_{i}"]) with gr.Column(): gr.Markdown( """# Step 3. TrainPress start to start training.
""", elem_classes="group_padding") refresh = gr.Button("Refresh", elem_id="refresh", visible=False) start = gr.Button("Start training", visible=False, elem_id="start_training") output_components.append(start) train_script = gr.Textbox(label="Train script", max_lines=100, interactive=True) train_config = gr.Textbox(label="Train config", max_lines=100, interactive=True) with gr.Accordion("Advanced options", elem_id='advanced_options', open=False): with gr.Row(): with gr.Column(min_width=300): seed = gr.Number(label="--seed", info="Seed", value=42, interactive=True) with gr.Column(min_width=300): workers = gr.Number(label="--max_data_loader_n_workers", info="Number of Workers", value=2, interactive=True) with gr.Column(min_width=300): learning_rate = gr.Textbox(label="--learning_rate", info="Learning Rate", value="8e-4", interactive=True) with gr.Column(min_width=300): save_every_n_epochs = gr.Number(label="--save_every_n_epochs", info="Save every N epochs", value=4, interactive=True) with gr.Column(min_width=300): guidance_scale = gr.Number(label="--guidance_scale", info="Guidance Scale", value=1.0, interactive=True) with gr.Column(min_width=300): timestep_sampling = gr.Textbox(label="--timestep_sampling", info="Timestep Sampling", value="shift", interactive=True) with gr.Column(min_width=300): network_dim = gr.Number(label="--network_dim", info="LoRA Rank", value=4, minimum=4, maximum=128, step=4, interactive=True) advanced_components, advanced_component_ids = init_advanced() with gr.Row(): terminal = LogsView(label="Train log", elem_id="terminal") with gr.Row(): gallery = gr.Gallery(get_samples, inputs=[lora_name], label="Samples", every=10, columns=6) with gr.TabItem("Publish") as publish_tab: hf_token = gr.Textbox(label="Huggingface Token") hf_login = gr.Button("Login") hf_logout = gr.Button("Logout") with gr.Row() as row: gr.Markdown("**LoRA**") gr.Markdown("**Upload**") loras = get_loras() with gr.Row(): lora_rows = refresh_publish_tab() with gr.Column(): with gr.Row(): repo_owner = gr.Textbox(label="Account", interactive=False) repo_name = gr.Textbox(label="Repository Name") repo_visibility = gr.Textbox(label="Repository Visibility ('public' or 'private')", value="public") upload_button = gr.Button("Upload to HuggingFace") upload_button.click( fn=upload_hf, inputs=[ base_model, lora_rows, repo_owner, repo_name, repo_visibility, hf_token, ] ) hf_login.click(fn=login_hf, inputs=[hf_token], outputs=[hf_token, hf_login, hf_logout, repo_owner]) hf_logout.click(fn=logout_hf, outputs=[hf_token, hf_login, hf_logout, repo_owner]) publish_tab.select(refresh_publish_tab, outputs=lora_rows) lora_rows.select(fn=set_repo, inputs=[lora_rows], outputs=[repo_name]) dataset_folder = gr.State() listeners = [ base_model, lora_name, resolution, seed, workers, concept_sentence, learning_rate, network_dim, max_train_epochs, save_every_n_epochs, timestep_sampling, guidance_scale, vram, num_repeats, sample_prompts, sample_every_n_steps, *advanced_components ] advanced_component_ids = [x.elem_id for x in advanced_components] original_advanced_component_values = [comp.value for comp in advanced_components] images.upload( load_captioning, inputs=[images, concept_sentence], outputs=output_components ) images.delete( load_captioning, inputs=[images, concept_sentence], outputs=output_components ) images.clear( hide_captioning, outputs=[captioning_area, start] ) max_train_epochs.change( fn=update_total_steps, inputs=[max_train_epochs, num_repeats, images], outputs=[total_steps] ) num_repeats.change( fn=update_total_steps, inputs=[max_train_epochs, num_repeats, images], outputs=[total_steps] ) images.upload( fn=update_total_steps, inputs=[max_train_epochs, num_repeats, images], outputs=[total_steps] ) images.delete( fn=update_total_steps, inputs=[max_train_epochs, num_repeats, images], outputs=[total_steps] ) images.clear( fn=update_total_steps, inputs=[max_train_epochs, num_repeats, images], outputs=[total_steps] ) concept_sentence.change(fn=update_sample, inputs=[concept_sentence], outputs=sample_prompts) start.click(fn=create_dataset, inputs=[dataset_folder, resolution, images] + caption_list, outputs=dataset_folder).then( fn=start_training, inputs=[ base_model, lora_name, train_script, train_config, sample_prompts, ], outputs=terminal, ) do_captioning.click(fn=run_captioning, inputs=[images, concept_sentence] + caption_list, outputs=caption_list) demo.load(fn=loaded, js=js, outputs=[hf_token, hf_login, hf_logout, repo_owner]) refresh.click(update, inputs=listeners, outputs=[train_script, train_config, dataset_folder]) if __name__ == "__main__": cwd = os.path.dirname(os.path.abspath(__file__)) demo.launch(debug=True, show_error=True, allowed_paths=[cwd])