Spaces:
Sleeping
Sleeping
| 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() |