yasserrmd commited on
Commit
602cd0f
·
verified ·
1 Parent(s): addd1a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -22,11 +22,11 @@ CONFIG = synthid_mixin.DEFAULT_WATERMARKING_CONFIG
22
  # Function to check for AI-generated content using SynthID and highlight watermark
23
  @spaces.GPU
24
  def check_plagiarism(text):
25
-
26
  # Logits processor for SynthID
27
  logits_processor = logits_processing.SynthIDLogitsProcessor(
28
  **CONFIG, top_k=40, temperature=0.5
29
  )
 
30
  # Tokenize and process the input text
31
  inputs = tokenizer(text, return_tensors="pt").to(DEVICE)
32
 
@@ -49,9 +49,10 @@ def check_plagiarism(text):
49
  token_scores = outputs.scores
50
 
51
  # Loop through each generated token and its corresponding score
52
- for token, score in zip(generated_tokens, token_scores):
53
- processed_score = logits_processor(score)
54
- token_text = tokenizer.decode(token)
 
55
 
56
  # If processed score indicates watermark, highlight this token
57
  if processed_score.mean().item() > 0.5:
 
22
  # Function to check for AI-generated content using SynthID and highlight watermark
23
  @spaces.GPU
24
  def check_plagiarism(text):
 
25
  # Logits processor for SynthID
26
  logits_processor = logits_processing.SynthIDLogitsProcessor(
27
  **CONFIG, top_k=40, temperature=0.5
28
  )
29
+
30
  # Tokenize and process the input text
31
  inputs = tokenizer(text, return_tensors="pt").to(DEVICE)
32
 
 
49
  token_scores = outputs.scores
50
 
51
  # Loop through each generated token and its corresponding score
52
+ for token_id, score in zip(generated_tokens, token_scores):
53
+ # Apply SynthIDLogitsProcessor to each score by calling it with 'scores=score'
54
+ processed_score = logits_processor(scores=score)
55
+ token_text = tokenizer.decode(token_id.unsqueeze(0)) # Decode token_id for individual token text
56
 
57
  # If processed score indicates watermark, highlight this token
58
  if processed_score.mean().item() > 0.5: