codelion commited on
Commit
159d2da
·
verified ·
1 Parent(s): 23d7134

Add AI text detector Gradio app

Browse files
Files changed (3) hide show
  1. README.md +11 -7
  2. app.py +48 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,16 @@
1
  ---
2
- title: Ai Detector
3
- emoji: 🐢
4
- colorFrom: indigo
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 6.10.0
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: AI Text Detector
3
+ emoji: 🔍
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
+ models:
12
+ - adaptive-classifier/ai-detector
13
+ datasets:
14
+ - pangram/editlens_iclr
15
+ short_description: Detect AI-generated text using adaptive-classifier
16
  ---
 
 
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """HuggingFace Space for AI text detection using adaptive-classifier."""
2
+
3
+ import gradio as gr
4
+ from adaptive_classifier import AdaptiveClassifier
5
+
6
+ # Load model once at startup
7
+ print("Loading model...")
8
+ classifier = AdaptiveClassifier.from_pretrained(
9
+ "adaptive-classifier/ai-detector", use_onnx=False
10
+ )
11
+ print("Model loaded!")
12
+
13
+
14
+ def detect(text: str) -> dict:
15
+ """Classify text as human-written or AI-generated."""
16
+ if not text or len(text.strip()) < 20:
17
+ return {"error": "Please enter at least a few sentences of text."}
18
+
19
+ predictions = classifier.predict(text, k=2)
20
+ return {label: round(score, 4) for label, score in predictions}
21
+
22
+
23
+ demo = gr.Interface(
24
+ fn=detect,
25
+ inputs=gr.Textbox(
26
+ lines=10,
27
+ placeholder="Paste text here to check if it's human-written or AI-generated...",
28
+ label="Input Text",
29
+ ),
30
+ outputs=gr.Label(num_top_classes=2, label="Prediction"),
31
+ title="AI Text Detector",
32
+ description=(
33
+ "Detects whether text is **human-written** or **AI-generated/edited**. "
34
+ "Built with [adaptive-classifier](https://github.com/codelion/adaptive-classifier) "
35
+ "using frozen [RADAR](https://huggingface.co/TrustSafeAI/RADAR-Vicuna-7B) embeddings, "
36
+ "trained on the [EditLens](https://huggingface.co/datasets/pangram/editlens_iclr) dataset. "
37
+ "Works best with 50+ words."
38
+ ),
39
+ examples=[
40
+ ["The quick brown fox jumps over the lazy dog. I went to the store yesterday and forgot my wallet, which was pretty embarrassing. Had to ask the cashier to hold my stuff while I ran back to the car."],
41
+ ["The implementation leverages a novel approach to address the fundamental challenges inherent in modern natural language processing systems. By utilizing advanced transformer architectures, we demonstrate significant improvements across multiple benchmark datasets."],
42
+ ],
43
+ cache_examples=False,
44
+ api_name="detect",
45
+ )
46
+
47
+ if __name__ == "__main__":
48
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ adaptive-classifier>=0.1.2
2
+ gradio>=4.0.0