Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
st.
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Analyze and display results
|
16 |
-
if st.button("Analyze"):
|
17 |
-
if user_input.strip():
|
18 |
-
result = classifier(user_input)
|
19 |
-
st.write(f"**Result:** {result[0]['label']} ({result[0]['score']:.2f})")
|
20 |
-
else:
|
21 |
-
st.warning("Please enter some text.")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the sentiment analysis pipeline
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model():
|
7 |
+
return pipeline("sentiment-analysis")
|
8 |
|
9 |
+
def main():
|
10 |
+
st.title("Sentiment Analysis App")
|
11 |
+
|
12 |
+
# Create text input
|
13 |
+
user_input = st.text_area("Enter text for sentiment analysis:")
|
14 |
+
|
15 |
+
# Analyze button
|
16 |
+
if st.button("Analyze Sentiment"):
|
17 |
+
if user_input:
|
18 |
+
# Load model
|
19 |
+
sentiment_model = load_model()
|
20 |
+
|
21 |
+
# Perform sentiment analysis
|
22 |
+
result = sentiment_model(user_input)[0]
|
23 |
+
|
24 |
+
# Display results
|
25 |
+
st.write("Sentiment:", result['label'])
|
26 |
+
st.write("Confidence Score:", f"{result['score']:.2%}")
|
27 |
+
else:
|
28 |
+
st.warning("Please enter some text to analyze.")
|
29 |
|
30 |
+
if __name__ == "__main__":
|
31 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|