Spaces:
Running
Running
Update textPreprocess.py
Browse files- textPreprocess.py +16 -6
textPreprocess.py
CHANGED
|
@@ -99,9 +99,13 @@ def predict_text(text: str, max_length: int = None):
|
|
| 99 |
pred = predictions[0]
|
| 100 |
# pred.label is "Human" or "AI"
|
| 101 |
# Map to "Human" or "Ai" to match previous API
|
| 102 |
-
label
|
| 103 |
-
if
|
| 104 |
-
label = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Confidence logic:
|
| 107 |
# If label is Human, use probability_human
|
|
@@ -141,9 +145,15 @@ def predict_batch(texts, batch_size=16):
|
|
| 141 |
results = []
|
| 142 |
for text, pred in zip(texts, predictions):
|
| 143 |
label = pred.label
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
results.append({
|
| 149 |
"text": text,
|
|
|
|
| 99 |
pred = predictions[0]
|
| 100 |
# pred.label is "Human" or "AI"
|
| 101 |
# Map to "Human" or "Ai" to match previous API
|
| 102 |
+
# Determine label based on higher confidence
|
| 103 |
+
if pred.probability_ai > pred.probability_human:
|
| 104 |
+
label = "AI"
|
| 105 |
+
confidence = pred.probability_ai
|
| 106 |
+
else:
|
| 107 |
+
label = "Human"
|
| 108 |
+
confidence = pred.probability_human
|
| 109 |
|
| 110 |
# Confidence logic:
|
| 111 |
# If label is Human, use probability_human
|
|
|
|
| 145 |
results = []
|
| 146 |
for text, pred in zip(texts, predictions):
|
| 147 |
label = pred.label
|
| 148 |
+
|
| 149 |
+
# Determine label based on higher confidence
|
| 150 |
+
if pred.probability_ai > pred.probability_human:
|
| 151 |
+
label = "AI"
|
| 152 |
+
confidence = pred.probability_ai
|
| 153 |
+
else:
|
| 154 |
+
label = "Human"
|
| 155 |
+
confidence = pred.probability_human
|
| 156 |
+
|
| 157 |
|
| 158 |
results.append({
|
| 159 |
"text": text,
|