richardorama commited on
Commit
ae42482
β€’
1 Parent(s): eac3bfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -47
app.py CHANGED
@@ -14,6 +14,55 @@ st.markdown("<h3 style='text-align: center; font-size: 16px;'>Simply Assorted La
14
  st.markdown("<h3 style='text-align: center; font-size: 20px; color: blue;'>Orama's AI Craze</h3>", unsafe_allow_html=True)
15
 
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ################ STATEMENT SUMMARIZATION - main area #################
18
 
19
 
@@ -118,53 +167,6 @@ else:
118
  #st.warning('πŸ‘ˆ Please enter Statement!')
119
 
120
 
121
- ################ SENTIMENT ANALYSIS - side bar #################
122
-
123
- # Initialize the sentiment analysis pipeline
124
- # No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
125
- sentiment_pipeline = pipeline("sentiment-analysis")
126
-
127
- def is_valid_list_string(string):
128
- try:
129
- result = ast.literal_eval(string)
130
- return isinstance(result, list)
131
- except (ValueError, SyntaxError):
132
- return False
133
-
134
- # Define the summarization function
135
- def analyze_sentiment(txt):
136
-
137
- st.write('\n\n')
138
- #st.write(txt[:100]) # Display the first 100 characters of the article
139
- #st.write('--------------------------------------------------------------')
140
-
141
- # Display the results
142
- if is_valid_list_string(txt):
143
- txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
144
- # Perform Hugging sentiment analysis on multiple texts
145
- results = sentiment_pipeline(txt_converted)
146
- for i, text in enumerate(txt_converted):
147
- st.write(f"Text: {text}")
148
- st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
149
- else:
150
- # Perform Hugging sentiment analysis on multiple texts
151
- results = sentiment_pipeline(txt)
152
- st.write(f"Text: {txt}")
153
- st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
154
-
155
- st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Sentiment Analysis</h3>", unsafe_allow_html=True)
156
- DEFAULT_SENTIMENT = ""
157
- # Create a text area for user input
158
- SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
159
-
160
- # Enable the button only if there is text in the SENTIMENT variable
161
- if SENTIMENT:
162
- if st.sidebar.button('Analyze Sentiment'):
163
- analyze_sentiment(SENTIMENT) # Directly pass the SENTIMENT
164
- else:
165
- st.sidebar.button('Analyze Sentiment', disabled=True)
166
- st.warning('πŸ‘ˆ Please enter Sentiment!')
167
-
168
 
169
  # ################ CHAT BOT - main area #################
170
 
 
14
  st.markdown("<h3 style='text-align: center; font-size: 20px; color: blue;'>Orama's AI Craze</h3>", unsafe_allow_html=True)
15
 
16
 
17
+ ################ SENTIMENT ANALYSIS - side bar #################
18
+
19
+ # Initialize the sentiment analysis pipeline
20
+ # No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
21
+ sentiment_pipeline = pipeline("sentiment-analysis")
22
+
23
+ def is_valid_list_string(string):
24
+ try:
25
+ result = ast.literal_eval(string)
26
+ return isinstance(result, list)
27
+ except (ValueError, SyntaxError):
28
+ return False
29
+
30
+ # Define the summarization function
31
+ def analyze_sentiment(txt):
32
+
33
+ st.write('\n\n')
34
+ #st.write(txt[:100]) # Display the first 100 characters of the article
35
+ #st.write('--------------------------------------------------------------')
36
+
37
+ # Display the results
38
+ if is_valid_list_string(txt):
39
+ txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
40
+ # Perform Hugging sentiment analysis on multiple texts
41
+ results = sentiment_pipeline(txt_converted)
42
+ for i, text in enumerate(txt_converted):
43
+ st.write(f"Text: {text}")
44
+ st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n")
45
+ else:
46
+ # Perform Hugging sentiment analysis on multiple texts
47
+ results = sentiment_pipeline(txt)
48
+ st.write(f"Text: {txt}")
49
+ st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
50
+
51
+ st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Sentiment Analysis</h3>", unsafe_allow_html=True)
52
+ DEFAULT_SENTIMENT = ""
53
+ # Create a text area for user input
54
+ SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
55
+
56
+ # Enable the button only if there is text in the SENTIMENT variable
57
+ if SENTIMENT:
58
+ if st.sidebar.button('Analyze Sentiment'):
59
+ analyze_sentiment(SENTIMENT) # Directly pass the SENTIMENT
60
+ else:
61
+ st.sidebar.button('Analyze Sentiment', disabled=True)
62
+ st.warning('πŸ‘ˆ Please enter Sentiment!')
63
+
64
+
65
+
66
  ################ STATEMENT SUMMARIZATION - main area #################
67
 
68
 
 
167
  #st.warning('πŸ‘ˆ Please enter Statement!')
168
 
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  # ################ CHAT BOT - main area #################
172