Spaces:
Sleeping
Sleeping
GeorgeSherif commited on
Commit ·
77215fd
1
Parent(s): 1349bfa
update
Browse files
app.py
CHANGED
|
@@ -13,16 +13,18 @@ else:
|
|
| 13 |
print("HUGGINGFACE_TOKEN environment variable not set.")
|
| 14 |
dataset_name = "GeorgeIbrahim/EGYCOCO" # Replace with your dataset name
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Load or create the dataset with train and val splits
|
| 17 |
try:
|
| 18 |
dataset = load_dataset(dataset_name)
|
| 19 |
print("Loaded existing dataset:", dataset)
|
| 20 |
except Exception as e:
|
| 21 |
# Create empty datasets for train and val splits if they don't exist
|
| 22 |
-
features = Features({
|
| 23 |
-
'image_id': Value(dtype='string'),
|
| 24 |
-
'caption': Value(dtype='string'),
|
| 25 |
-
})
|
| 26 |
train_dataset = Dataset.from_dict({'image_id': [], 'caption': []}, features=features)
|
| 27 |
val_dataset = Dataset.from_dict({'image_id': [], 'caption': []}, features=features)
|
| 28 |
dataset = {"train": train_dataset, "val": val_dataset}
|
|
@@ -74,7 +76,7 @@ def save_annotation(caption, session_data):
|
|
| 74 |
caption = "skipped"
|
| 75 |
|
| 76 |
# Add the new annotation as a new row to the appropriate split
|
| 77 |
-
new_data = Dataset.from_dict({"image_id": [image_id], "caption": [caption]})
|
| 78 |
global dataset
|
| 79 |
dataset[split] = concatenate_datasets([dataset[split], new_data])
|
| 80 |
|
|
|
|
| 13 |
print("HUGGINGFACE_TOKEN environment variable not set.")
|
| 14 |
dataset_name = "GeorgeIbrahim/EGYCOCO" # Replace with your dataset name
|
| 15 |
|
| 16 |
+
# Define the features schema once at the beginning
|
| 17 |
+
features = Features({
|
| 18 |
+
'image_id': Value(dtype='string'),
|
| 19 |
+
'caption': Value(dtype='string'),
|
| 20 |
+
})
|
| 21 |
+
|
| 22 |
# Load or create the dataset with train and val splits
|
| 23 |
try:
|
| 24 |
dataset = load_dataset(dataset_name)
|
| 25 |
print("Loaded existing dataset:", dataset)
|
| 26 |
except Exception as e:
|
| 27 |
# Create empty datasets for train and val splits if they don't exist
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
train_dataset = Dataset.from_dict({'image_id': [], 'caption': []}, features=features)
|
| 29 |
val_dataset = Dataset.from_dict({'image_id': [], 'caption': []}, features=features)
|
| 30 |
dataset = {"train": train_dataset, "val": val_dataset}
|
|
|
|
| 76 |
caption = "skipped"
|
| 77 |
|
| 78 |
# Add the new annotation as a new row to the appropriate split
|
| 79 |
+
new_data = Dataset.from_dict({"image_id": [image_id], "caption": [caption]}, features=features)
|
| 80 |
global dataset
|
| 81 |
dataset[split] = concatenate_datasets([dataset[split], new_data])
|
| 82 |
|