Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,18 @@ import json
|
|
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 =
|
14 |
|
15 |
# Define the authentication function
|
16 |
def check_auth(username, password):
|
|
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
# Set up flagging callback function
|
12 |
+
class CustomHuggingFaceDatasetSaver(gr.FlaggingCallback):
|
13 |
+
def __init__(self, hf_token, hf_dataset, max_output_length=100):
|
14 |
+
super().__init__(hf_token, hf_dataset)
|
15 |
+
self.max_output_length = max_output_length
|
16 |
+
|
17 |
+
def flag(self, inputs, outputs, predicted_outputs):
|
18 |
+
if predicted_outputs is not None:
|
19 |
+
predicted_outputs = predicted_outputs[:self.max_output_length]
|
20 |
+
super().flag(inputs, outputs, predicted_outputs)
|
21 |
+
|
22 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
23 |
+
hf_writer = CustomHuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
|
24 |
|
25 |
# Define the authentication function
|
26 |
def check_auth(username, password):
|