Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,52 @@ import openai
|
|
4 |
import gradio as gr
|
5 |
import csv
|
6 |
import json
|
|
|
7 |
|
8 |
# Set the OpenAI API key
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
##################
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
class HuggingFaceDatasetSaver(FlaggingCallback):
|
14 |
"""
|
15 |
A callback that saves each flagged sample (both the input and output data)
|
|
|
4 |
import gradio as gr
|
5 |
import csv
|
6 |
import json
|
7 |
+
from abc import ABC, abstractmethod
|
8 |
|
9 |
# Set the OpenAI API key
|
10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
11 |
|
12 |
##################
|
13 |
|
14 |
+
class FlaggingCallback(ABC):
|
15 |
+
"""
|
16 |
+
An abstract class for defining the methods that any FlaggingCallback should have.
|
17 |
+
"""
|
18 |
+
|
19 |
+
@abstractmethod
|
20 |
+
def setup(self, components: List[IOComponent], flagging_dir: str):
|
21 |
+
"""
|
22 |
+
This method should be overridden and ensure that everything is set up correctly for flag().
|
23 |
+
This method gets called once at the beginning of the Interface.launch() method.
|
24 |
+
Parameters:
|
25 |
+
components: Set of components that will provide flagged data.
|
26 |
+
flagging_dir: A string, typically containing the path to the directory where the flagging file should be storied (provided as an argument to Interface.__init__()).
|
27 |
+
"""
|
28 |
+
pass
|
29 |
+
|
30 |
+
@abstractmethod
|
31 |
+
def flag(
|
32 |
+
self,
|
33 |
+
flag_data: List[Any],
|
34 |
+
flag_option: str | None = None,
|
35 |
+
flag_index: int | None = None,
|
36 |
+
username: str | None = None,
|
37 |
+
) -> int:
|
38 |
+
"""
|
39 |
+
This method should be overridden by the FlaggingCallback subclass and may contain optional additional arguments.
|
40 |
+
This gets called every time the <flag> button is pressed.
|
41 |
+
Parameters:
|
42 |
+
interface: The Interface object that is being used to launch the flagging interface.
|
43 |
+
flag_data: The data to be flagged.
|
44 |
+
flag_option (optional): In the case that flagging_options are provided, the flag option that is being used.
|
45 |
+
flag_index (optional): The index of the sample that is being flagged.
|
46 |
+
username (optional): The username of the user that is flagging the data, if logged in.
|
47 |
+
Returns:
|
48 |
+
(int) The total number of samples that have been flagged.
|
49 |
+
"""
|
50 |
+
pass
|
51 |
+
|
52 |
+
|
53 |
class HuggingFaceDatasetSaver(FlaggingCallback):
|
54 |
"""
|
55 |
A callback that saves each flagged sample (both the input and output data)
|