DeepLearning101 commited on
Commit
79e69f0
1 Parent(s): 7776b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -20,11 +20,26 @@ if HF_API_TOKEN is None:
20
  # 設置 Hugging Face API 令牌
21
  HfFolder.save_token(HF_API_TOKEN)
22
 
 
 
 
 
 
 
 
 
23
  # 加載或創建數據集
24
  try:
25
  dataset = load_dataset(DATASET_NAME)
26
  except:
27
- dataset = DatasetDict({"feedback": Dataset.from_dict({"user_input": [], "response": [], "feedback_type": [], "improvement": []})})
 
 
 
 
 
 
 
28
 
29
  async def send_chat_message(user_input):
30
  payload = {
@@ -90,9 +105,14 @@ def save_feedback(user_input, response, feedback_type, improvement):
90
  }
91
  print(f"Saving feedback: {feedback}")
92
  # Append to the dataset
93
- new_data = {"user_input": user_input, "response": response, "feedback_type": feedback_type, "improvement": improvement}
 
 
 
 
 
94
  global dataset
95
- dataset = dataset["feedback"].add_item(new_data)
96
  dataset.push_to_hub(DATASET_NAME)
97
 
98
  def handle_feedback(response, feedback_type, improvement):
@@ -165,5 +185,4 @@ with gr.Blocks() as iface:
165
 
166
  show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
167
 
168
-
169
  iface.launch()
 
20
  # 設置 Hugging Face API 令牌
21
  HfFolder.save_token(HF_API_TOKEN)
22
 
23
+ # 定義數據集特徵
24
+ features = {
25
+ "user_input": "string",
26
+ "response": "string",
27
+ "feedback_type": "string",
28
+ "improvement": "string"
29
+ }
30
+
31
  # 加載或創建數據集
32
  try:
33
  dataset = load_dataset(DATASET_NAME)
34
  except:
35
+ dataset = DatasetDict({
36
+ "feedback": Dataset.from_dict({
37
+ "user_input": [],
38
+ "response": [],
39
+ "feedback_type": [],
40
+ "improvement": []
41
+ })
42
+ })
43
 
44
  async def send_chat_message(user_input):
45
  payload = {
 
105
  }
106
  print(f"Saving feedback: {feedback}")
107
  # Append to the dataset
108
+ new_data = {
109
+ "user_input": [user_input],
110
+ "response": [response],
111
+ "feedback_type": [feedback_type],
112
+ "improvement": [improvement]
113
+ }
114
  global dataset
115
+ dataset["feedback"] = dataset["feedback"].add_item(new_data)
116
  dataset.push_to_hub(DATASET_NAME)
117
 
118
  def handle_feedback(response, feedback_type, improvement):
 
185
 
186
  show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
187
 
 
188
  iface.launch()