liyaoshi commited on
Commit
0810bda
·
verified ·
1 Parent(s): b8120dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -5,23 +5,23 @@ import os
5
  openai_api_key = os.environ.get('openai_api_key')
6
 
7
  def moderation(input_text,api_key=openai_api_key):
8
- headers = {
9
  "Content-Type": "application/json",
10
  "Authorization": f"Bearer {api_key}"
11
- }
12
- data = {
13
  "input": input_text
14
- }
15
-
16
- response = requests.post('https://api.openai.com/v1/moderations',headers=headers,json=data)
17
-
18
- result = response.json()['results'][0]
19
-
20
- flag = 1 if result['flagged'] else 0
21
- categories = result['categories']
22
- scores = result['category_scores']
23
-
24
- return flag,scores
25
 
26
 
27
 
 
5
  openai_api_key = os.environ.get('openai_api_key')
6
 
7
  def moderation(input_text,api_key=openai_api_key):
8
+ headers = {
9
  "Content-Type": "application/json",
10
  "Authorization": f"Bearer {api_key}"
11
+ }
12
+ data = {
13
  "input": input_text
14
+ }
15
+
16
+ response = requests.post('https://api.openai.com/v1/moderations',headers=headers,json=data)
17
+ print(response.json())
18
+ result = response.json()['results'][0]
19
+
20
+ flag = 1 if result['flagged'] else 0
21
+ categories = result['categories']
22
+ scores = result['category_scores']
23
+
24
+ return flag,scores
25
 
26
 
27