File size: 1,224 Bytes
04ad217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
import torch

# Load pre-trained DistilBERT model and tokenizer
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')

def check_text(text):
    # Tokenize and convert to model input format
    inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True)

    # Make a prediction
    outputs = model(**inputs)

    # Get predicted label
    prediction = torch.argmax(outputs.logits).item()

    # Analyze the prediction and classify as AI-generated or human-written
    if prediction == 0:  # You may need to adjust this based on your model
        return "This text is likely human-written."
    else:
        return "This text appears to be AI-generated."

def main():
    st.title("Text Detector")

    # Get user input
    user_input = st.text_area("Enter text:")

    if st.button("Check"):
        if user_input:
            result = check_text(user_input)
            st.write(result)
        else:
            st.warning("Please enter some text.")

if __name__ == "__main__":
    main()