Spaces:
Sleeping
Sleeping
Deploying app.py
Browse files
app.py
CHANGED
|
@@ -4,26 +4,24 @@ from transformers import pipeline
|
|
| 4 |
|
| 5 |
CLASSIFIER_MODEL_ID = "sks01dev/clickbait-classifier"
|
| 6 |
|
| 7 |
-
# Load model assets directly from the Hub
|
| 8 |
classifier = pipeline(
|
| 9 |
-
"sentiment-analysis",
|
| 10 |
model=CLASSIFIER_MODEL_ID,
|
| 11 |
tokenizer=CLASSIFIER_MODEL_ID,
|
| 12 |
-
return_all_scores=True
|
| 13 |
)
|
| 14 |
|
| 15 |
def predict(headline):
|
| 16 |
results = classifier(headline)[0]
|
| 17 |
-
# Format output for clear confidence display
|
| 18 |
formatted_output = {
|
| 19 |
-
"NOT CLICKBAIT (0)": results[0]['score'],
|
| 20 |
-
"CLICKBAIT (1)": results[1]['score']
|
| 21 |
}
|
| 22 |
return formatted_output
|
| 23 |
|
| 24 |
# Gradio Interface Setup
|
| 25 |
gr.Interface(
|
| 26 |
-
fn=predict,
|
| 27 |
inputs=gr.Textbox(lines=2, label="Enter News Headline"),
|
| 28 |
outputs=gr.Label(num_top_classes=2, title="Prediction Confidence"),
|
| 29 |
title="World-Class Clickbait Predictor",
|
|
@@ -31,6 +29,5 @@ gr.Interface(
|
|
| 31 |
examples=[
|
| 32 |
["10 Ways To Instantly Improve Your Mood"],
|
| 33 |
["You Won't Believe What Happened When We Tested This!"],
|
| 34 |
-
["You Won't Believe What Happened When We Tested This!"],
|
| 35 |
]
|
| 36 |
).launch()
|
|
|
|
| 4 |
|
| 5 |
CLASSIFIER_MODEL_ID = "sks01dev/clickbait-classifier"
|
| 6 |
|
|
|
|
| 7 |
classifier = pipeline(
|
| 8 |
+
"sentiment-analysis",
|
| 9 |
model=CLASSIFIER_MODEL_ID,
|
| 10 |
tokenizer=CLASSIFIER_MODEL_ID,
|
| 11 |
+
return_all_scores=True
|
| 12 |
)
|
| 13 |
|
| 14 |
def predict(headline):
|
| 15 |
results = classifier(headline)[0]
|
|
|
|
| 16 |
formatted_output = {
|
| 17 |
+
"NOT CLICKBAIT (0)": results[0]['score'],
|
| 18 |
+
"CLICKBAIT (1)": results[1]['score']
|
| 19 |
}
|
| 20 |
return formatted_output
|
| 21 |
|
| 22 |
# Gradio Interface Setup
|
| 23 |
gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
inputs=gr.Textbox(lines=2, label="Enter News Headline"),
|
| 26 |
outputs=gr.Label(num_top_classes=2, title="Prediction Confidence"),
|
| 27 |
title="World-Class Clickbait Predictor",
|
|
|
|
| 29 |
examples=[
|
| 30 |
["10 Ways To Instantly Improve Your Mood"],
|
| 31 |
["You Won't Believe What Happened When We Tested This!"],
|
|
|
|
| 32 |
]
|
| 33 |
).launch()
|