import gradio as gr from transformers import AutoTokenizer, AutoModelForSequenceClassification import torch model_path = "RUSpam/spam_deberta_v4" tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForSequenceClassification.from_pretrained(model_path) def predict_spam(text): inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256) with torch.no_grad(): outputs = model(**inputs) logits = outputs.logits probabilities = torch.softmax(logits, dim=1) predicted_class = torch.argmax(logits, dim=1).item() spam_probability = probabilities[0][1].item() not_spam_probability = probabilities[0][0].item() result = "Спам" if predicted_class == 1 else "Не спам" return { "Результат": result, "Вероятность спама": f"{spam_probability:.2%}" } # Создание интерфейса Gradio iface = gr.Interface( fn=predict_spam, inputs=gr.Textbox(lines=5, label="Введите текст"), outputs=[ gr.Label(label="Результат"), gr.Label(label="Вероятность спама") ], title="Определение спама в русскоязычных текстах" ) iface.launch()