|
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'])): |
|
|
|
image_data = base64.b64decode(image_base64) |
|
image = Image.open(io.BytesIO(image_data)) |
|
image.save(os.path.join(output_dir, f"image_{i}.png")) |
|
|
|
|
|
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(): |
|
|
|
dataset = load_dataset("dataautogpt3/Dalle3") |
|
|
|
|
|
df = pd.DataFrame(dataset[next(iter(dataset))]) |
|
|
|
|
|
output_dir = '/path/to/your/desired/output' |
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
decode_and_save_images(df, output_dir) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|