Karim-Gamal commited on
Commit
0448e63
1 Parent(s): 49a00eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+
4
+ import gradio as gr
5
+
6
+
7
+ # ex_list = [["Women are not as capable as men in leadership roles."],["Women are capable as men in leadership roles."]]
8
+
9
+ def classify_gender_equality(password, input_sentence):
10
+ # Here goes your code to classify gender equality from input_sentence
11
+ # Return the result as a string
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
+ prompt = model_prompt + sentence
28
+ completions = openai.Completion.create(
29
+ engine=endpoint,
30
+ prompt=prompt,
31
+ max_tokens=1024,
32
+ n=1,
33
+ stop=None,
34
+ temperature=0.5,
35
+ )
36
+ message = completions.choices[0].text
37
+ return message.strip().lower() == "promoting gender equality"
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
+ sentence = input_sentence
44
+ if is_gender_equal(sentence):
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")
53
+
54
+ input_text = gr.inputs.Textbox(label="Input Sentence", default="Women deserve equal pay")
55
+
56
+ # Create the output text field
57
+ output_text = gr.outputs.Textbox(label="Gender Equality Classification")
58
+
59
+ # Create the Gradio interface
60
+ gr.Interface(fn=classify_gender_equality, inputs=[password_input, input_text], outputs=output_text, title='Gender Equality Classification').launch()