| import gradio as gr |
| import json |
| import os |
|
|
| |
| image_folder = "Images/" |
| metadata_file = "descriptions.json" |
|
|
| |
| with open(metadata_file, "r") as f: |
| metadata = json.load(f) |
|
|
| |
| def train_lora(image_folder, metadata): |
| |
| dataset = [] |
| 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}) |
| else: |
| print(f"Warning: {image_name} not found in {image_folder}") |
|
|
| |
| num_images = len(dataset) |
| return f"Training LoRA with {num_images} images and their descriptions." |
|
|
| |
| def start_training(): |
| return train_lora(image_folder, metadata) |
|
|
| |
| demo = gr.Interface( |
| fn=start_training, |
| inputs=None, |
| outputs="text", |
| title="Train LoRA on Your Dataset", |
| description="Click below to start training with the uploaded images and metadata." |
| ) |
|
|
| demo.launch() |
|
|