Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -99,12 +99,22 @@ max_seq_len = 25
|
|
99 |
logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
100 |
|
101 |
# Dataset setup
|
102 |
-
FLAGGED_DATASET_ID = "InfinitodeLTD/DungenDev-FlaggedOutputs"
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
def generate_text(seed_text, next_words=30, temperature=0.5):
|
110 |
seed_text = seed_text.strip().lower()
|
|
|
99 |
logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
100 |
|
101 |
# Dataset setup
|
102 |
+
FLAGGED_DATASET_ID = "InfinitodeLTD/DungenDev-FlaggedOutputs"
|
103 |
+
|
104 |
+
def load_or_create_dataset(dataset_id):
|
105 |
+
try:
|
106 |
+
dataset = load_dataset(dataset_id)
|
107 |
+
if "flagged_data" not in dataset:
|
108 |
+
raise ValueError("Dataset does not contain the 'flagged_data' config.")
|
109 |
+
|
110 |
+
return dataset["flagged_data"]
|
111 |
+
except (datasets.DatasetNotFoundError, ValueError) as e:
|
112 |
+
logging.warning(f"Dataset not found or incorrect schema: {e}. Creating a new dataset.")
|
113 |
+
dataset = Dataset.from_dict({"Timestamp": [], "Prompt": [], "Flagged Text": []})
|
114 |
+
dataset.push_to_hub(dataset_id, config_name="flagged_data") # important: config_name
|
115 |
+
return dataset
|
116 |
+
|
117 |
+
flagged_dataset = load_or_create_dataset(FLAGGED_DATASET_ID)
|
118 |
|
119 |
def generate_text(seed_text, next_words=30, temperature=0.5):
|
120 |
seed_text = seed_text.strip().lower()
|