owaiskha9654
commited on
Commit
β’
3cb5cab
1
Parent(s):
3aa67a5
Update app.py
Browse files
app.py
CHANGED
@@ -22,25 +22,37 @@ model.config.id2label={
|
|
22 |
"4": "Openness",}
|
23 |
|
24 |
def Personality_Detection_from_reviews_submitted (model_input: str) -> Dict[str, float]:
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
model_input = gr.Textbox("Input text here (Note: This model is trained to classify Big Five Personality Traits From Expository text features)", show_label=False)
|
45 |
model_output = gr.Label(" Big-Five personality traits Result", num_top_classes=6, show_label=True, label="Big-Five personality traits Labels assigned to this text based on its features")
|
46 |
examples = [
|
|
|
22 |
"4": "Openness",}
|
23 |
|
24 |
def Personality_Detection_from_reviews_submitted (model_input: str) -> Dict[str, float]:
|
25 |
+
if len(model_input)<20:
|
26 |
+
ret ={
|
27 |
+
"Extroversion": float(0),
|
28 |
+
"Neuroticism": float(0),
|
29 |
+
"Agreeableness": float(0),
|
30 |
+
"Conscientiousness": float(0),
|
31 |
+
"Openness": float(0),}
|
32 |
+
return ret
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
else:
|
37 |
+
# Encoding input data
|
38 |
+
dict_custom={}
|
39 |
+
Preprocess_part1=model_input[:len(model_input)]
|
40 |
+
Preprocess_part2=model_input[len(model_input):]
|
41 |
+
dict1=tokenizer.encode_plus(Preprocess_part1,max_length=1024,padding=True,truncation=True)
|
42 |
+
dict2=tokenizer.encode_plus(Preprocess_part2,max_length=1024,padding=True,truncation=True)
|
43 |
+
dict_custom['input_ids']=[dict1['input_ids'],dict1['input_ids']]
|
44 |
+
dict_custom['token_type_ids']=[dict1['token_type_ids'],dict1['token_type_ids']]
|
45 |
+
dict_custom['attention_mask']=[dict1['attention_mask'],dict1['attention_mask']]
|
46 |
+
outs = model(torch.tensor(dict_custom['input_ids']), token_type_ids=None, attention_mask=torch.tensor(dict_custom['attention_mask']))
|
47 |
+
b_logit_pred = outs[0]
|
48 |
+
pred_label = torch.sigmoid(b_logit_pred)
|
49 |
+
ret ={
|
50 |
+
"Extroversion": float(pred_label[0][0]),
|
51 |
+
"Neuroticism": float(pred_label[0][1]),
|
52 |
+
"Agreeableness": float(pred_label[0][2]),
|
53 |
+
"Conscientiousness": float(pred_label[0][3]),
|
54 |
+
"Openness": float(pred_label[0][4]),}
|
55 |
+
return ret
|
56 |
model_input = gr.Textbox("Input text here (Note: This model is trained to classify Big Five Personality Traits From Expository text features)", show_label=False)
|
57 |
model_output = gr.Label(" Big-Five personality traits Result", num_top_classes=6, show_label=True, label="Big-Five personality traits Labels assigned to this text based on its features")
|
58 |
examples = [
|