DonImages commited on
Commit
417c33d
·
verified ·
1 Parent(s): 93f1db9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -18
app.py CHANGED
@@ -1,7 +1,6 @@
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
@@ -10,32 +9,44 @@ metadata_file = "descriptions.json" # JSON file with image descriptions
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)
 
 
1
  import gradio as gr
2
  import json
3
  import os
 
4
 
5
  # Paths
6
  image_folder = "Images/" # Folder containing the images
 
9
  # Load metadata
10
  with open(metadata_file, "r") as f:
11
  metadata = json.load(f)
12
+ print(f"Loaded metadata: {len(metadata)} items") # Print the number of descriptions
13
 
14
+ # Placeholder function for training LoRA
15
+ def train_lora(image_folder, metadata):
16
+ print("Starting training process...") # Log the start of the training
17
+ # Prepare a dataset of image paths and descriptions
18
  dataset = []
19
+ for image_name, description in metadata.items():
 
 
 
 
20
  image_path = os.path.join(image_folder, image_name)
21
+ if os.path.exists(image_path): # Ensure the image file exists
22
  dataset.append({"image": image_path, "description": description})
23
+ print(f"Added {image_name} to dataset") # Log each added image
24
  else:
25
+ print(f"Warning: {image_name} not found in {image_folder}") # Log missing images
26
+
27
+ # Log how many images were successfully added
28
+ num_images = len(dataset)
29
+ print(f"Dataset prepared with {num_images} images.")
30
 
31
+ # Placeholder for training logic
32
+ # Replace this with your actual training code
33
+ print("Training LoRA with the prepared dataset...")
34
+
35
+ # For now, just return a message
36
+ return f"Training LoRA with {num_images} images and their descriptions."
37
+
38
+ # Define Gradio app
39
+ def start_training():
40
+ return train_lora(image_folder, metadata)
41
 
42
+ # Gradio interface
43
  demo = gr.Interface(
44
+ fn=start_training,
45
  inputs=None,
46
  outputs="text",
47
+ title="Train LoRA on Your Dataset",
48
+ description="Click below to start training with the uploaded images and metadata."
49
  )
50
 
51
+ # Launch the Gradio interface
52
+ demo.launch()