Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -52,21 +52,33 @@ def log_feedback(prompt, response, task, rating):
|
|
| 52 |
st.warning("HF_TOKEN not configured. Feedback not saved.")
|
| 53 |
return
|
| 54 |
|
| 55 |
-
new_data = {
|
| 56 |
-
"timestamp": [str(datetime.datetime.now())],
|
| 57 |
-
"task": [task],
|
| 58 |
-
"prompt": [prompt],
|
| 59 |
-
"response": [response],
|
| 60 |
-
"rating": [rating]
|
| 61 |
-
}
|
| 62 |
-
df = pd.DataFrame(new_data)
|
| 63 |
-
|
| 64 |
api = HfApi(token=hf_token)
|
| 65 |
-
csv_data = df.to_csv(index=False, header=False)
|
| 66 |
-
|
| 67 |
api.create_repo(repo_id=FEEDBACK_REPO, repo_type="dataset", exist_ok=True)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
filename = f"feedback_{datetime.date.today()}.csv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
api.upload_file(
|
| 71 |
path_or_fileobj=csv_data.encode(),
|
| 72 |
path_in_repo=filename,
|
|
|
|
| 52 |
st.warning("HF_TOKEN not configured. Feedback not saved.")
|
| 53 |
return
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
api = HfApi(token=hf_token)
|
|
|
|
|
|
|
| 56 |
api.create_repo(repo_id=FEEDBACK_REPO, repo_type="dataset", exist_ok=True)
|
| 57 |
|
| 58 |
+
now = datetime.datetime.now()
|
| 59 |
+
new_row = pd.DataFrame([{
|
| 60 |
+
"timestamp": str(now),
|
| 61 |
+
"task": task,
|
| 62 |
+
"prompt": prompt,
|
| 63 |
+
"response": response,
|
| 64 |
+
"rating": rating
|
| 65 |
+
}])
|
| 66 |
+
|
| 67 |
+
# One file per day — download existing, append, re-upload
|
| 68 |
filename = f"feedback_{datetime.date.today()}.csv"
|
| 69 |
+
try:
|
| 70 |
+
existing_path = api.hf_hub_download(
|
| 71 |
+
repo_id=FEEDBACK_REPO,
|
| 72 |
+
filename=filename,
|
| 73 |
+
repo_type="dataset",
|
| 74 |
+
token=hf_token,
|
| 75 |
+
)
|
| 76 |
+
existing_df = pd.read_csv(existing_path)
|
| 77 |
+
combined = pd.concat([existing_df, new_row], ignore_index=True)
|
| 78 |
+
except Exception:
|
| 79 |
+
combined = new_row
|
| 80 |
+
|
| 81 |
+
csv_data = combined.to_csv(index=False)
|
| 82 |
api.upload_file(
|
| 83 |
path_or_fileobj=csv_data.encode(),
|
| 84 |
path_in_repo=filename,
|