genia-dataset-02 / main.py
lpastor's picture
Muevo image.json a carpeta images, actualizo .gitignore y ajusto nombres de atributos
0fd8596
# pandas: For data manipulation and transformation.
# pyarrow: For reading and writing Parquet files.
import pyarrow.parquet as pq
import os
import json
table = pq.read_table('data/test-00000-of-00001.parquet')
df = table.to_pandas() # DataFrame
print("INICIO", df)
with open("images/images.json") as json_file:
data = json.load(json_file)
image_rows = data["imagesToUpload"]
for img in image_rows:
image_path = f"images/{img["name"]}"
image_text = img["text"]
with open(image_path, "rb") as image:
image_bytes = image.read()
new_row = {'image': {'bytes': image_bytes, 'path': image_path}, 'text': image_text}
df = df._append(new_row, ignore_index=True)
os.remove(image_path)
print("FIN", df)
df.to_parquet('data/test-00000-of-00001.parquet')