Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import json
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# Paths
|
| 6 |
image_folder = "Images/" # Folder containing the images
|
|
@@ -10,32 +11,37 @@ metadata_file = "descriptions.json" # JSON file with image descriptions
|
|
| 10 |
with open(metadata_file, "r") as f:
|
| 11 |
metadata = json.load(f)
|
| 12 |
|
| 13 |
-
# Placeholder function for training LoRA
|
| 14 |
-
def
|
| 15 |
-
# Prepare a dataset of image paths and descriptions
|
| 16 |
dataset = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
for image_name, description in metadata.items():
|
| 18 |
image_path = os.path.join(image_folder, image_name)
|
| 19 |
if os.path.exists(image_path): # Ensure the image file exists
|
| 20 |
dataset.append({"image": image_path, "description": description})
|
|
|
|
|
|
|
|
|
|
| 21 |
else:
|
| 22 |
-
|
| 23 |
|
| 24 |
# Placeholder for training logic
|
| 25 |
-
|
| 26 |
-
return f"Training LoRA with {num_images} images and their descriptions."
|
| 27 |
|
| 28 |
# Define Gradio app
|
| 29 |
def start_training():
|
| 30 |
-
return
|
| 31 |
|
| 32 |
# Gradio interface
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn=start_training,
|
| 35 |
inputs=None,
|
| 36 |
outputs="text",
|
| 37 |
-
title="Train LoRA
|
| 38 |
-
description="Click below to start training with the uploaded images and metadata."
|
| 39 |
)
|
| 40 |
|
| 41 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
+
import time # For simulating progress
|
| 5 |
|
| 6 |
# Paths
|
| 7 |
image_folder = "Images/" # Folder containing the images
|
|
|
|
| 11 |
with open(metadata_file, "r") as f:
|
| 12 |
metadata = json.load(f)
|
| 13 |
|
| 14 |
+
# Placeholder function for training LoRA with progress tracking
|
| 15 |
+
def train_lora_with_progress(image_folder, metadata, progress=gr.Progress()):
|
|
|
|
| 16 |
dataset = []
|
| 17 |
+
num_images = len(metadata)
|
| 18 |
+
completed = 0
|
| 19 |
+
|
| 20 |
+
# Start processing images
|
| 21 |
for image_name, description in metadata.items():
|
| 22 |
image_path = os.path.join(image_folder, image_name)
|
| 23 |
if os.path.exists(image_path): # Ensure the image file exists
|
| 24 |
dataset.append({"image": image_path, "description": description})
|
| 25 |
+
completed += 1
|
| 26 |
+
progress(completed / num_images, f"Processed {completed}/{num_images} images: {image_name}")
|
| 27 |
+
time.sleep(0.5) # Simulating processing time
|
| 28 |
else:
|
| 29 |
+
progress(completed / num_images, f"Warning: {image_name} not found in {image_folder}")
|
| 30 |
|
| 31 |
# Placeholder for training logic
|
| 32 |
+
return f"Training completed with {len(dataset)} valid images."
|
|
|
|
| 33 |
|
| 34 |
# Define Gradio app
|
| 35 |
def start_training():
|
| 36 |
+
return train_lora_with_progress(image_folder, metadata)
|
| 37 |
|
| 38 |
# Gradio interface
|
| 39 |
demo = gr.Interface(
|
| 40 |
fn=start_training,
|
| 41 |
inputs=None,
|
| 42 |
outputs="text",
|
| 43 |
+
title="Train LoRA with Progress",
|
| 44 |
+
description="Click below to start training with the uploaded images and metadata. Progress will be displayed live."
|
| 45 |
)
|
| 46 |
|
| 47 |
demo.launch()
|