MightyOctopus commited on
Commit
8200bf7
·
verified ·
1 Parent(s): 73fe9ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -39,7 +39,7 @@ user_input="""Brooo, you won’t believe what happened today 😭 So I’m just
39
 
40
 
41
  @tool
42
- def detect_text(text):
43
  """ Process AI text detection using fakespot-ai/roberta-base-ai-text-detection-v1 model.
44
  It returns its result in a List[Dict] form.
45
  e.g. [{'label': 'AI', 'score': 0.9998624324798584}]
@@ -49,11 +49,31 @@ def detect_text(text):
49
  model=TEXT_DETECTOR_MODEL_ID
50
  )
51
 
52
- cleaned_text = classifier(clean_text(text))
53
- label_result = cleaned_text[0]["label"]
54
- score_result = cleaned_text[0]["score"]
 
 
55
 
56
- return label_result, score_result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  def generate_dynamic_query(text, label, score):
59
 
 
39
 
40
 
41
  @tool
42
+ def detect_text(texts):
43
  """ Process AI text detection using fakespot-ai/roberta-base-ai-text-detection-v1 model.
44
  It returns its result in a List[Dict] form.
45
  e.g. [{'label': 'AI', 'score': 0.9998624324798584}]
 
49
  model=TEXT_DETECTOR_MODEL_ID
50
  )
51
 
52
+ ### Split text into max 300 words into multiple batches in case the text contains more than 350 words
53
+ ### due to the max token limit of the detection model
54
+ num_words = 300
55
+ batched_words = []
56
+ words: List = texts.split()
57
 
58
+ if len(texts.split()) >= num_words:
59
+ for i in range(0, len(words), num_words):
60
+ chunk = " ".join(words[i: i + num_words])
61
+ batched_words.append(chunk)
62
+
63
+ cleaned_text = classifier([clean_text(t) for t in batched_words])
64
+ label_result = cleaned_text[0]["label"]
65
+ score_result = cleaned_text[0]["score"]
66
+
67
+ return label_result, score_result
68
+ else:
69
+ cleaned_text = classifier(clean_text(texts))
70
+
71
+ ### Works with a batch of texts
72
+ label_result = cleaned_text[0]["label"]
73
+ score_result = cleaned_text[0]["score"]
74
+
75
+ return label_result, score_result
76
+
77
 
78
  def generate_dynamic_query(text, label, score):
79