Update app.py
Browse files
app.py
CHANGED
|
@@ -55,26 +55,34 @@ DEFAULT_SENTIMENT = "I'm so happy today!"
|
|
| 55 |
# Create a text area for user input
|
| 56 |
SENTIMENT = st.sidebar.text_area('Enter Sentiment', DEFAULT_SENTIMENT, height=150)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Define the summarization function
|
| 59 |
def summarize(txt):
|
| 60 |
|
| 61 |
-
txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
|
| 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 |
-
if isinstance(txt_converted, list):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
for i, text in enumerate(txt_converted):
|
| 74 |
st.write(f"Text: {text}")
|
| 75 |
st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
|
| 76 |
else:
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
| 79 |
|
| 80 |
# Create a button and trigger the summarize function when clicked
|
|
|
|
| 55 |
# Create a text area for user input
|
| 56 |
SENTIMENT = st.sidebar.text_area('Enter Sentiment', DEFAULT_SENTIMENT, height=150)
|
| 57 |
|
| 58 |
+
def is_valid_list_string(string):
|
| 59 |
+
try:
|
| 60 |
+
result = ast.literal_eval(string)
|
| 61 |
+
return isinstance(result, list)
|
| 62 |
+
except (ValueError, SyntaxError):
|
| 63 |
+
return False
|
| 64 |
+
|
| 65 |
# Define the summarization function
|
| 66 |
def summarize(txt):
|
| 67 |
|
|
|
|
|
|
|
| 68 |
st.write('\n\n')
|
| 69 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
| 70 |
st.write('--------------------------------------------------------------')
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Display the results
|
| 73 |
#if type(txt_converted) == 'list':
|
| 74 |
+
#if isinstance(txt_converted, list):
|
| 75 |
+
if is_valid_list_string(txt):
|
| 76 |
+
txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
|
| 77 |
+
# Perform Hugging sentiment analysis on multiple texts
|
| 78 |
+
results = sentiment_pipeline(txt_converted)
|
| 79 |
for i, text in enumerate(txt_converted):
|
| 80 |
st.write(f"Text: {text}")
|
| 81 |
st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
|
| 82 |
else:
|
| 83 |
+
# Perform Hugging sentiment analysis on multiple texts
|
| 84 |
+
results = sentiment_pipeline(txt)
|
| 85 |
+
st.write(f"Text: {txt}")
|
| 86 |
st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
| 87 |
|
| 88 |
# Create a button and trigger the summarize function when clicked
|