File size: 2,566 Bytes
11ed07b
 
 
 
 
 
 
 
 
e809d1d
11ed07b
 
 
 
e809d1d
11ed07b
 
e809d1d
11ed07b
 
 
 
 
 
 
e809d1d
11ed07b
e809d1d
11ed07b
 
 
 
 
 
 
 
 
 
 
 
e809d1d
 
11ed07b
e809d1d
11ed07b
 
 
 
 
 
e809d1d
 
11ed07b
 
e809d1d
11ed07b
 
 
e809d1d
11ed07b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import gradio as gr
from transformers import pipeline

# Загружаем модель прямо из вашего нового репозитория на Hugging Face
MODEL_NAME = "ENTUM-AI/distilbert-clickbait-classifier"

try:
    classifier = pipeline("text-classification", model=MODEL_NAME)
except Exception as e:
    print(f"Error loading model: {e}")
    classifier = None

def predict(text):
    if not text.strip():
        return "Please enter a headline."
    
    if classifier is None:
        return "Model has not loaded yet or an error occurred."
        
    result = classifier(text)[0]
    label = result['label']
    score = result['score']
    
    # Форматируем красивый вывод
    if label == "Clickbait":
        return f"🚨 CLICKBAIT! (Confidence: {score:.1%})"
    else:
        return f"📰 NORMAL NEWS (Confidence: {score:.1%})"

# Настраиваем красивый интерфейс Gradio
theme = gr.themes.Soft(
    primary_hue="blue",
    secondary_hue="indigo",
)

with gr.Blocks(theme=theme, title="Clickbait Detector 🎣") as demo:
    gr.Markdown(
        """
        # 🎣 Clickbait Headline Detector
        
        This model, based on **DistilBERT**, predicts whether a news headline or article title is "clickbait".
        It was trained on tens of thousands of real media headlines.
        
        *Enter any English headline below to check it!*
        """
    )
    
    with gr.Row():
        with gr.Column(scale=2):
            input_text = gr.Textbox(
                label="Enter headline", 
                placeholder="Example: 10 Bizarre Facts About Apples...",
                lines=3
            )
            submit_btn = gr.Button("Check Headline 🔍", variant="primary")
            
        with gr.Column(scale=1):
            output_text = gr.Textbox(
                label="Model Verdict", 
                lines=3,
                interactive=False
            )
            
    # Примеры для быстрого тестирования
    gr.Examples(
        examples=[
            ["10 Bizarre Facts About Apples That Will BLOW YOUR MIND! 🍎🤯"],
            ["Apple releases new quarterly earnings report showing 5% growth."],
            ["You'll Never Guess What Happened Next..."],
            ["Federal Reserve announces increase in interest rates by 0.25%"]
        ],
        inputs=input_text
    )
    
    submit_btn.click(fn=predict, inputs=input_text, outputs=output_text)

# Запускаем приложение
demo.launch()