Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,27 +8,9 @@ import json
|
|
8 |
# Set the OpenAI API key
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
-
# Set up
|
12 |
-
class CustomFlaggingCallback(gr.FlaggingCallback):
|
13 |
-
def __init__(self, hf_token, dataset_name):
|
14 |
-
self.hf_writer = gr.HuggingFaceDatasetSaver(hf_token, dataset_name)
|
15 |
-
|
16 |
-
def setup(self, interface, interface_state):
|
17 |
-
pass
|
18 |
-
|
19 |
-
def flag(self, flagged_data):
|
20 |
-
# Custom logic to handle flagged data
|
21 |
-
# Example: Save flagged data to Hugging Face Dataset without writing the output to JSON file
|
22 |
-
self.hf_writer.add_data(flagged_data["input"])
|
23 |
-
self.hf_writer.flush()
|
24 |
-
|
25 |
-
# Define your Hugging Face API token and dataset name
|
26 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
27 |
-
|
28 |
-
|
29 |
-
# Create an instance of the custom flagging callback
|
30 |
-
custom_callback = CustomFlaggingCallback(HF_TOKEN, DATASET_NAME)
|
31 |
-
|
32 |
|
33 |
# Define the authentication function
|
34 |
def check_auth(username, password):
|
@@ -146,7 +128,7 @@ iface = gr.Interface(
|
|
146 |
favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
|
147 |
allow_flagging="manual", # Enable flagging with manual control
|
148 |
flagging_options=["Incorrect"],
|
149 |
-
flagging_callback=
|
150 |
)
|
151 |
|
152 |
# Launch the interface with authentication
|
|
|
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):
|
|
|
128 |
favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
|
129 |
allow_flagging="manual", # Enable flagging with manual control
|
130 |
flagging_options=["Incorrect"],
|
131 |
+
flagging_callback=hf_writer
|
132 |
)
|
133 |
|
134 |
# Launch the interface with authentication
|