Sankalp3011 commited on
Commit
b0ffbda
·
verified ·
1 Parent(s): b143d79

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ model_name = "roberta-base-openai-detector"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+
9
+ def detect_ai(text):
10
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
11
+ with torch.no_grad():
12
+ logits = model(**inputs).logits
13
+ prob = logits.softmax(dim=1).tolist()[0]
14
+ out = {
15
+ "Human Probability (%)": round(prob[0] * 100, 2),
16
+ "AI Probability (%)": round(prob[1] * 100, 2)
17
+ }
18
+ return out
19
+
20
+ iface = gr.Interface(
21
+ fn=detect_ai,
22
+ inputs=gr.TextArea(lines=8, label="Paste your text"),
23
+ outputs="label",
24
+ title="Open Source AI Text Detector",
25
+ description="Paste text below. Returns % probability for AI or human-generated content."
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ iface.launch()