Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
import os
|
5 |
+
|
6 |
+
MODEL_NAME = "NeuroSpaceX/ruSpamNS"
|
7 |
+
TOKEN = os.getenv("HF_TOKEN") # Читаем токен из переменной окружения
|
8 |
+
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=TOKEN)
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, use_auth_token=TOKEN)
|
11 |
+
|
12 |
+
def classify_text(text):
|
13 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
14 |
+
with torch.no_grad():
|
15 |
+
outputs = model(**inputs)
|
16 |
+
prediction = torch.argmax(outputs.logits, dim=1).item()
|
17 |
+
return "СПАМ" if prediction == 1 else "НЕ СПАМ"
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=classify_text,
|
21 |
+
inputs=gr.Textbox(lines=3, placeholder="Введите текст..."),
|
22 |
+
outputs="text",
|
23 |
+
title="ruSpamNS - Проверка на спам",
|
24 |
+
description="Введите текст, чтобы проверить, является ли он спамом."
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|