Upload Gradio UI for Clickbait Classifier
Browse files
app.py
CHANGED
|
@@ -7,15 +7,15 @@ MODEL_NAME = "ENTUM-AI/distilbert-clickbait-classifier"
|
|
| 7 |
try:
|
| 8 |
classifier = pipeline("text-classification", model=MODEL_NAME)
|
| 9 |
except Exception as e:
|
| 10 |
-
print(f"
|
| 11 |
classifier = None
|
| 12 |
|
| 13 |
def predict(text):
|
| 14 |
if not text.strip():
|
| 15 |
-
return "
|
| 16 |
|
| 17 |
if classifier is None:
|
| 18 |
-
return "
|
| 19 |
|
| 20 |
result = classifier(text)[0]
|
| 21 |
label = result['label']
|
|
@@ -23,9 +23,9 @@ def predict(text):
|
|
| 23 |
|
| 24 |
# Форматируем красивый вывод
|
| 25 |
if label == "Clickbait":
|
| 26 |
-
return f"🚨
|
| 27 |
else:
|
| 28 |
-
return f"📰
|
| 29 |
|
| 30 |
# Настраиваем красивый интерфейс Gradio
|
| 31 |
theme = gr.themes.Soft(
|
|
@@ -38,25 +38,25 @@ with gr.Blocks(theme=theme, title="Clickbait Detector 🎣") as demo:
|
|
| 38 |
"""
|
| 39 |
# 🎣 Clickbait Headline Detector
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
*
|
| 45 |
"""
|
| 46 |
)
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
input_text = gr.Textbox(
|
| 51 |
-
label="
|
| 52 |
-
placeholder="
|
| 53 |
lines=3
|
| 54 |
)
|
| 55 |
-
submit_btn = gr.Button("
|
| 56 |
|
| 57 |
with gr.Column(scale=1):
|
| 58 |
output_text = gr.Textbox(
|
| 59 |
-
label="
|
| 60 |
lines=3,
|
| 61 |
interactive=False
|
| 62 |
)
|
|
|
|
| 7 |
try:
|
| 8 |
classifier = pipeline("text-classification", model=MODEL_NAME)
|
| 9 |
except Exception as e:
|
| 10 |
+
print(f"Error loading model: {e}")
|
| 11 |
classifier = None
|
| 12 |
|
| 13 |
def predict(text):
|
| 14 |
if not text.strip():
|
| 15 |
+
return "Please enter a headline."
|
| 16 |
|
| 17 |
if classifier is None:
|
| 18 |
+
return "Model has not loaded yet or an error occurred."
|
| 19 |
|
| 20 |
result = classifier(text)[0]
|
| 21 |
label = result['label']
|
|
|
|
| 23 |
|
| 24 |
# Форматируем красивый вывод
|
| 25 |
if label == "Clickbait":
|
| 26 |
+
return f"🚨 CLICKBAIT! (Confidence: {score:.1%})"
|
| 27 |
else:
|
| 28 |
+
return f"📰 NORMAL NEWS (Confidence: {score:.1%})"
|
| 29 |
|
| 30 |
# Настраиваем красивый интерфейс Gradio
|
| 31 |
theme = gr.themes.Soft(
|
|
|
|
| 38 |
"""
|
| 39 |
# 🎣 Clickbait Headline Detector
|
| 40 |
|
| 41 |
+
This model, based on **DistilBERT**, predicts whether a news headline or article title is "clickbait".
|
| 42 |
+
It was trained on tens of thousands of real media headlines.
|
| 43 |
|
| 44 |
+
*Enter any English headline below to check it!*
|
| 45 |
"""
|
| 46 |
)
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
input_text = gr.Textbox(
|
| 51 |
+
label="Enter headline",
|
| 52 |
+
placeholder="Example: 10 Bizarre Facts About Apples...",
|
| 53 |
lines=3
|
| 54 |
)
|
| 55 |
+
submit_btn = gr.Button("Check Headline 🔍", variant="primary")
|
| 56 |
|
| 57 |
with gr.Column(scale=1):
|
| 58 |
output_text = gr.Textbox(
|
| 59 |
+
label="Model Verdict",
|
| 60 |
lines=3,
|
| 61 |
interactive=False
|
| 62 |
)
|