Create app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,41 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Paths
|
| 6 |
+
image_folder = "Images/" # Folder containing the images
|
| 7 |
+
metadata_file = "descriptions.json" # JSON file with image descriptions
|
| 8 |
+
|
| 9 |
+
# Load metadata
|
| 10 |
+
with open(metadata_file, "r") as f:
|
| 11 |
+
metadata = json.load(f)
|
| 12 |
+
|
| 13 |
+
# Placeholder function for training LoRA
|
| 14 |
+
def train_lora(image_folder, metadata):
|
| 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 |
+
print(f"Warning: {image_name} not found in {image_folder}")
|
| 23 |
+
|
| 24 |
+
# Placeholder for training logic
|
| 25 |
+
num_images = len(dataset)
|
| 26 |
+
return f"Training LoRA with {num_images} images and their descriptions."
|
| 27 |
+
|
| 28 |
+
# Define Gradio app
|
| 29 |
+
def start_training():
|
| 30 |
+
return train_lora(image_folder, metadata)
|
| 31 |
+
|
| 32 |
+
# Gradio interface
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=start_training,
|
| 35 |
+
inputs=None,
|
| 36 |
+
outputs="text",
|
| 37 |
+
title="Train LoRA on Your Dataset",
|
| 38 |
+
description="Click below to start training with the uploaded images and metadata."
|
| 39 |
+
)
|
| 40 |
|
|
|
|
| 41 |
demo.launch()
|