File size: 1,852 Bytes
0448e63 062e912 0448e63 062e912 0448e63 062e912 0448e63 062e912 0448e63 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import os
import openai
import gradio as gr
# ex_list = [["Women are not as capable as men in leadership roles."],["Women are capable as men in leadership roles."]]
def classify_gender_equality(password, input_sentence):
# Here goes your code to classify gender equality from input_sentence
# Return the result as a string
# set up OpenAI API key
openai.api_key = password
# Set up the fine-tuned model for gender equality classification
# model_engine = "text-davinci-003"
model_prompt = ("""
Please classify the following sentence as promoting or not promoting gender equality:
Sentence:
""")
def is_gender_equal(sentence):
prompt = model_prompt + sentence
completions = openai.Completion.create(
engine="text-davinci-003", # The gender equality classification API endpoint
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip().lower()
# Example usage
# sentence = "Women are capable as men in leadership roles."
# sentence = "Women are not as capable as men in leadership roles."
# sentence = "Gender equality is important for the progress of society."
return "This Sentence is " + is_gender_equal(input_sentence)
# Create the input text fields
password_input = gr.inputs.Textbox(label="OpenAI API key", type="password")
input_text = gr.inputs.Textbox(label="Input Sentence", default="Women deserve equal pay")
# Create the output text field
output_text = gr.outputs.Textbox(label="Gender Equality Classification")
# Create the Gradio interface
gr.Interface(fn=classify_gender_equality, inputs=[password_input, input_text], outputs=output_text, title='Gender Equality Classification').launch() |