Commit
·
062e912
1
Parent(s):
0448e63
Update app.py
Browse files
app.py
CHANGED
@@ -12,41 +12,37 @@ def classify_gender_equality(password, input_sentence):
|
|
12 |
|
13 |
# set up OpenAI API key
|
14 |
openai.api_key = password
|
|
|
15 |
# Set up the fine-tuned model for gender equality classification
|
16 |
-
model_engine = "text-davinci-003"
|
17 |
model_prompt = ("""
|
18 |
Please classify the following sentence as promoting or not promoting gender equality:
|
19 |
|
20 |
Sentence:
|
21 |
""")
|
22 |
|
23 |
-
# The gender equality classification API endpoint
|
24 |
-
endpoint = "text-davinci-003"
|
25 |
-
|
26 |
def is_gender_equal(sentence):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
# Example usage
|
40 |
# sentence = "Women are capable as men in leadership roles."
|
41 |
# sentence = "Women are not as capable as men in leadership roles."
|
42 |
# sentence = "Gender equality is important for the progress of society."
|
43 |
-
|
44 |
-
|
45 |
-
# print(f"'{sentence}' is promoting gender equality.")
|
46 |
-
return "This sentence is promoting gender equality."
|
47 |
-
else:
|
48 |
-
# print(f"'{sentence}' is not promoting gender equality.")
|
49 |
-
return "This sentence is not promoting gender equality."
|
50 |
|
51 |
# Create the input text fields
|
52 |
password_input = gr.inputs.Textbox(label="OpenAI API key", type="password")
|
|
|
12 |
|
13 |
# set up OpenAI API key
|
14 |
openai.api_key = password
|
15 |
+
|
16 |
# Set up the fine-tuned model for gender equality classification
|
17 |
+
# model_engine = "text-davinci-003"
|
18 |
model_prompt = ("""
|
19 |
Please classify the following sentence as promoting or not promoting gender equality:
|
20 |
|
21 |
Sentence:
|
22 |
""")
|
23 |
|
|
|
|
|
|
|
24 |
def is_gender_equal(sentence):
|
25 |
+
prompt = model_prompt + sentence
|
26 |
+
completions = openai.Completion.create(
|
27 |
+
engine="text-davinci-003", # The gender equality classification API endpoint
|
28 |
+
prompt=prompt,
|
29 |
+
max_tokens=1024,
|
30 |
+
n=1,
|
31 |
+
stop=None,
|
32 |
+
temperature=0.5,
|
33 |
+
)
|
34 |
+
message = completions.choices[0].text
|
35 |
+
return message.strip().lower()
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
|
40 |
# Example usage
|
41 |
# sentence = "Women are capable as men in leadership roles."
|
42 |
# sentence = "Women are not as capable as men in leadership roles."
|
43 |
# sentence = "Gender equality is important for the progress of society."
|
44 |
+
|
45 |
+
return "This Sentence is " + is_gender_equal(input_sentence)
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Create the input text fields
|
48 |
password_input = gr.inputs.Textbox(label="OpenAI API key", type="password")
|