| | import os |
| | import warnings |
| |
|
| | import streamlit as st |
| | from transformers import pipeline |
| |
|
| | |
| | os.environ["CUDA_VISIBLE_DEVICES"] = "-1" |
| | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" |
| |
|
| | |
| | warnings.filterwarnings("ignore") |
| |
|
| |
|
| | |
| | @st.cache_resource |
| | def load_model(): |
| | return pipeline("sentiment-analysis") |
| |
|
| |
|
| | |
| | st.title("News Sentiment Classification 📰💡") |
| | st.write( |
| | """ |
| | This app uses a pre-trained model from Hugging Face to classify the sentiment of news headlines or articles. |
| | Enter your news content below, and the model will classify it as either 'POSITIVE' or 'NEGATIVE'. |
| | """ |
| | ) |
| |
|
| | |
| | news_input = st.text_area("Enter a news headline or article:", "") |
| |
|
| | |
| | sentiment_classifier = load_model() |
| |
|
| | |
| | if st.button("Classify Sentiment"): |
| | if news_input: |
| | result = sentiment_classifier(news_input) |
| |
|
| | |
| | sentiment = result[0]["label"] |
| | confidence = result[0]["score"] |
| |
|
| | st.subheader(f"Sentiment: {sentiment}") |
| | st.write(f"Confidence: {confidence:.2%}") |
| | else: |
| | st.error("Please enter a news headline or article for classification.") |
| | st.error("Please enter a news headline or article for classification.") |
| |
|