Update app.py
Browse files
app.py
CHANGED
|
@@ -33,3 +33,43 @@ if st.sidebar.button('Summarize Article'):
|
|
| 33 |
summarize(ARTICLE)
|
| 34 |
else:
|
| 35 |
st.warning('π Please enter Article!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
summarize(ARTICLE)
|
| 34 |
else:
|
| 35 |
st.warning('π Please enter Article!')
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
#################################
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Initialize the sentiment analysis pipeline
|
| 43 |
+
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
| 44 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 45 |
+
|
| 46 |
+
# Default article text
|
| 47 |
+
DEFAULT_SENTIMENT = [
|
| 48 |
+
"I'm so happy today!",
|
| 49 |
+
"This is the worst experience ever.",
|
| 50 |
+
"It's a decent product, nothing special."
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
# Create a text area for user input
|
| 54 |
+
SENTIMENT = st.sidebar.text_area('Enter Article', DEFAULT_SENTIMENT, height=150)
|
| 55 |
+
|
| 56 |
+
# Define the summarization function
|
| 57 |
+
def summarize(txt):
|
| 58 |
+
st.write('\n\n')
|
| 59 |
+
#st.write(txt[:100]) # Display the first 100 characters of the article
|
| 60 |
+
st.write('--------------------------------------------------------------')
|
| 61 |
+
|
| 62 |
+
# Perform Hugging sentiment analysis on multiple texts
|
| 63 |
+
results = sentiment_pipeline(txt)
|
| 64 |
+
|
| 65 |
+
# Display the results
|
| 66 |
+
for i, text in enumerate(texts):
|
| 67 |
+
st.write(f"Text: {text}")
|
| 68 |
+
st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Create a button and trigger the summarize function when clicked
|
| 72 |
+
if st.sidebar.button('Summarize Sentiment'):
|
| 73 |
+
summarize(SENTIMENT)
|
| 74 |
+
else:
|
| 75 |
+
st.warning('π Please enter Sentiment!')
|