jmcinern commited on
Commit
c42b6b7
·
verified ·
1 Parent(s): a7ef04b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -10,6 +10,12 @@ from pathlib import Path
10
  import json
11
  import hashlib
12
  from filelock import FileLock
 
 
 
 
 
 
13
 
14
 
15
  PAIRS_CSV = Path("pairs.csv") # columns: run_id, model, source_type, instruction, response, text
@@ -109,9 +115,30 @@ def save_row(annotator_type, item, choice):
109
  "response_B": item["response_B"],
110
  "timestamp": time.time(),
111
  }
112
- # Concurrency-safe append
 
113
  with FileLock(str(LOCK_FILE)):
114
- pd.DataFrame([row]).to_csv(OUT_FILE, mode="a", header=False, index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  QUESTION_MD = (
117
  "**Question:** Which Question–Answer pair exhibits a stronger command of Irish grammar and "
 
10
  import json
11
  import hashlib
12
  from filelock import FileLock
13
+ from huggingface_hub import HfApi
14
+ import os
15
+
16
+ HF_DATASET_REPO = "jmcinern/Irish_Prompt_Response_Human_Feedback"
17
+ HF_TOKEN = os.environ.get("hf_write")
18
+ api = HfApi()
19
 
20
 
21
  PAIRS_CSV = Path("pairs.csv") # columns: run_id, model, source_type, instruction, response, text
 
115
  "response_B": item["response_B"],
116
  "timestamp": time.time(),
117
  }
118
+
119
+ # append safely to local /data/annotations.csv
120
  with FileLock(str(LOCK_FILE)):
121
+ df = pd.DataFrame([row])
122
+ df.to_csv(OUT_FILE, mode="a", header=False, index=False)
123
+
124
+ # prepare filename per role + source
125
+ filename = f"annotations_{item['source_type']}_{annotator_type}.csv"
126
+
127
+ # push to HF dataset repo
128
+ if HF_TOKEN:
129
+ try:
130
+ api.upload_file(
131
+ path_or_fileobj=str(OUT_FILE),
132
+ path_in_repo=filename,
133
+ repo_id=HF_DATASET_REPO,
134
+ repo_type="dataset",
135
+ token=HF_TOKEN,
136
+ )
137
+ print(f"[HF] Uploaded {filename} to {HF_DATASET_REPO}")
138
+ except Exception as e:
139
+ print(f"[HF] Upload failed: {e}")
140
+
141
+
142
 
143
  QUESTION_MD = (
144
  "**Question:** Which Question–Answer pair exhibits a stronger command of Irish grammar and "