VictorM-Coder commited on
Commit
7a13e4b
·
verified ·
1 Parent(s): fe75c23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -17,9 +17,11 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
  def get_model():
18
  global tokenizer, model
19
  if model is None:
 
 
20
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
21
 
22
- # Hugging Face Build Fix: Force float32 unless a capable GPU is detected
23
  dtype = torch.float32
24
  if device.type == "cuda" and torch.cuda.is_bf16_supported():
25
  dtype = torch.bfloat16
@@ -29,7 +31,6 @@ def get_model():
29
  ).to(device).eval()
30
  return tokenizer, model
31
 
32
- # Only affects the content label as requested
33
  THRESHOLD = 0.20
34
 
35
  # -----------------------------
@@ -67,7 +68,7 @@ def split_preserving_structure(text):
67
  return final_blocks
68
 
69
  # -----------------------------
70
- # IMPROVED DETECTION LOGIC
71
  # -----------------------------
72
  @torch.inference_mode()
73
  def analyze(text):
@@ -112,7 +113,6 @@ def analyze(text):
112
 
113
  if i in prob_map:
114
  score = prob_map[i]
115
- # Standard coloring thresholds (Independent of the final label threshold)
116
  if score < 0.35: color, bg = "#11823b", "rgba(17, 130, 59, 0.15)"
117
  elif score < 0.70: color, bg = "#b8860b", "rgba(184, 134, 11, 0.15)"
118
  else: color, bg = "#b80d0d", "rgba(184, 13, 13, 0.15)"
@@ -127,7 +127,7 @@ def analyze(text):
127
 
128
  highlighted_html += "</div>"
129
 
130
- # CONTENT LABEL LOGIC
131
  label = "AI Content Detected" if weighted_avg >= THRESHOLD else "0 or * AI Content Detected"
132
 
133
  df = pd.DataFrame({"Sentence": pure_sents, "AI Confidence": [f"{p:.1%}" for p in probs]})
 
17
  def get_model():
18
  global tokenizer, model
19
  if model is None:
20
+ # Loading messages to help debug in HF logs
21
+ print(f"Loading model: {MODEL_NAME} on {device}")
22
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
23
 
24
+ # Use float32 on CPU to prevent build-time precision hangs
25
  dtype = torch.float32
26
  if device.type == "cuda" and torch.cuda.is_bf16_supported():
27
  dtype = torch.bfloat16
 
31
  ).to(device).eval()
32
  return tokenizer, model
33
 
 
34
  THRESHOLD = 0.20
35
 
36
  # -----------------------------
 
68
  return final_blocks
69
 
70
  # -----------------------------
71
+ # ANALYSIS
72
  # -----------------------------
73
  @torch.inference_mode()
74
  def analyze(text):
 
113
 
114
  if i in prob_map:
115
  score = prob_map[i]
 
116
  if score < 0.35: color, bg = "#11823b", "rgba(17, 130, 59, 0.15)"
117
  elif score < 0.70: color, bg = "#b8860b", "rgba(184, 134, 11, 0.15)"
118
  else: color, bg = "#b80d0d", "rgba(184, 13, 13, 0.15)"
 
127
 
128
  highlighted_html += "</div>"
129
 
130
+ # Updated Label Logic per your request
131
  label = "AI Content Detected" if weighted_avg >= THRESHOLD else "0 or * AI Content Detected"
132
 
133
  df = pd.DataFrame({"Sentence": pure_sents, "AI Confidence": [f"{p:.1%}" for p in probs]})