|
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(): |
|
dataset = [] |
|
num_images = len(metadata) |
|
progress_log = "" |
|
|
|
|
|
for i, (image_name, description) in enumerate(metadata.items()): |
|
image_path = os.path.join(image_folder, image_name) |
|
if os.path.exists(image_path): |
|
dataset.append({"image": image_path, "description": description}) |
|
progress_log += f"Processed {i+1}/{num_images}: {image_name}\n" |
|
else: |
|
progress_log += f"Warning: {image_name} not found.\n" |
|
time.sleep(0.5) |
|
|
|
return progress_log + f"\nTraining completed with {len(dataset)} valid images." |
|
|
|
|
|
demo = gr.Interface( |
|
fn=train_lora_with_progress, |
|
inputs=None, |
|
outputs="text", |
|
title="Train LoRA with Progress Log", |
|
description="Click below to start training and view live progress logs." |
|
) |
|
|
|
demo.launch(enable_queue=True) |
|
|