rahul7star commited on
Commit
7eb6cc3
·
verified ·
1 Parent(s): 7a5b44b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -377,19 +377,22 @@ LORA_NAME = "ohami_filter_autorun"
377
 
378
  # ========== HELPERS ==========
379
  def create_dataset(images, *captions):
380
- destination_folder = f"datasets_{uuid.uuid4()}"
381
- os.makedirs(destination_folder, exist_ok=True)
382
-
383
- jsonl_file_path = os.path.join(destination_folder, "metadata.jsonl")
384
- with open(jsonl_file_path, "a") as jsonl_file:
385
- for index, image in enumerate(images):
386
- new_image_path = shutil.copy(str(image), destination_folder)
387
- caption = captions[index]
388
- file_name = os.path.basename(new_image_path)
389
- data = {"file_name": file_name, "prompt": caption}
390
- jsonl_file.write(json.dumps(data) + "\n")
391
-
392
- return destination_folder
 
 
 
393
 
394
  def recursive_update(d, u):
395
  for k, v in u.items():
 
377
 
378
  # ========== HELPERS ==========
379
  def create_dataset(images, *captions):
380
+ if len(images) != len(captions):
381
+ raise ValueError("Number of images and captions must be the same.")
382
+
383
+ destination_folder = Path(f"/tmp/datasets_{uuid.uuid4()}")
384
+ destination_folder.mkdir(parents=True, exist_ok=True)
385
+
386
+ jsonl_file_path = destination_folder / "metadata.jsonl"
387
+
388
+ with jsonl_file_path.open("a", encoding="utf-8") as jsonl_file:
389
+ for image_path, caption in zip(images, captions):
390
+ new_image_path = shutil.copy(str(image_path), destination_folder)
391
+ file_name = Path(new_image_path).name
392
+ entry = {"file_name": file_name, "prompt": caption}
393
+ jsonl_file.write(json.dumps(entry, ensure_ascii=False) + "\n")
394
+
395
+ return str(destination_folder)
396
 
397
  def recursive_update(d, u):
398
  for k, v in u.items():