Spaces:
Running
Running
aliasgerovs
commited on
Commit
•
eb8fa16
1
Parent(s):
1c49ee1
Updated
Browse files- app.py +4 -4
- predictors.py +1 -38
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from datetime import date
|
4 |
-
from predictors import predict_bc_scores, predict_mc_scores
|
5 |
from analysis import depth_analysis
|
6 |
from predictors import predict_quillbot
|
7 |
from plagiarism import plagiarism_check, build_date
|
@@ -27,7 +27,7 @@ def ai_generated_test(option, input, models):
|
|
27 |
if option == "Human vs AI":
|
28 |
return predict_bc_scores(input), None
|
29 |
elif option == "Human vs AI Source Models":
|
30 |
-
return predict_bc_scores(input),
|
31 |
return None, None
|
32 |
|
33 |
|
@@ -59,7 +59,7 @@ def main(
|
|
59 |
)
|
60 |
depth_analysis_plot = depth_analysis(input)
|
61 |
bc_score = predict_bc_scores(input)
|
62 |
-
mc_score =
|
63 |
quilscore = predict_quillbot(input)
|
64 |
|
65 |
return (
|
@@ -73,7 +73,7 @@ def main(
|
|
73 |
|
74 |
# START OF GRADIO
|
75 |
|
76 |
-
title = "
|
77 |
months = {
|
78 |
"January": "01",
|
79 |
"February": "02",
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from datetime import date
|
4 |
+
from predictors import predict_bc_scores, predict_mc_scores
|
5 |
from analysis import depth_analysis
|
6 |
from predictors import predict_quillbot
|
7 |
from plagiarism import plagiarism_check, build_date
|
|
|
27 |
if option == "Human vs AI":
|
28 |
return predict_bc_scores(input), None
|
29 |
elif option == "Human vs AI Source Models":
|
30 |
+
return predict_bc_scores(input), predict_mc_scores(input, models)
|
31 |
return None, None
|
32 |
|
33 |
|
|
|
59 |
)
|
60 |
depth_analysis_plot = depth_analysis(input)
|
61 |
bc_score = predict_bc_scores(input)
|
62 |
+
mc_score = predict_mc_scores(input, models)
|
63 |
quilscore = predict_quillbot(input)
|
64 |
|
65 |
return (
|
|
|
73 |
|
74 |
# START OF GRADIO
|
75 |
|
76 |
+
title = "AI Detection and Source Analysis"
|
77 |
months = {
|
78 |
"January": "01",
|
79 |
"February": "02",
|
predictors.py
CHANGED
@@ -227,43 +227,6 @@ def predict_mc(model, tokenizer, text):
|
|
227 |
output_norm = softmax(output.logits.detach().cpu().numpy(), 1)[0]
|
228 |
return output_norm
|
229 |
|
230 |
-
|
231 |
-
def predict_mc_scores(input):
|
232 |
-
bc_scores = []
|
233 |
-
mc_scores = []
|
234 |
-
|
235 |
-
samples_len_bc = len(split_text_allow_complete_sentences_nltk(input, type_det="bc"))
|
236 |
-
segments_bc = split_text_allow_complete_sentences_nltk(input, type_det="bc")
|
237 |
-
for i in range(samples_len_bc):
|
238 |
-
cleaned_text_bc = remove_special_characters(segments_bc[i])
|
239 |
-
bc_score = predict_bc(text_bc_model, text_bc_tokenizer, cleaned_text_bc)
|
240 |
-
bc_scores.append(bc_score)
|
241 |
-
bc_scores_array = np.array(bc_scores)
|
242 |
-
average_bc_scores = np.mean(bc_scores_array, axis=0)
|
243 |
-
bc_score_list = average_bc_scores.tolist()
|
244 |
-
bc_score = {"AI": bc_score_list[1], "HUMAN": bc_score_list[0]}
|
245 |
-
segments_mc = split_text_allow_complete_sentences_nltk(input, type_det="mc")
|
246 |
-
samples_len_mc = len(split_text_allow_complete_sentences_nltk(input, type_det="mc"))
|
247 |
-
for i in range(samples_len_mc):
|
248 |
-
cleaned_text_mc = remove_special_characters(segments_mc[i])
|
249 |
-
mc_score = predict_mc(text_mc_model, text_mc_tokenizer, cleaned_text_mc)
|
250 |
-
mc_scores.append(mc_score)
|
251 |
-
mc_scores_array = np.array(mc_scores)
|
252 |
-
average_mc_scores = np.mean(mc_scores_array, axis=0)
|
253 |
-
mc_score_list = average_mc_scores.tolist()
|
254 |
-
mc_score = {}
|
255 |
-
for score, label in zip(mc_score_list, mc_label_map):
|
256 |
-
mc_score[label.upper()] = score
|
257 |
-
|
258 |
-
sum_prob = 1 - bc_score["HUMAN"]
|
259 |
-
for key, value in mc_score.items():
|
260 |
-
mc_score[key] = value * sum_prob
|
261 |
-
if sum_prob < 0.01:
|
262 |
-
mc_score = {}
|
263 |
-
|
264 |
-
return mc_score
|
265 |
-
|
266 |
-
|
267 |
def predict_bc_scores(input):
|
268 |
bc_scores = []
|
269 |
samples_len_bc = len(split_text_allow_complete_sentences_nltk(input, type_det="bc"))
|
@@ -313,7 +276,7 @@ def predict_1on1_single(input, model):
|
|
313 |
return predictions
|
314 |
|
315 |
|
316 |
-
def
|
317 |
|
318 |
if len(models) == 0:
|
319 |
return {}
|
|
|
227 |
output_norm = softmax(output.logits.detach().cpu().numpy(), 1)[0]
|
228 |
return output_norm
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
def predict_bc_scores(input):
|
231 |
bc_scores = []
|
232 |
samples_len_bc = len(split_text_allow_complete_sentences_nltk(input, type_det="bc"))
|
|
|
276 |
return predictions
|
277 |
|
278 |
|
279 |
+
def predict_mc_scores(input, models):
|
280 |
|
281 |
if len(models) == 0:
|
282 |
return {}
|