Karim-Gamal's picture
Update app.py
062e912
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()