akhatr-phyniks commited on
Commit
6cbff2d
·
verified ·
1 Parent(s): f9e74f5

adds feedback-dataset

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -8,6 +8,7 @@ from dotenv import load_dotenv
8
  import csv
9
  from datetime import datetime
10
  import json
 
11
 
12
  # Load environment variables from .env file if it exists
13
  load_dotenv()
@@ -35,8 +36,9 @@ FEEDBACK_FILE = "feedback.csv"
35
  FEEDBACK_HEADERS = ["timestamp", "session_id", "message", "response", "rating", "comment"]
36
 
37
  def save_feedback(session_id, message, response, rating, comment):
38
- """Save feedback to CSV file."""
39
  try:
 
40
  file_exists = os.path.isfile(FEEDBACK_FILE)
41
  with open(FEEDBACK_FILE, 'a', newline='') as f:
42
  writer = csv.DictWriter(f, fieldnames=FEEDBACK_HEADERS)
@@ -50,6 +52,20 @@ def save_feedback(session_id, message, response, rating, comment):
50
  "rating": rating,
51
  "comment": comment
52
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  except Exception as e:
54
  print(f"Error saving feedback: {e}")
55
 
 
8
  import csv
9
  from datetime import datetime
10
  import json
11
+ import huggingface_hub
12
 
13
  # Load environment variables from .env file if it exists
14
  load_dotenv()
 
36
  FEEDBACK_HEADERS = ["timestamp", "session_id", "message", "response", "rating", "comment"]
37
 
38
  def save_feedback(session_id, message, response, rating, comment):
39
+ """Save feedback to CSV file and upload to Hugging Face."""
40
  try:
41
+ # Save to local CSV file
42
  file_exists = os.path.isfile(FEEDBACK_FILE)
43
  with open(FEEDBACK_FILE, 'a', newline='') as f:
44
  writer = csv.DictWriter(f, fieldnames=FEEDBACK_HEADERS)
 
52
  "rating": rating,
53
  "comment": comment
54
  })
55
+
56
+ # Upload to Hugging Face if token is available
57
+ hf_token = os.getenv("HF_TOKEN")
58
+ if hf_token:
59
+ try:
60
+ api = huggingface_hub.HfApi(token=hf_token)
61
+ api.upload_file(
62
+ path_or_fileobj=FEEDBACK_FILE,
63
+ path_in_repo=FEEDBACK_FILE,
64
+ repo_id=os.getenv("HF_REPO_ID", "your-username/your-repo"),
65
+ repo_type="dataset"
66
+ )
67
+ except Exception as e:
68
+ print(f"Warning: Failed to upload feedback to Hugging Face: {e}")
69
  except Exception as e:
70
  print(f"Error saving feedback: {e}")
71