Desarrollo instrucciones en main.py para subida de imagenes al dataset
Browse files
main.py
CHANGED
@@ -1 +1,24 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# pandas: For data manipulation and transformation.
|
2 |
+
# pyarrow: For reading and writing Parquet files.
|
3 |
+
import pyarrow.parquet as pq
|
4 |
+
import json
|
5 |
+
|
6 |
+
table = pq.read_table('data/test-00000-of-00001.parquet')
|
7 |
+
df = table.to_pandas() # DataFrame
|
8 |
+
|
9 |
+
print("INICIO", df)
|
10 |
+
|
11 |
+
with open("images.json") as json_file:
|
12 |
+
data = json.load(json_file)
|
13 |
+
image_rows = data["imagesToUpload"]
|
14 |
+
|
15 |
+
for img in image_rows:
|
16 |
+
image_path = img["path"]
|
17 |
+
image_text = img["text"]
|
18 |
+
with open(image_path, "rb") as image:
|
19 |
+
image_bytes = image.read()
|
20 |
+
new_row = {'image': {'bytes': image_bytes, 'path': image_path}, 'text': image_text}
|
21 |
+
df = df._append(new_row, ignore_index=True)
|
22 |
+
|
23 |
+
print("FIN", df)
|
24 |
+
# df.to_parquet('data/test-00000-of-00001.parquet')
|