VictorM-Coder commited on
Commit
ec9938b
·
verified ·
1 Parent(s): b409777

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -19,15 +19,25 @@ def detect_ai(text):
19
  with torch.no_grad():
20
  outputs = model(**inputs)
21
  probs = torch.softmax(outputs.logits, dim=1)
22
- ai_score = float(probs[0][1]) # fix here
23
  results.append({"sentence": sent, "ai_score": ai_score})
24
 
 
25
  highlighted = ""
26
  for r in results:
27
  color = f"rgba(255,0,0,{r['ai_score']})"
28
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
29
 
30
- return highlighted, results
 
 
 
 
 
 
 
 
 
31
 
32
 
33
  with gr.Blocks() as demo:
 
19
  with torch.no_grad():
20
  outputs = model(**inputs)
21
  probs = torch.softmax(outputs.logits, dim=1)
22
+ ai_score = float(probs[0][1])
23
  results.append({"sentence": sent, "ai_score": ai_score})
24
 
25
+ # Build highlighted HTML
26
  highlighted = ""
27
  for r in results:
28
  color = f"rgba(255,0,0,{r['ai_score']})"
29
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
30
 
31
+ # Compute total AI percentage
32
+ if results:
33
+ avg_ai = sum(r['ai_score'] for r in results) / len(results)
34
+ total_percent = round(avg_ai * 100, 2)
35
+ highlighted += f"<p><b>Total AI Probability: {total_percent}%</b></p>"
36
+ else:
37
+ total_percent = 0.0
38
+
39
+ return highlighted, {"sentences": results, "total_ai_percent": total_percent}
40
+
41
 
42
 
43
  with gr.Blocks() as demo: