Dalle3 / download.py
dataautogpt3's picture
Update download.py
3a5662d
import base64
from PIL import Image
import io
import os
import pandas as pd
from datasets import load_dataset
def decode_and_save_images(df, output_dir):
for i, (image_base64, caption) in enumerate(zip(df['image'], df['caption'])):
# Decode and save the image
image_data = base64.b64decode(image_base64)
image = Image.open(io.BytesIO(image_data))
image.save(os.path.join(output_dir, f"image_{i}.png"))
# Save the caption
with open(os.path.join(output_dir, f"caption_{i}.txt"), 'w') as file:
file.write(caption)
print(f"Saved Image and Caption {i}")
def main():
# Load dataset from Hugging Face
dataset = load_dataset("dataautogpt3/Dalle3")
# Assuming the first split contains the data
df = pd.DataFrame(dataset[next(iter(dataset))])
# Specify your desired output directory here
output_dir = '/path/to/your/desired/output' # Replace with your specific path
os.makedirs(output_dir, exist_ok=True)
# Process and save images and captions
decode_and_save_images(df, output_dir)
if __name__ == "__main__":
main()