kmanoj commited on
Commit
ed4a54d
1 Parent(s): 61fa3f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -4,16 +4,27 @@ from transformers import pipeline
4
  pipe=pipeline('sentiment-analysis')
5
  # Set the title
6
  st.title("Sentiment Analysis")
7
- # Input for text to analyze sentiment
8
- text = st.text_area("Enter text for sentiment analysis:")
9
-
10
- if text:
11
- if st.button("Analyze Sentiment"):
12
- out=pipe(text)
13
- result=out[0]
14
- sentiment = result["label"]
15
- score = result["score"]
16
- st.write(f"Sentiment: {sentiment}")
17
- st.write(f"Sentiment Score: {score}")
 
 
 
 
 
 
 
 
 
 
 
18
  # else:
19
  # st.error("Error: Something went wrong. Please try again...")
 
4
  pipe=pipeline('sentiment-analysis')
5
  # Set the title
6
  st.title("Sentiment Analysis")
7
+
8
+ # Using 'form' to group input elements together
9
+ with st.form("sentiment Analysis"):
10
+ # Input for text to analyze sentiment
11
+ text = st.text_area("Enter text for sentiment analysis:")
12
+
13
+ # Add a button to analyze sentiment
14
+ submit_button = st.form_submit_button("Analyze Sentiment")
15
+
16
+ # Check if the form was submitted
17
+ if text and submit_button:
18
+ out = pipe(text)
19
+ result = out[0] # Assuming you want the first result if multiple are returned
20
+ sentiment = result["label"]
21
+ score = round(result["score"], 2) # Round the score to two decimal places
22
+ st.write(f"Sentiment: {sentiment}")
23
+ st.write(f"Sentiment Score: {score}")
24
+
25
+
26
+
27
+
28
+
29
  # else:
30
  # st.error("Error: Something went wrong. Please try again...")