Update app.py
Browse files
app.py
CHANGED
|
@@ -56,24 +56,30 @@ SENTIMENT = st.sidebar.text_area('Enter Sentiment', DEFAULT_SENTIMENT, height=15
|
|
| 56 |
|
| 57 |
# Define the summarization function
|
| 58 |
def summarize(txt):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
st.write('\n\n')
|
| 60 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
| 61 |
st.write('--------------------------------------------------------------')
|
| 62 |
|
| 63 |
# Perform Hugging sentiment analysis on multiple texts
|
| 64 |
-
results = sentiment_pipeline(
|
| 65 |
|
| 66 |
# Display the results
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Create a button and trigger the summarize function when clicked
|
| 73 |
if st.sidebar.button('Summarize Sentiment'):
|
| 74 |
#ast.literal_eval() is a function in Python that safely evaluates a string containing a valid Python expression,
|
| 75 |
#such as lists, dictionaries, tuples, sets, integers, and floats. It parses the string and returns the corresponding
|
| 76 |
#Python object, without executing any arbitrary code, which makes it safer than using eval().
|
| 77 |
-
summarize(
|
| 78 |
else:
|
| 79 |
st.warning('👈 Please enter Sentiment!')
|
|
|
|
| 56 |
|
| 57 |
# Define the summarization function
|
| 58 |
def summarize(txt):
|
| 59 |
+
|
| 60 |
+
txt_converted = summarize(ast.literal_eval(SENTIMENT)) #convert string to actual content, e.g. list
|
| 61 |
+
st.write(f'xxxxxxxxxx {txt_converted}')
|
| 62 |
+
|
| 63 |
st.write('\n\n')
|
| 64 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
| 65 |
st.write('--------------------------------------------------------------')
|
| 66 |
|
| 67 |
# Perform Hugging sentiment analysis on multiple texts
|
| 68 |
+
results = sentiment_pipeline(txt_converted)
|
| 69 |
|
| 70 |
# Display the results
|
| 71 |
+
if type(txt_converted) == 'list':
|
| 72 |
+
for i, text in enumerate(txt_converted):
|
| 73 |
+
st.write(f"Text: {text}")
|
| 74 |
+
st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
|
| 75 |
+
else:
|
| 76 |
+
st.write(f"Sentiment: {results['label']}, Score: {results['score']:.2f}\n")
|
| 77 |
|
| 78 |
# Create a button and trigger the summarize function when clicked
|
| 79 |
if st.sidebar.button('Summarize Sentiment'):
|
| 80 |
#ast.literal_eval() is a function in Python that safely evaluates a string containing a valid Python expression,
|
| 81 |
#such as lists, dictionaries, tuples, sets, integers, and floats. It parses the string and returns the corresponding
|
| 82 |
#Python object, without executing any arbitrary code, which makes it safer than using eval().
|
| 83 |
+
summarize(txt)
|
| 84 |
else:
|
| 85 |
st.warning('👈 Please enter Sentiment!')
|