luulinh90s commited on
Commit
2b0d981
·
1 Parent(s): 0b2d6d0
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -125,18 +125,29 @@ def load_samples():
125
 
126
  def select_balanced_samples(samples):
127
  try:
128
- if len(samples) < 10:
129
- logger.warning(f"Not enough common samples. Only {len(samples)} available.")
130
- return samples
131
 
132
- selected_samples = random.sample(samples, 10)
133
- logger.info(f"Selected 10 unique samples")
 
 
 
 
 
 
 
 
 
 
 
 
134
  return selected_samples
135
  except Exception as e:
136
  logger.exception("Error selecting balanced samples")
137
  return []
138
 
139
-
140
  @app.route('/')
141
  def introduction():
142
  return render_template('introduction.html')
 
125
 
126
  def select_balanced_samples(samples):
127
  try:
128
+ # Separate samples into two groups
129
+ tp_fp_samples = [s for s in samples if s['category'] in ['TP', 'FP']]
130
+ tn_fn_samples = [s for s in samples if s['category'] in ['TN', 'FN']]
131
 
132
+ # Check if we have enough samples in each group
133
+ if len(tp_fp_samples) < 5 or len(tn_fn_samples) < 5:
134
+ logger.warning(f"Not enough samples in each category. TP+FP: {len(tp_fp_samples)}, TN+FN: {len(tn_fn_samples)}")
135
+ return samples if len(samples) <= 10 else random.sample(samples, 10)
136
+
137
+ # Select 5 samples from each group
138
+ selected_tp_fp = random.sample(tp_fp_samples, 5)
139
+ selected_tn_fn = random.sample(tn_fn_samples, 5)
140
+
141
+ # Combine and shuffle the selected samples
142
+ selected_samples = selected_tp_fp + selected_tn_fn
143
+ random.shuffle(selected_samples)
144
+
145
+ logger.info(f"Selected 10 balanced samples: 5 from TP+FP, 5 from TN+FN")
146
  return selected_samples
147
  except Exception as e:
148
  logger.exception("Error selecting balanced samples")
149
  return []
150
 
 
151
  @app.route('/')
152
  def introduction():
153
  return render_template('introduction.html')