|
import gradio as gr |
|
import json |
|
import os |
|
import time |
|
|
|
|
|
image_folder = "Images/" |
|
metadata_file = "descriptions.json" |
|
|
|
|
|
with open(metadata_file, "r") as f: |
|
metadata = json.load(f) |
|
|
|
|
|
def train_lora_with_progress(image_folder, metadata, progress=gr.Progress()): |
|
dataset = [] |
|
num_images = len(metadata) |
|
completed = 0 |
|
|
|
|
|
for image_name, description in metadata.items(): |
|
image_path = os.path.join(image_folder, image_name) |
|
if os.path.exists(image_path): |
|
dataset.append({"image": image_path, "description": description}) |
|
completed += 1 |
|
progress(completed / num_images, f"Processed {completed}/{num_images} images: {image_name}") |
|
time.sleep(0.5) |
|
else: |
|
progress(completed / num_images, f"Warning: {image_name} not found in {image_folder}") |
|
|
|
|
|
return f"Training completed with {len(dataset)} valid images." |
|
|
|
|
|
def start_training(): |
|
return train_lora_with_progress(image_folder, metadata) |
|
|
|
|
|
demo = gr.Interface( |
|
fn=start_training, |
|
inputs=None, |
|
outputs="text", |
|
title="Train LoRA with Progress", |
|
description="Click below to start training with the uploaded images and metadata. Progress will be displayed live." |
|
) |
|
|
|
demo.launch() |
|
|