Spaces:
Running
Running
raj-tomar001
commited on
Commit
•
cdbcd6b
1
Parent(s):
a4ddd85
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import DebertaTokenizer, DebertaForSequenceClassification
|
3 |
from transformers import pipeline
|
4 |
import json
|
5 |
|
6 |
|
7 |
-
save_path_abstract = './fine-tuned-
|
8 |
-
model_abstract =
|
9 |
-
tokenizer_abstract =
|
10 |
|
11 |
classifier_abstract = pipeline('text-classification', model=model_abstract, tokenizer=tokenizer_abstract)
|
12 |
|
13 |
-
save_path_essay = './fine-tuned-
|
14 |
-
model_essay =
|
15 |
-
tokenizer_essay =
|
16 |
|
17 |
classifier_essay = pipeline('text-classification', model=model_essay, tokenizer=tokenizer_essay)
|
18 |
|
@@ -36,18 +36,13 @@ def process_result_detection_tab(text):
|
|
36 |
'Human Written, Machine Polished': float: the probability that the text is human written and machine polished
|
37 |
'''
|
38 |
mapping = {'llm': 'Machine Generated', 'human':'Human Written', 'machine-humanized': 'Machine Written, Machine Humanized', 'machine-polished': 'Human Written, Machine Polished'}
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# Add scores from classifier_abstract
|
44 |
-
if result['label'] in mapping:
|
45 |
-
final_results[mapping[result['label']]] += 0.5 * result['score']
|
46 |
-
|
47 |
-
# Add scores from classifier_essay
|
48 |
-
if result_r['label'] in mapping:
|
49 |
-
final_results[mapping[result_r['label']]] += 0.5 * result_r['score']
|
50 |
|
|
|
51 |
print(final_results)
|
52 |
return final_results
|
53 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import DebertaTokenizer, DebertaForSequenceClassification, DistilBertTokenizer, DistilBertForSequenceClassification
|
3 |
from transformers import pipeline
|
4 |
import json
|
5 |
|
6 |
|
7 |
+
save_path_abstract = './fine-tuned-distillberta'
|
8 |
+
model_abstract = DistilBertForSequenceClassification.from_pretrained(save_path_abstract)
|
9 |
+
tokenizer_abstract = DistilBertTokenizer.from_pretrained(save_path_abstract)
|
10 |
|
11 |
classifier_abstract = pipeline('text-classification', model=model_abstract, tokenizer=tokenizer_abstract)
|
12 |
|
13 |
+
save_path_essay = './fine-tuned-distillberta'
|
14 |
+
model_essay = DistilBertForSequenceClassification.from_pretrained(save_path_essay)
|
15 |
+
tokenizer_essay = DistilBertTokenizer.from_pretrained(save_path_essay)
|
16 |
|
17 |
classifier_essay = pipeline('text-classification', model=model_essay, tokenizer=tokenizer_essay)
|
18 |
|
|
|
36 |
'Human Written, Machine Polished': float: the probability that the text is human written and machine polished
|
37 |
'''
|
38 |
mapping = {'llm': 'Machine Generated', 'human':'Human Written', 'machine-humanized': 'Machine Written, Machine Humanized', 'machine-polished': 'Human Written, Machine Polished'}
|
39 |
+
result = classifier_abstract(text)
|
40 |
+
result_r = classifier_essay(text)
|
41 |
|
42 |
+
labels = [mapping[x['label']] for x in result]
|
43 |
+
scores = list(0.5 * np.array([x['score'] for x in result]) + 0.5 * np.array([x['score'] for x in result_r]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
final_results = dict(zip(labels, scores))
|
46 |
print(final_results)
|
47 |
return final_results
|
48 |
|