Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,11 @@ import gradio as gr
|
|
| 11 |
image_folder = "Images/"
|
| 12 |
metadata_file = "descriptions.json"
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Custom Dataset Class
|
| 16 |
class ImageDescriptionDataset(Dataset):
|
|
@@ -83,14 +88,15 @@ def train_lora(image_folder, metadata):
|
|
| 83 |
|
| 84 |
print("Training completed.")
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
def
|
| 88 |
print("Preparing dataset...")
|
|
|
|
| 89 |
return train_lora(image_folder, metadata)
|
| 90 |
|
| 91 |
# Gradio interface
|
| 92 |
demo = gr.Interface(
|
| 93 |
-
fn=
|
| 94 |
inputs=None,
|
| 95 |
outputs="text",
|
| 96 |
title="Train LoRA on Your Dataset",
|
|
|
|
| 11 |
image_folder = "Images/"
|
| 12 |
metadata_file = "descriptions.json"
|
| 13 |
|
| 14 |
+
# Define the function to load metadata
|
| 15 |
+
def load_metadata(metadata_file):
|
| 16 |
+
with open(metadata_file, 'r') as f:
|
| 17 |
+
metadata = json.load(f)
|
| 18 |
+
return metadata
|
| 19 |
|
| 20 |
# Custom Dataset Class
|
| 21 |
class ImageDescriptionDataset(Dataset):
|
|
|
|
| 88 |
|
| 89 |
print("Training completed.")
|
| 90 |
|
| 91 |
+
# Gradio app function to load metadata and start training
|
| 92 |
+
def start_training_gradio():
|
| 93 |
print("Preparing dataset...")
|
| 94 |
+
metadata = load_metadata(metadata_file) # Load metadata
|
| 95 |
return train_lora(image_folder, metadata)
|
| 96 |
|
| 97 |
# Gradio interface
|
| 98 |
demo = gr.Interface(
|
| 99 |
+
fn=start_training_gradio, # Use the new function name here
|
| 100 |
inputs=None,
|
| 101 |
outputs="text",
|
| 102 |
title="Train LoRA on Your Dataset",
|