File size: 671 Bytes
6e65e2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4ae333
6e65e2c
a4ae333
6e65e2c
 
 
 
 
 
 
 
 
 
 
 
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
import os

import gradio as gr
import torch
from transformers import pipeline

from utils import clean_text


pipeline = pipeline(
    task="text-classification",
    model="fakespot-ai/roberta-base-ai-text-detection-v1",
    device="cuda" if torch.cuda.is_available() else "cpu",
    token=os.environ.get("ACCESS_TOKEN")
)


def predict(text: str) -> list[dict]:
    cleaned_text = clean_text(text)
    predictions = pipeline(cleaned_text, top_k=None)
    return {
        p["label"]: p["score"] for p in predictions
    }


demo = gr.Interface(
    predict,
    inputs=gr.Textbox(),
    outputs=gr.Label(num_top_classes=2),
    title="AI Text Detector"
)
demo.launch()