mislavb commited on
Commit
3d3344e
·
1 Parent(s): c123d93

add moderation

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -324,8 +324,15 @@ def run_summary_hard():
324
  rows = cur.fetchall()
325
 
326
  print("[run_hard] fetched these rows: ")
 
 
327
  for row in rows:
328
- print(row)
 
 
 
 
 
329
 
330
  rows = [[row[2], row[3]] for row in rows]
331
 
@@ -342,6 +349,7 @@ def run_summary_hard():
342
  # add new rows to random positions in the table
343
  for new_row in new_rows:
344
  rows.insert(random.randint(0, len(rows)), new_row)
 
345
 
346
  summary = get_summary(rows)
347
  print("hard summary: ", summary)
 
324
  rows = cur.fetchall()
325
 
326
  print("[run_hard] fetched these rows: ")
327
+ client = openai.Client(api_key=openai_api_key)
328
+ tmp_rows = []
329
  for row in rows:
330
+ moderated = client.moderations.create(input=row[2] + "_" + row[3])
331
+ flagged = moderated.results[0].flagged
332
+ print(row, flagged)
333
+ if not flagged:
334
+ tmp_rows.append(row)
335
+ rows = tmp_rows
336
 
337
  rows = [[row[2], row[3]] for row in rows]
338
 
 
349
  # add new rows to random positions in the table
350
  for new_row in new_rows:
351
  rows.insert(random.randint(0, len(rows)), new_row)
352
+ print("new row: ", new_row)
353
 
354
  summary = get_summary(rows)
355
  print("hard summary: ", summary)