CannaTech commited on
Commit
cb5d309
·
1 Parent(s): 776c1b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -8,9 +8,21 @@ import json
8
  # Set the OpenAI API key
9
  openai.api_key = os.getenv("OPENAI_API_KEY")
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Set up flagging callback function
12
  HF_TOKEN = os.getenv("HF_TOKEN")
13
- hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
14
 
15
  # Define the authentication function
16
  def check_auth(username, password):
 
8
  # Set the OpenAI API key
9
  openai.api_key = os.getenv("OPENAI_API_KEY")
10
 
11
+ class CustomHuggingFaceDatasetSaver(gr.FlaggingCallback):
12
+ def __init__(self, hf_token, dataset_name):
13
+ super().__init__()
14
+ self.hf_token = hf_token
15
+ self.dataset_name = dataset_name
16
+
17
+ def on_flag(self, sample):
18
+ if len(sample["output"]) > 1000:
19
+ sample["output"] = sample["output"][:1000] # Truncate output to 1000 characters
20
+
21
+ super().on_flag(sample)
22
+
23
  # Set up flagging callback function
24
  HF_TOKEN = os.getenv("HF_TOKEN")
25
+ hf_writer = CustomHuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
26
 
27
  # Define the authentication function
28
  def check_auth(username, password):