mihalykiss commited on
Commit
18e11fc
·
1 Parent(s): 0fd14a7

UI - theme

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -25,31 +25,31 @@ label_mapping = {
25
  }
26
 
27
  def classify_text(text):
28
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
29
  inputs = {key: value.to(device) for key, value in inputs.items()}
30
 
31
  with torch.no_grad():
32
  outputs = model(**inputs)
33
  probabilities = torch.softmax(outputs.logits, dim=1)[0]
34
  predicted_class = torch.argmax(probabilities).item()
35
- confidence = probabilities[predicted_class].item()
36
-
37
  if predicted_class == 24:
38
- prediction_label = "✅ **Human Written**"
39
- confidence_message = f"🔒 **Confidence:** {confidence:.2f}"
40
- if confidence > 0.8:
41
- confidence_message += " (Highly Likely Human)"
42
  else:
43
- prediction_label = f"🤖 **AI Generated by {label_mapping[predicted_class]}**"
44
- confidence_message = f"🔒 **Confidence:** {confidence:.2f}"
45
- if confidence > 0.8:
46
- confidence_message += " (Highly Likely AI)"
47
-
48
- return f"**Result:**\n\n{prediction_label}\n\n{confidence_message}"
49
 
50
- title = "🧠 SzegedAI ModernBERT Text Detector"
 
 
 
 
 
 
51
  description = """
52
- **AI Detection Tool by SzegedAI**
53
 
54
  Detect AI-generated texts with precision using the new **ModernBERT** model, fine-tuned for machine-generated text detection, and capable of identifying 40 different models.
55
 
@@ -62,22 +62,18 @@ Detect AI-generated texts with precision using the new **ModernBERT** model, fin
62
  iface = gr.Interface(
63
  fn=classify_text,
64
  inputs=gr.Textbox(
65
- label="✏️ Enter Text for Analysis",
66
  placeholder="Type or paste your content here...",
67
  lines=5,
68
  elem_id="text_input_box"
69
  ),
70
- outputs=gr.Textbox(
71
- label="Detection Results",
72
- lines=4,
73
- elem_id="result_output_box"
74
- ),
75
  title=title,
76
  description=description,
77
  allow_flagging="never",
78
  live=False,
79
  css="""
80
- #text_input_box, #result_output_box {
81
  border-radius: 10px;
82
  border: 2px solid #4CAF50;
83
  font-size: 18px;
 
25
  }
26
 
27
  def classify_text(text):
28
+ inputs = tokenizer(text, return_tensors="pt", truncation=True)
29
  inputs = {key: value.to(device) for key, value in inputs.items()}
30
 
31
  with torch.no_grad():
32
  outputs = model(**inputs)
33
  probabilities = torch.softmax(outputs.logits, dim=1)[0]
34
  predicted_class = torch.argmax(probabilities).item()
35
+ confidence = probabilities[predicted_class].item() * 100
36
+
37
  if predicted_class == 24:
38
+ prediction_label = f"✅ The text is **{confidence:.2f}%** likely **Human written**."
39
+ model_info = ""
 
 
40
  else:
41
+ prediction_label = f"🤖 The text is **{confidence:.2f}%** likely **AI generated**."
42
+ model_info = f"**Identified AI Model:** {label_mapping[predicted_class]}"
 
 
 
 
43
 
44
+ result_message = f"**Result:**\n\n{prediction_label}"
45
+ if model_info:
46
+ result_message += f"\n\n{model_info}"
47
+
48
+ return result_message
49
+
50
+ title = "AI Generated Text Detector"
51
  description = """
52
+ **AI detection tool by SzegedAI**
53
 
54
  Detect AI-generated texts with precision using the new **ModernBERT** model, fine-tuned for machine-generated text detection, and capable of identifying 40 different models.
55
 
 
62
  iface = gr.Interface(
63
  fn=classify_text,
64
  inputs=gr.Textbox(
65
+ label="Enter Text for Analysis",
66
  placeholder="Type or paste your content here...",
67
  lines=5,
68
  elem_id="text_input_box"
69
  ),
70
+ outputs=gr.Markdown(),
 
 
 
 
71
  title=title,
72
  description=description,
73
  allow_flagging="never",
74
  live=False,
75
  css="""
76
+ #text_input_box {
77
  border-radius: 10px;
78
  border: 2px solid #4CAF50;
79
  font-size: 18px;