README.md CHANGED
@@ -11,4 +11,4 @@ license: mit
11
  hf_oauth: true
12
  ---
13
 
14
- Check out the configuration reference at: https://huggingface.co/docs/hub/spaces-config-reference.
 
11
  hf_oauth: true
12
  ---
13
 
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
src/constants.py CHANGED
@@ -5,31 +5,17 @@ import os
5
  import pathlib
6
 
7
 
8
- DATASET_NAME = "mulsi/fruit-vegetable-concepts"
9
  CONCEPTS = [
10
- # Environment
11
- "stem",
12
- "leaf",
13
- "tail",
14
- "seed",
15
- "pulp",
16
- "soil",
17
- "tree",
18
  # Shapes
19
- "ovaloid",
20
  "sphere",
21
- "cylinder",
22
  "cube",
 
23
  # Colors
24
- "black",
25
- "purple",
26
  "red",
27
- "blue",
28
  "green",
29
- "brown",
30
  "orange",
31
  "yellow",
32
- "white",
33
  ]
34
  ASSETS_FOLDER = pathlib.Path(__file__).parent / "assets"
35
 
 
5
  import pathlib
6
 
7
 
8
+ DATASET_NAME = "Xmaster6y/fruit-vegetable-concepts"
9
  CONCEPTS = [
 
 
 
 
 
 
 
 
10
  # Shapes
 
11
  "sphere",
 
12
  "cube",
13
+ "cylinder",
14
  # Colors
 
 
15
  "red",
 
16
  "green",
 
17
  "orange",
18
  "yellow",
 
19
  ]
20
  ASSETS_FOLDER = pathlib.Path(__file__).parent / "assets"
21
 
src/global_variables.py CHANGED
@@ -26,7 +26,7 @@ def setup():
26
  repo_type="dataset",
27
  )
28
  all_metadata = {}
29
- for split in ["train", "test"]:
30
  all_metadata[split] = []
31
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl") as reader:
32
  for row in reader:
