DeepLearning101 commited on
Commit
6ca9070
1 Parent(s): 41f9aa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -6,13 +6,21 @@ import json
6
  from datasets import Dataset, DatasetDict, load_dataset, load_from_disk
7
  from huggingface_hub import HfApi, HfFolder
8
 
9
- HEA_API_TOKEN = os.environ.get("HF_API_TOKEN")
 
10
  LLM_API = os.environ.get("LLM_API")
11
  LLM_URL = os.environ.get("LLM_URL")
12
  USER_ID = "HuggingFace Space"
13
- HfFolder.save_token(HEA_API_TOKEN)
14
  DATASET_NAME = os.environ.get("DATASET_NAME")
15
 
 
 
 
 
 
 
 
 
16
  try:
17
  dataset = load_dataset(DATASET_NAME)
18
  except:
@@ -88,11 +96,6 @@ def save_feedback(user_input, response, feedback_type, improvement):
88
  dataset.push_to_hub(DATASET_NAME)
89
 
90
  def handle_feedback(response, feedback_type, improvement):
91
- feedback = {
92
- "response": response,
93
- "feedback_type": feedback_type,
94
- "improvement": improvement
95
- }
96
  save_feedback(response, feedback_type, improvement)
97
  return "Thank you for your feedback!"
98
 
 
6
  from datasets import Dataset, DatasetDict, load_dataset, load_from_disk
7
  from huggingface_hub import HfApi, HfFolder
8
 
9
+ # 从环境变量中获取 Hugging Face API 令牌和其他配置
10
+ HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
11
  LLM_API = os.environ.get("LLM_API")
12
  LLM_URL = os.environ.get("LLM_URL")
13
  USER_ID = "HuggingFace Space"
 
14
  DATASET_NAME = os.environ.get("DATASET_NAME")
15
 
16
+ # 确保令牌不为空
17
+ if HF_API_TOKEN is None:
18
+ raise ValueError("HF_API_TOKEN 环境变量未设置。请在 Hugging Face Space 的设置中添加该环境变量。")
19
+
20
+ # 设置 Hugging Face API 令牌
21
+ HfFolder.save_token(HF_API_TOKEN)
22
+
23
+ # 加载或创建数据集
24
  try:
25
  dataset = load_dataset(DATASET_NAME)
26
  except:
 
96
  dataset.push_to_hub(DATASET_NAME)
97
 
98
  def handle_feedback(response, feedback_type, improvement):
 
 
 
 
 
99
  save_feedback(response, feedback_type, improvement)
100
  return "Thank you for your feedback!"
101