JohanBeytell commited on
Commit
8d314d3
·
verified ·
1 Parent(s): d46ffba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -96,15 +96,16 @@ sp.Load("dungen_dev_preview.model")
96
  model = tf.keras.models.load_model("dungen_dev_preview_model.keras")
97
  max_seq_len = 25
98
 
99
- # Logging setup
100
- CSV_FILE = "flagged_outputs.csv"
101
- if not os.path.exists(CSV_FILE):
102
- with open(CSV_FILE, "w", newline="", encoding="utf-8") as csvfile: #added encoding
103
- writer = csv.writer(csvfile)
104
- writer.writerow(["Timestamp", "Flagged Text"])
105
-
106
  logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
107
 
 
 
 
 
 
 
 
 
108
  def generate_text(seed_text, next_words=30, temperature=0.5):
109
  seed_text = seed_text.strip().lower()
110
 
@@ -151,12 +152,17 @@ def generate_text(seed_text, next_words=30, temperature=0.5):
151
 
152
  return decoded
153
 
154
- def flag_output(text):
155
- logging.info(f"Output flagged: {text}")
 
 
 
156
  timestamp = datetime.now().isoformat()
157
- with open(CSV_FILE, "a", newline="", encoding="utf-8") as csvfile: #added encoding
158
- writer = csv.writer(csvfile)
159
- writer.writerow([timestamp, text])
 
 
160
  return "Output Flagged. Thank you for your feedback."
161
 
162
  with gr.Blocks() as demo:
 
96
  model = tf.keras.models.load_model("dungen_dev_preview_model.keras")
97
  max_seq_len = 25
98
 
 
 
 
 
 
 
 
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()
111
 
 
152
 
153
  return decoded
154
 
155
+ def flag_output(prompt_used, text_flagged):
156
+ if not text_flagged.strip(): # Check for empty or whitespace-only strings
157
+ return "Cannot flag an empty output."
158
+
159
+ logging.info(f"Output flagged: {text_flagged} with prompt: {prompt_used}")
160
  timestamp = datetime.now().isoformat()
161
+ new_data = {"Timestamp": [timestamp], "Prompt": [prompt_used], "Flagged Text": [text_flagged]}
162
+ new_dataset = Dataset.from_dict(new_data)
163
+ global flagged_dataset
164
+ flagged_dataset = Dataset.from_pandas(flagged_dataset.to_pandas().append(new_dataset.to_pandas(), ignore_index=True))
165
+ flagged_dataset.push_to_hub(FLAGGED_DATASET_ID)
166
  return "Output Flagged. Thank you for your feedback."
167
 
168
  with gr.Blocks() as demo: