Commit
·
3a5662d
1
Parent(s):
202fcb6
Update download.py
Browse files- download.py +9 -13
download.py
CHANGED
|
@@ -6,19 +6,15 @@ import pandas as pd
|
|
| 6 |
from datasets import load_dataset
|
| 7 |
|
| 8 |
def decode_and_save_images(df, output_dir):
|
| 9 |
-
for i,
|
| 10 |
-
# Decode image
|
| 11 |
-
image_data = base64.b64decode(
|
| 12 |
image = Image.open(io.BytesIO(image_data))
|
|
|
|
| 13 |
|
| 14 |
-
# Save
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# Save caption
|
| 19 |
-
caption_filename = f"{output_dir}/caption_{i}.txt"
|
| 20 |
-
with open(caption_filename, 'w') as file:
|
| 21 |
-
file.write(row['caption'])
|
| 22 |
|
| 23 |
print(f"Saved Image and Caption {i}")
|
| 24 |
|
|
@@ -26,8 +22,8 @@ def main():
|
|
| 26 |
# Load dataset from Hugging Face
|
| 27 |
dataset = load_dataset("dataautogpt3/Dalle3")
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
df = pd.DataFrame(dataset[
|
| 31 |
|
| 32 |
# Specify your desired output directory here
|
| 33 |
output_dir = '/path/to/your/desired/output' # Replace with your specific path
|
|
|
|
| 6 |
from datasets import load_dataset
|
| 7 |
|
| 8 |
def decode_and_save_images(df, output_dir):
|
| 9 |
+
for i, (image_base64, caption) in enumerate(zip(df['image'], df['caption'])):
|
| 10 |
+
# Decode and save the image
|
| 11 |
+
image_data = base64.b64decode(image_base64)
|
| 12 |
image = Image.open(io.BytesIO(image_data))
|
| 13 |
+
image.save(os.path.join(output_dir, f"image_{i}.png"))
|
| 14 |
|
| 15 |
+
# Save the caption
|
| 16 |
+
with open(os.path.join(output_dir, f"caption_{i}.txt"), 'w') as file:
|
| 17 |
+
file.write(caption)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
print(f"Saved Image and Caption {i}")
|
| 20 |
|
|
|
|
| 22 |
# Load dataset from Hugging Face
|
| 23 |
dataset = load_dataset("dataautogpt3/Dalle3")
|
| 24 |
|
| 25 |
+
# Assuming the first split contains the data
|
| 26 |
+
df = pd.DataFrame(dataset[next(iter(dataset))])
|
| 27 |
|
| 28 |
# Specify your desired output directory here
|
| 29 |
output_dir = '/path/to/your/desired/output' # Replace with your specific path
|