Boltuzamaki
commited on
Commit
•
cff61f9
1
Parent(s):
1d15c78
init
Browse files- .gitignore +1 -0
- app.py +49 -0
- requirements copy.txt +4 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Disable TensorFlow and CUDA logs
|
8 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Disable GPU usage
|
9 |
+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # Suppress TensorFlow warnings
|
10 |
+
|
11 |
+
# Suppress all warnings from Python
|
12 |
+
warnings.filterwarnings("ignore")
|
13 |
+
|
14 |
+
|
15 |
+
# Load sentiment-analysis pipeline from Hugging Face
|
16 |
+
@st.cache_resource
|
17 |
+
def load_model():
|
18 |
+
return pipeline("sentiment-analysis")
|
19 |
+
|
20 |
+
|
21 |
+
# App title and description
|
22 |
+
st.title("News Sentiment Classification 📰💡")
|
23 |
+
st.write(
|
24 |
+
"""
|
25 |
+
This app uses a pre-trained model from Hugging Face to classify the sentiment of news headlines or articles.
|
26 |
+
Enter your news content below, and the model will classify it as either 'POSITIVE' or 'NEGATIVE'.
|
27 |
+
"""
|
28 |
+
)
|
29 |
+
|
30 |
+
# Input from the user
|
31 |
+
news_input = st.text_area("Enter a news headline or article:", "")
|
32 |
+
|
33 |
+
# Load the model (cached to avoid reloading every time)
|
34 |
+
sentiment_classifier = load_model()
|
35 |
+
|
36 |
+
# Classify the sentiment when the button is pressed
|
37 |
+
if st.button("Classify Sentiment"):
|
38 |
+
if news_input:
|
39 |
+
result = sentiment_classifier(news_input)
|
40 |
+
|
41 |
+
# Display the sentiment and confidence score
|
42 |
+
sentiment = result[0]["label"]
|
43 |
+
confidence = result[0]["score"]
|
44 |
+
|
45 |
+
st.subheader(f"Sentiment: {sentiment}")
|
46 |
+
st.write(f"Confidence: {confidence:.2%}")
|
47 |
+
else:
|
48 |
+
st.error("Please enter a news headline or article for classification.")
|
49 |
+
st.error("Please enter a news headline or article for classification.")
|
requirements copy.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.38.0
|
2 |
+
transformers==4.45.0
|
3 |
+
tensorflow==2.17.0
|
4 |
+
tf-keras==2.17.0
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.38.0
|
2 |
+
transformers==4.45.0
|
3 |
+
tensorflow==2.17.0
|
4 |
+
tf-keras==2.17.0
|