|
import os |
|
import openai |
|
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
def classify_gender_equality(password, input_sentence): |
|
|
|
|
|
|
|
|
|
openai.api_key = password |
|
|
|
|
|
|
|
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", |
|
prompt=prompt, |
|
max_tokens=1024, |
|
n=1, |
|
stop=None, |
|
temperature=0.5, |
|
) |
|
message = completions.choices[0].text |
|
return message.strip().lower() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "This Sentence is " + is_gender_equal(input_sentence) |
|
|
|
|
|
password_input = gr.inputs.Textbox(label="OpenAI API key", type="password") |
|
|
|
input_text = gr.inputs.Textbox(label="Input Sentence", default="Women deserve equal pay") |
|
|
|
|
|
output_text = gr.outputs.Textbox(label="Gender Equality Classification") |
|
|
|
|
|
gr.Interface(fn=classify_gender_equality, inputs=[password_input, input_text], outputs=output_text, title='Gender Equality Classification').launch() |