news_classifier / app.py
kozy9's picture
Update app.py
36c47de verified
import gradio as gr
from transformers import pipeline
news_classifier = pipeline(task="text-classification",
model='kozy9/news_classification_file',
top_k=1,
batch_size=32)
def chat_interface(user_text):
if not user_text.strip():
return "⚠️ Please type something."
result = news_classifier(user_text)[0]
label = result[0]['label']
score = result[0]['score']
# Format output nicely
output = f"πŸ“° Category: {label}\n"
output += f"🎯 Confidence: {score:.2%}\n"
return output
demo = gr.Interface(
fn=chat_interface,
title ="πŸ“° News Article Classifier",
description = """This model classifies news articles into 4 categories:
- 🌍 World
- ⚽ Sports
- πŸ’Ό Business
- πŸ”¬ Sci/Tech""",
inputs=gr.Textbox(lines=10,label="πŸ“ Enter news headline or description", placeholder="Type or paste news text here..."),
outputs=gr.Textbox(lines=3, label="🏷️ Prediction"),
examples=[
["Scientists discover new planet in distant solar system"],
["Manchester United wins the championship"],
["Stock market reaches all-time high"],
["Peace talks begin between conflicting nations"],
["new chip was invinted to develope AI"]
]
)
demo.launch()