JohanBeytell commited on
Commit
61f9507
·
verified ·
1 Parent(s): a2f6b94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
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" # Replace with your dataset ID
103
- try:
104
- flagged_dataset = load_dataset(FLAGGED_DATASET_ID)
105
- except:
106
- flagged_dataset = Dataset.from_dict({"Timestamp": [], "Prompt": [], "Flagged Text": []})
107
- flagged_dataset.push_to_hub(FLAGGED_DATASET_ID)
 
 
 
 
 
 
 
 
 
 
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()