@@ -78,8 +78,7 @@ def update_votes(
78
  all_votes[s_id] = {}
79
  all_votes[s_id][username] = {c: c in voted_concepts for c in CONCEPTS}
80
  new_concepts = compute_concepts(all_votes[s_id])
81
- for concept, concept_value in new_concepts.items():
82
- all_metadata[current_split][idx][concept] = concept_value
83
 
84
  def compute_concepts(votes):
85
  vote_sum = {c: 0 for c in CONCEPTS}
@@ -117,13 +116,13 @@ def save_current_work(
117
  json.dump(new_votes[key], f)
118
  all_votes = new_votes
119
  new_metadata = {}
120
- for split in ["train", "test"]:
121
  new_metadata[split] = []
122
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl") as reader:
123
  for row in reader:
124
  s_id = row["id"]
125
  if s_id in all_votes:
126
- row.update(compute_concepts(all_votes[s_id]))
127
  new_metadata[split].append(row)
128
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl", mode='w') as writer:
129
  writer.write_all(new_metadata[split])
 
26
  repo_type="dataset",
27
  )
28
  all_metadata = {}
29
+ for split in ["train", "validation", "test"]:
30
  all_metadata[split] = []
31
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl") as reader:
32
  for row in reader:
 
78
  all_votes[s_id] = {}
79
  all_votes[s_id][username] = {c: c in voted_concepts for c in CONCEPTS}
80
  new_concepts = compute_concepts(all_votes[s_id])
81
+ all_metadata[current_split][idx]["concepts"] = new_concepts
 
82
 
83
  def compute_concepts(votes):
84
  vote_sum = {c: 0 for c in CONCEPTS}
 
116
  json.dump(new_votes[key], f)
117
  all_votes = new_votes
118
  new_metadata = {}
119
+ for split in ["train", "validation", "test"]:
120
  new_metadata[split] = []
121
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl") as reader:
122
  for row in reader:
123
  s_id = row["id"]
124
  if s_id in all_votes:
125
+ row["concepts"] = compute_concepts(all_votes[s_id])
126
  new_metadata[split].append(row)
127
  with jsonlines.open(f"{ASSETS_FOLDER}/{DATASET_NAME}/data/{split}/metadata.jsonl", mode='w') as writer:
128
  writer.write_all(new_metadata[split])
src/label_interface.py CHANGED
@@ -12,7 +12,7 @@ from src.constants import CONCEPTS, ASSETS_FOLDER, DATASET_NAME
12
 
13
 
14
  def filter_sample(sample, concepts, username, sample_type):
15
- has_concepts = all([sample[c] for c in concepts])
16
  if not has_concepts:
17
  return False
18
  if "votes" in sample and username in sample["votes"]:
@@ -53,14 +53,14 @@ def get_next_image(
53
  except KeyError:
54
  voted_concepts = []
55
  unseen_concepts = []
56
- tie_concepts = [c for c in CONCEPTS if sample[c] is None]
57
 
58
  return (
59
  image_path,
60
  voted_concepts,
61
  f"{split}:{sample_idx}",
62
  sample["class"],
63
- {c: sample[c] for c in CONCEPTS},
64
  unseen_concepts,
65
  tie_concepts,
66
  filtered_indices,
@@ -117,7 +117,7 @@ with gr.Blocks() as interface:
117
  with gr.Row():
118
  split = gr.Radio(
119
  label="Split",
120
- choices=["train", "test"],
121
  value="train",
122
  )
123
  sample_type = gr.Radio(
@@ -130,20 +130,6 @@ with gr.Blocks() as interface:
130
  multiselect=True,
131
  choices=CONCEPTS,
132
  )
133
-
134
- with gr.Row():
135
- next_button = gr.Button(
136
- value="Next",
137
- )
138
- gr.LoginButton()
139
- submit_button = gr.Button(
140
- value="Local Submit",
141
- )
142
- with gr.Row():
143
- save_button = gr.Button(
144
- value="Save",
145
- )
146
-
147
  with gr.Group():
148
  voted_concepts = gr.CheckboxGroup(
149
  label="Voted Concepts",
@@ -158,6 +144,18 @@ with gr.Blocks() as interface:
158
  choices=CONCEPTS,
159
  )
160
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  with gr.Group():
162
  gr.Markdown(
163
  "## # Image Info",
 
12
 
13
 
14
  def filter_sample(sample, concepts, username, sample_type):
15
+ has_concepts = all([sample["concepts"].get(c, False) for c in concepts])
16
  if not has_concepts:
17
  return False
18
  if "votes" in sample and username in sample["votes"]:
 
53
  except KeyError:
54
  voted_concepts = []
55
  unseen_concepts = []
56
+ tie_concepts = [c for c in sample["concepts"] if sample["concepts"][c] is None]
57
 
58
  return (
59
  image_path,
60
  voted_concepts,
61
  f"{split}:{sample_idx}",
62
  sample["class"],
63
+ sample["concepts"],
64
  unseen_concepts,
65
  tie_concepts,
66
  filtered_indices,
 
117
  with gr.Row():
118
  split = gr.Radio(
119
  label="Split",
120
+ choices=["train", "validation", "test"],
121
  value="train",
122
  )
123
  sample_type = gr.Radio(
 
130
  multiselect=True,
131
  choices=CONCEPTS,
132
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  with gr.Group():
134
  voted_concepts = gr.CheckboxGroup(
135
  label="Voted Concepts",
 
144
  choices=CONCEPTS,
145
  )
146
 
147
+ with gr.Row():
148
+ next_button = gr.Button(
149
+ value="Next",
150
+ )
151
+ gr.LoginButton()
152
+ submit_button = gr.Button(
153
+ value="Local Submit",
154
+ )
155
+ with gr.Row():
156
+ save_button = gr.Button(
157
+ value="Save",
158
+ )
159
  with gr.Group():
160
  gr.Markdown(
161
  "## # Image Info",
src/sample_interface.py CHANGED
@@ -37,14 +37,14 @@ def get_image(
37
  except KeyError:
38
  voted_concepts = []
39
  unseen_concepts = []
40
- tie_concepts = [c for c in CONCEPTS if sample[c] is None]
41
 
42
  return (
43
  image_path,
44
  voted_concepts,
45
  f"{split}:{sample_idx}",
46
  sample["class"],
47
- {c: sample[c] for c in CONCEPTS},
48
  str(sample_idx),
49
  unseen_concepts,
50
  tie_concepts,
@@ -104,7 +104,7 @@ with gr.Blocks() as interface:
104
  )
105
  split = gr.Radio(
106
  label="Split",
107
- choices=["train", "test"],
108
  value="train",
109
  )
110
  index = gr.Textbox(
@@ -112,6 +112,19 @@ with gr.Blocks() as interface:
112
  label="Index",
113
  max_lines=1,
114
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  with gr.Row():
117
  prev_button = gr.Button(
@@ -128,21 +141,6 @@ with gr.Blocks() as interface:
128
  save_button = gr.Button(
129
  value="Save",
130
  )
131
-
132
- with gr.Group():
133
- voted_concepts = gr.CheckboxGroup(
134
- label="Voted Concepts",
135
- choices=CONCEPTS,
136
- )
137
- unseen_concepts = gr.CheckboxGroup(
138
- label="Previously Unseen Concepts",
139
- choices=CONCEPTS,
140
- )
141
- tie_concepts = gr.CheckboxGroup(
142
- label="Tie Concepts",
143
- choices=CONCEPTS,
144
- )
145
-
146
  with gr.Group():
147
  gr.Markdown(
148
  "## # Image Info",
 
37
  except KeyError:
38
  voted_concepts = []
39
  unseen_concepts = []
40
+ tie_concepts = [c for c in sample["concepts"] if sample["concepts"][c] is None]
41
 
42
  return (
43
  image_path,
44
  voted_concepts,
45
  f"{split}:{sample_idx}",
46
  sample["class"],
47
+ sample["concepts"],
48
  str(sample_idx),
49
  unseen_concepts,
50
  tie_concepts,
 
104
  )
105
  split = gr.Radio(
106
  label="Split",
107
+ choices=["train", "validation", "test"],
108
  value="train",
109
  )
110
  index = gr.Textbox(
 
112
  label="Index",
113
  max_lines=1,
114
  )
115
+ with gr.Group():
116
+ voted_concepts = gr.CheckboxGroup(
117
+ label="Voted Concepts",
118
+ choices=CONCEPTS,
119
+ )
120
+ unseen_concepts = gr.CheckboxGroup(
121
+ label="Previously Unseen Concepts",
122
+ choices=CONCEPTS,
123
+ )
124
+ tie_concepts = gr.CheckboxGroup(
125
+ label="Tie Concepts",
126
+ choices=CONCEPTS,
127
+ )
128
 
129
  with gr.Row():
130
  prev_button = gr.Button(
 
141
  save_button = gr.Button(
142
  value="Save",
143
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  with gr.Group():
145
  gr.Markdown(
146
  "## # Image Info",
src/vote_interface.py CHANGED
@@ -28,7 +28,7 @@ with gr.Blocks() as interface:
28
  )
29
  split = gr.Radio(
30
  label="Split",
31
- choices=["train", "test"],
32
  value="train",
33
  )
34
 
 
28
  )
29
  split = gr.Radio(
30
  label="Split",
31
+ choices=["train", "validation", "test"],
32
  value="train",
33
  )
34