vai0511 commited on
Commit
0fa4b26
·
verified ·
1 Parent(s): 1a66d90

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Load the model and tokenizer from Hugging Face Hub
6
+ model_name = "vai0511/ai-content-classifier"
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+
10
+ # Define function for classification
11
+ def classify_text(text):
12
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
13
+ with torch.no_grad():
14
+ outputs = model(**inputs)
15
+
16
+ logits = outputs.logits
17
+ predicted_class = torch.argmax(logits, dim=1).item()
18
+
19
+ labels = {0: "Human-Written", 1: "AI-Generated", 2: "Paraphrased"}
20
+ return labels[predicted_class]
21
+
22
+ # Gradio Interface
23
+ iface = gr.Interface(
24
+ fn=classify_text,
25
+ inputs=gr.Textbox(lines=5, placeholder="Enter your text here..."),
26
+ outputs="text",
27
+ title="AI-Driven Content Source Identification",
28
+ description="Detect whether the given text is human-written, AI-generated, or paraphrased."
29
+ )
30
+
31
+ iface.launch()