luulinh90s commited on
Commit
d97b9ff
1 Parent(s): 85d7b7f
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -17,6 +17,8 @@ if hf_token:
17
  else:
18
  logger.error("HF_TOKEN not found in environment variables")
19
 
 
 
20
  # Set up logging
21
  logging.basicConfig(level=logging.INFO,
22
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -79,15 +81,17 @@ def save_session_data(username, data):
79
 
80
  logger.info(f"Data uploaded to Hugging Face Data Space:\n{json_data}")
81
 
82
-
83
- # Upload the file to a separate Hugging Face Space dedicated to data storage
84
- api = HfApi()
85
- api.upload_file(
86
- path_or_fileobj=temp_file_path,
87
- path_in_repo=f"session_data_pref/{file_name}",
88
- repo_id="luulinh90s/Tabular-LLM-Study-Data",
89
- repo_type="space",
90
- )
 
 
91
 
92
  # Remove the temporary file
93
  os.remove(temp_file_path)
@@ -154,14 +158,14 @@ def load_samples(methods):
154
 
155
  def select_balanced_samples(samples):
156
  try:
157
- # Ensure we have at least 10 unique samples
158
  unique_samples = list({(s['category'], s['file']) for s in samples})
159
 
160
- if len(unique_samples) < 10:
161
  logger.warning(f"Not enough unique samples. Only {len(unique_samples)} available.")
162
  selected_samples = unique_samples
163
  else:
164
- selected_samples = random.sample(unique_samples, 10)
165
 
166
  logger.info(f"Unique sampled samples:\n{selected_samples}")
167
 
 
17
  else:
18
  logger.error("HF_TOKEN not found in environment variables")
19
 
20
+ SAMPLE_NUM = 10
21
+
22
  # Set up logging
23
  logging.basicConfig(level=logging.INFO,
24
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
 
81
 
82
  logger.info(f"Data uploaded to Hugging Face Data Space:\n{json_data}")
83
 
84
+ if json_data['current_index'] < SAMPLE_NUM:
85
+ pass
86
+ else:
87
+ # Upload the file to a separate Hugging Face Space dedicated to data storage
88
+ api = HfApi()
89
+ api.upload_file(
90
+ path_or_fileobj=temp_file_path,
91
+ path_in_repo=f"session_data_pref/{file_name}",
92
+ repo_id="luulinh90s/Tabular-LLM-Study-Data",
93
+ repo_type="space",
94
+ )
95
 
96
  # Remove the temporary file
97
  os.remove(temp_file_path)
 
158
 
159
  def select_balanced_samples(samples):
160
  try:
161
+ # Ensure we have at least N unique samples
162
  unique_samples = list({(s['category'], s['file']) for s in samples})
163
 
164
+ if len(unique_samples) < SAMPLE_NUM:
165
  logger.warning(f"Not enough unique samples. Only {len(unique_samples)} available.")
166
  selected_samples = unique_samples
167
  else:
168
+ selected_samples = random.sample(unique_samples, SAMPLE_NUM)
169
 
170
  logger.info(f"Unique sampled samples:\n{selected_samples}")
171