lg3394 commited on
Commit
6d5858a
·
verified ·
1 Parent(s): ee52c90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -2,8 +2,7 @@ import gradio as gr
2
  import openai
3
  import os
4
 
5
- # Set your API key securely
6
- openai.api_key = os.getenv("OPENAI_API_KEY") # Store your key in an environment variable
7
 
8
  def moderate_text(text):
9
  text = str(text).strip() if text else ""
@@ -12,12 +11,10 @@ def moderate_text(text):
12
  return "Input text is empty. Please enter valid text."
13
 
14
  try:
15
- # Check if Moderation is supported
16
  response = openai.Moderation.create(
17
  input=text
18
  )
19
 
20
- # Extract moderation results
21
  moderation_categories = response["results"][0]["categories"]
22
  moderation_flagged = response["results"][0]["flagged"]
23
 
@@ -26,5 +23,5 @@ def moderate_text(text):
26
  return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
27
  else:
28
  return "The text is not flagged for any moderation issues."
29
- except AttributeError as ae:
30
 
 
2
  import openai
3
  import os
4
 
5
+ openai.api_key = os.getenv("OPENAI_API_KEY")
 
6
 
7
  def moderate_text(text):
8
  text = str(text).strip() if text else ""
 
11
  return "Input text is empty. Please enter valid text."
12
 
13
  try:
 
14
  response = openai.Moderation.create(
15
  input=text
16
  )
17
 
 
18
  moderation_categories = response["results"][0]["categories"]
19
  moderation_flagged = response["results"][0]["flagged"]
20
 
 
23
  return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
24
  else:
25
  return "The text is not flagged for any moderation issues."
26
+ except AttributeError as ae:
27