Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import time
|
5 |
+
|
6 |
+
# Paths
|
7 |
+
image_folder = "Images/" # Folder containing the images
|
8 |
+
metadata_file = "descriptions.json" # JSON file with image descriptions
|
9 |
+
|
10 |
+
# Load metadata
|
11 |
+
with open(metadata_file, "r") as f:
|
12 |
+
metadata = json.load(f)
|
13 |
+
|
14 |
+
# Function for training with simple console logging
|
15 |
+
def train_lora_with_progress():
|
16 |
+
dataset = []
|
17 |
+
num_images = len(metadata)
|
18 |
+
progress_log = ""
|
19 |
+
|
20 |
+
# Process images and descriptions
|
21 |
+
for i, (image_name, description) in enumerate(metadata.items()):
|
22 |
+
image_path = os.path.join(image_folder, image_name)
|
23 |
+
if os.path.exists(image_path):
|
24 |
+
dataset.append({"image": image_path, "description": description})
|
25 |
+
progress_log += f"Processed {i+1}/{num_images}: {image_name}\n"
|
26 |
+
else:
|
27 |
+
progress_log += f"Warning: {image_name} not found.\n"
|
28 |
+
time.sleep(0.5) # Simulate time for each step
|
29 |
+
|
30 |
+
return progress_log + f"\nTraining completed with {len(dataset)} valid images."
|
31 |
+
|
32 |
+
# Gradio app
|
33 |
+
demo = gr.Interface(
|
34 |
+
fn=train_lora_with_progress,
|
35 |
+
inputs=None,
|
36 |
+
outputs="text",
|
37 |
+
title="Train LoRA with Progress Log",
|
38 |
+
description="Click below to start training and view live progress logs."
|
39 |
+
)
|
40 |
+
|
41 |
+
demo.launch(enable_queue=True)
|