richardorama
commited on
Commit
β’
8cf4aa8
1
Parent(s):
d19d235
Update app.py
Browse files
app.py
CHANGED
@@ -54,10 +54,7 @@ sentiment_pipeline = pipeline("sentiment-analysis")
|
|
54 |
# ]"""
|
55 |
|
56 |
# DEFAULT_SENTIMENT = "I'm so happy today!"
|
57 |
-
DEFAULT_SENTIMENT = ""
|
58 |
|
59 |
-
# Create a text area for user input
|
60 |
-
SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
|
61 |
|
62 |
def is_valid_list_string(string):
|
63 |
try:
|
@@ -67,7 +64,7 @@ def is_valid_list_string(string):
|
|
67 |
return False
|
68 |
|
69 |
# Define the summarization function
|
70 |
-
def
|
71 |
|
72 |
st.write('\n\n')
|
73 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
@@ -89,12 +86,27 @@ def summarize(txt):
|
|
89 |
st.write(f"Text: {txt}")
|
90 |
st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
else:
|
100 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# ]"""
|
55 |
|
56 |
# DEFAULT_SENTIMENT = "I'm so happy today!"
|
|
|
57 |
|
|
|
|
|
58 |
|
59 |
def is_valid_list_string(string):
|
60 |
try:
|
|
|
64 |
return False
|
65 |
|
66 |
# Define the summarization function
|
67 |
+
def analyze(txt):
|
68 |
|
69 |
st.write('\n\n')
|
70 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
|
|
86 |
st.write(f"Text: {txt}")
|
87 |
st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
88 |
|
89 |
+
|
90 |
+
DEFAULT_SENTIMENT = ""
|
91 |
+
# Create a text area for user input
|
92 |
+
SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
|
93 |
+
|
94 |
+
# Enable the button only if there is text in the SENTIMENT variable
|
95 |
+
if SENTIMENT:
|
96 |
+
if st.sidebar.button('Analyze Sentiment'):
|
97 |
+
# Call your Analyze function here
|
98 |
+
#st.write(f"Summarizing: {SENTIMENT}")
|
99 |
+
analyze(SENTIMENT) # Directly pass the SENTIMENT
|
100 |
else:
|
101 |
+
st.sidebar.button('Summarize Sentiment', disabled=True)
|
102 |
+
st.warning('π Please enter Sentiment!')
|
103 |
+
|
104 |
+
# # Create a button and trigger the summarize function when clicked
|
105 |
+
# if st.sidebar.button('Summarize Sentiment'):
|
106 |
+
# #ast.literal_eval() is a function in Python that safely evaluates a string containing a valid Python expression,
|
107 |
+
# #such as lists, dictionaries, tuples, sets, integers, and floats. It parses the string and returns the corresponding
|
108 |
+
# #Python object, without executing any arbitrary code, which makes it safer than using eval().
|
109 |
+
# #summarize(str(SENTIMENT)) #explicitly change SENTIMENT to string so that even when ypu provide unquoted string, it still works
|
110 |
+
# analyze(SENTIMENT) # Directly pass the SENTIMENT
|
111 |
+
# else:
|
112 |
+
# st.warning('π Please enter Sentiment!')
|