Spaces:
Runtime error
Runtime error
Commit
·
6f0c225
1
Parent(s):
f0dcd05
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,32 @@
|
|
1 |
# import the main classes
|
2 |
-
import
|
3 |
-
import torch
|
4 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
|
6 |
|
7 |
-
# Load the model.
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
9 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
10 |
-
|
11 |
# input examples list
|
12 |
ex_list = [["Women are not as capable as men in leadership roles."],["Women are capable as men in leadership roles."]]
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
top_p=0.9,
|
23 |
-
top_k=0,
|
24 |
-
num_return_sequences=1,
|
25 |
-
)
|
26 |
-
return tokenizer.decode(output[0], skip_special_tokens=True)
|
27 |
|
28 |
def classify_gender_equality(input_sentence):
|
29 |
# Here goes your code to classify gender equality from input_sentence
|
30 |
# Return the result as a string
|
31 |
|
32 |
-
|
33 |
# sub_text = 'Gender equality is important for the progress of society.'
|
34 |
sub_text = input_sentence
|
35 |
-
prompt = f"Please classify the this sentence {sub_text} as promoting or not promoting gender equality
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
|
42 |
|
|
|
1 |
# import the main classes
|
2 |
+
import requests
|
|
|
|
|
3 |
|
4 |
|
|
|
|
|
|
|
|
|
5 |
# input examples list
|
6 |
ex_list = [["Women are not as capable as men in leadership roles."],["Women are capable as men in leadership roles."]]
|
7 |
|
8 |
+
|
9 |
+
API_URL_Switch = "https://api-inference.huggingface.co/models/google/flan-t5-base"
|
10 |
+
headers_Switch = {"Authorization": "Bearer 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"}
|
11 |
+
|
12 |
+
|
13 |
+
def query_Switch(payload):
|
14 |
+
response = requests.post(API_URL_Switch, headers=headers_Switch, json=payload)
|
15 |
+
return response.json()
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def classify_gender_equality(input_sentence):
|
18 |
# Here goes your code to classify gender equality from input_sentence
|
19 |
# Return the result as a string
|
20 |
|
|
|
21 |
# sub_text = 'Gender equality is important for the progress of society.'
|
22 |
sub_text = input_sentence
|
23 |
+
prompt = f"Please classify the this sentence ( {sub_text} ) as promoting or not promoting gender equality"
|
24 |
+
|
25 |
+
output_temp = query_Switch({
|
26 |
+
"inputs": prompt,
|
27 |
+
})
|
28 |
+
|
29 |
+
return "This sentence is " + output_temp[0]['generated_text'] + " for gender equality"
|
30 |
|
31 |
|
32 |
|