fffiloni commited on
Commit
4387a40
·
verified ·
1 Parent(s): 11dafde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -91,6 +91,24 @@ def train_dreambooth_blora_sdxl(instance_data_dir, b_lora_trained_folder, instan
91
  except subprocess.CalledProcessError as e:
92
  print(f"An error occurred: {e}")
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, training_type, training_steps):
95
 
96
  if is_shared_ui:
@@ -116,6 +134,9 @@ def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, train
116
  # Check if the directory exists and create it if necessary
117
  if not os.path.exists(local_dir):
118
  os.makedirs(local_dir)
 
 
 
119
 
120
  shutil.copy(image_path, local_dir)
121
  print(f"source image has been copied in {local_dir} directory")
 
91
  except subprocess.CalledProcessError as e:
92
  print(f"An error occurred: {e}")
93
 
94
+
95
+ def clear_directory(directory_path):
96
+ # Check if the directory exists
97
+ if os.path.exists(directory_path):
98
+ # Iterate over all the files and directories inside the specified directory
99
+ for filename in os.listdir(directory_path):
100
+ file_path = os.path.join(directory_path, filename)
101
+ try:
102
+ # Check if it is a file or a directory and remove accordingly
103
+ if os.path.isfile(file_path) or os.path.islink(file_path):
104
+ os.unlink(file_path) # Remove the file
105
+ elif os.path.isdir(file_path):
106
+ shutil.rmtree(file_path) # Remove the directory
107
+ except Exception as e:
108
+ print(f'Failed to delete {file_path}. Reason: {e}')
109
+ else:
110
+ print(f'The directory {directory_path} does not exist.')
111
+
112
  def main(image_path, b_lora_trained_folder, instance_prompt, class_prompt, training_type, training_steps):
113
 
114
  if is_shared_ui:
 
134
  # Check if the directory exists and create it if necessary
135
  if not os.path.exists(local_dir):
136
  os.makedirs(local_dir)
137
+ else :
138
+ directory_to_clear = local_dir
139
+ clear_directory(directory_to_clear)
140
 
141
  shutil.copy(image_path, local_dir)
142
  print(f"source image has been copied in {local_dir} directory")