taesiri commited on
Commit
f64b497
·
1 Parent(s): b97e4b1
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -134,14 +134,25 @@ def save_evaluation(post_id, model_a, model_b, verdict):
134
 
135
 
136
  def get_random_sample():
137
- """Get a random sample from the dataset. Sampling with replacement is allowed."""
138
- idx = random.randint(0, len(dataset) - 1)
139
- sample = dataset[idx]
 
 
 
 
 
 
 
 
 
 
140
 
141
- # Filter photoexp to get entries with the same post_id
142
- matching_photoexp_entries = photoexp[photoexp.post_id == sample["post_id"]]
 
143
 
144
- # Randomly select one entry from the matching entries
145
  if not matching_photoexp_entries.empty:
146
  random_photoexp_entry = matching_photoexp_entries.sample(n=1).iloc[0]
147
  additional_edited_image = random_photoexp_entry["edited_image"]
@@ -164,7 +175,8 @@ def get_random_sample():
164
  image_b = sample["edited_image"]
165
  model_b = sample["model"]
166
 
167
- print(f"Selected sample {idx}: {sample['post_id']} - {sample['model']}")
 
168
 
169
  return {
170
  "post_id": sample["post_id"],
 
134
 
135
 
136
  def get_random_sample():
137
+ """Get a random sample by first selecting a post_id then picking random edits for that post."""
138
+ # First randomly select a post_id from valid posts
139
+ random_post_id = random.choice(list(valid_post_ids))
140
+
141
+ # Filter dataset for this post_id using batched processing
142
+ post_edits = dataset.filter(
143
+ lambda xs: [x == random_post_id for x in xs["post_id"]],
144
+ batched=True,
145
+ batch_size=256,
146
+ )
147
+
148
+ # Get matching photoexp entries for this post_id
149
+ matching_photoexp_entries = photoexp[photoexp.post_id == random_post_id]
150
 
151
+ # Randomly select one edit from the dataset
152
+ idx = random.randint(0, len(post_edits) - 1)
153
+ sample = post_edits[idx]
154
 
155
+ # Randomly select one entry from the matching photoexp entries
156
  if not matching_photoexp_entries.empty:
157
  random_photoexp_entry = matching_photoexp_entries.sample(n=1).iloc[0]
158
  additional_edited_image = random_photoexp_entry["edited_image"]
 
175
  image_b = sample["edited_image"]
176
  model_b = sample["model"]
177
 
178
+ print(f"Selected post_id: {random_post_id}")
179
+ print(f"Selected edit from model: {sample['model']}")
180
 
181
  return {
182
  "post_id": sample["post_id"],