File size: 1,590 Bytes
5e6614b
b0d8677
 
96a3b09
5e6614b
b0d8677
 
 
 
 
 
 
 
96a3b09
 
b0d8677
96a3b09
 
 
 
b0d8677
 
 
 
96a3b09
 
 
b0d8677
96a3b09
b0d8677
 
96a3b09
b0d8677
 
 
96a3b09
b0d8677
 
 
 
 
 
96a3b09
 
b0d8677
5e6614b
 
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
43
44
45
46
47
48
import gradio as gr
import json
import os
import time  # For simulating progress

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

# Placeholder function for training LoRA with progress tracking
def train_lora_with_progress(image_folder, metadata, progress=gr.Progress()):
    dataset = []
    num_images = len(metadata)
    completed = 0

    # Start processing images
    for image_name, description in metadata.items():
        image_path = os.path.join(image_folder, image_name)
        if os.path.exists(image_path):  # Ensure the image file exists
            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)  # Simulating processing time
        else:
            progress(completed / num_images, f"Warning: {image_name} not found in {image_folder}")

    # Placeholder for training logic
    return f"Training completed with {len(dataset)} valid images."

# Define Gradio app
def start_training():
    return train_lora_with_progress(image_folder, metadata)

# Gradio interface
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()