Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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...")
|