GeorgeSherif commited on
Commit
965aed3
·
1 Parent(s): 1fbc4e1
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -3,12 +3,6 @@ import os
3
  import threading
4
  import random
5
  from datasets import load_dataset, Dataset, Features, Value
6
- from huggingface_hub import login
7
- token = os.getenv("HUGGINGFACE_TOKEN")
8
- if token:
9
- login(token=token)
10
- else:
11
- print("HUGGINGFACE_TOKEN environment variable not set.")
12
 
13
  # Set up your Hugging Face dataset name
14
  dataset_name = "GeorgeIbrahim/EGYCOCO" # Replace with your dataset name
@@ -28,6 +22,7 @@ except Exception as e:
28
  image_folder = "test"
29
  image_files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
30
  lock = threading.Lock()
 
31
 
32
  # Function to get a random image that hasn’t been annotated or skipped
33
  def get_next_image():
@@ -52,7 +47,7 @@ def save_annotation(caption):
52
 
53
  # Add the new annotation to the dataset
54
  new_data = {"image_id": image_id, "caption": caption}
55
- dataset = dataset.add_item(new_data)
56
 
57
  # Save updated dataset to Hugging Face
58
  dataset.push_to_hub(dataset_name)
@@ -74,7 +69,7 @@ def skip_image():
74
  image_id = os.path.basename(current_image)
75
  # Record "skipped" caption directly here
76
  new_data = {"image_id": image_id, "caption": "skipped"}
77
- dataset = dataset.add_item(new_data)
78
 
79
  # Save updated dataset to Hugging Face
80
  dataset.push_to_hub(dataset_name)
 
3
  import threading
4
  import random
5
  from datasets import load_dataset, Dataset, Features, Value
 
 
 
 
 
 
6
 
7
  # Set up your Hugging Face dataset name
8
  dataset_name = "GeorgeIbrahim/EGYCOCO" # Replace with your dataset name
 
22
  image_folder = "test"
23
  image_files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
24
  lock = threading.Lock()
25
+ current_image = None
26
 
27
  # Function to get a random image that hasn’t been annotated or skipped
28
  def get_next_image():
 
47
 
48
  # Add the new annotation to the dataset
49
  new_data = {"image_id": image_id, "caption": caption}
50
+ dataset.add_item(new_data) # Update the dataset variable
51
 
52
  # Save updated dataset to Hugging Face
53
  dataset.push_to_hub(dataset_name)
 
69
  image_id = os.path.basename(current_image)
70
  # Record "skipped" caption directly here
71
  new_data = {"image_id": image_id, "caption": "skipped"}
72
+ dataset.add_item(new_data) # Update the dataset variable
73
 
74
  # Save updated dataset to Hugging Face
75
  dataset.push_to_hub(dataset_name)