File size: 1,276 Bytes
cb92b08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
import json
import os
import time

# Paths
image_folder = "Images/"  # Folder containing the images
metadata_file = "descriptions.json"  # JSON file with image descriptions

# Load metadata
with open(metadata_file, "r") as f:
    metadata = json.load(f)

# Function for training with simple console logging
def train_lora_with_progress():
    dataset = []
    num_images = len(metadata)
    progress_log = ""
    
    # Process images and descriptions
    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)  # Simulate time for each step
    
    return progress_log + f"\nTraining completed with {len(dataset)} valid images."

# Gradio app
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)