import torch import gradio as gr from transformers import ( AutoTokenizer, AutoModelForSequenceClassification ) MODEL_NAME = "duclo90/results" tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) model.eval() def classify_text(text): inputs = tokenizer( text, return_tensors="pt", truncation=True, max_length=512 ) with torch.no_grad(): outputs = model(**inputs) probs = torch.softmax(outputs.logits, dim=-1) score, pred = torch.max(probs, dim=-1) label = model.config.id2label[pred.item()] confidence = round(score.item(), 3) return f"Prediction: {label} (Confidence: {confidence})" iface = gr.Interface( fn=classify_text, inputs=gr.Textbox(lines=6, placeholder="Enter text here..."), outputs="text", title="Human vs Machine Text Classifier", description="Classifies text as human-written or machine-generated using a fine-tuned BERT model." ) iface.launch()