Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,32 +8,23 @@ import json
|
|
8 |
# Set the OpenAI API key
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
def setup(self):
|
14 |
-
pass
|
15 |
-
|
16 |
-
def apply(self, flagged_samples):
|
17 |
-
for sample in flagged_samples:
|
18 |
-
input_data = sample["input"]
|
19 |
-
output_data = sample["output"]
|
20 |
-
flag = sample["flag"]
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
writer.writerow([input_data, output_data, flag])
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
|
36 |
|
|
|
37 |
# Define the authentication function
|
38 |
def check_auth(username, password):
|
39 |
# Get the credentials from the environment variable
|
@@ -150,7 +141,7 @@ iface = gr.Interface(
|
|
150 |
favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
|
151 |
allow_flagging="manual", # Enable flagging with manual control
|
152 |
flagging_options=["Incorrect"],
|
153 |
-
flagging_callback=
|
154 |
)
|
155 |
|
156 |
# Launch the interface with authentication
|
|
|
8 |
# Set the OpenAI API key
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
+
# Set up the Hugging Face Dataset Saver
|
12 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
class CustomFlaggingCallback:
|
15 |
+
def __init__(self, hf_token, dataset_name):
|
16 |
+
self.hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
|
17 |
|
18 |
+
def __call__(self, input_data, output_data):
|
19 |
+
# Custom logic to handle flagged data
|
20 |
+
# Example: Save flagged data to Hugging Face Dataset without writing the output to JSON file
|
21 |
+
self.hf_writer.add_data(input_data)
|
22 |
+
self.hf_writer.flush()
|
|
|
23 |
|
24 |
+
# Create an instance of the custom flagging callback
|
25 |
+
custom_callback = CustomFlaggingCallback(HF_TOKEN, "CannaTech/Flagged")
|
|
|
26 |
|
27 |
+
|
28 |
# Define the authentication function
|
29 |
def check_auth(username, password):
|
30 |
# Get the credentials from the environment variable
|
|
|
141 |
favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
|
142 |
allow_flagging="manual", # Enable flagging with manual control
|
143 |
flagging_options=["Incorrect"],
|
144 |
+
flagging_callback=custom_callback
|
145 |
)
|
146 |
|
147 |
# Launch the interface with authentication
|