Spaces:
Sleeping
Sleeping
khadija3818
commited on
Commit
•
dafef37
1
Parent(s):
f215cbd
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,30 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Streamlit web app
|
11 |
def main():
|
12 |
-
st.title("
|
13 |
|
14 |
# Input text area
|
15 |
user_input = st.text_area("Enter text:", "Type or paste your text here...")
|
16 |
|
17 |
-
# Button to trigger
|
18 |
-
if st.button("
|
19 |
-
# Classification result
|
20 |
-
classification_result = emotion_classifier(user_input)
|
21 |
-
|
22 |
# Display the result
|
23 |
-
|
24 |
-
st.write("Score:"
|
25 |
|
26 |
# Run the app
|
27 |
if __name__ == "__main__":
|
28 |
-
main()
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load the sentiment analysis model from Hugging Face
|
5 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Function to get sentiment prediction
|
8 |
+
def predict_sentiment(text):
|
9 |
+
result = sentiment_analysis(text)
|
10 |
+
label = result[0]['label']
|
11 |
+
score = result[0]['score']
|
12 |
+
return label, score
|
13 |
|
14 |
# Streamlit web app
|
15 |
def main():
|
16 |
+
st.title("Sentiment Analysis App")
|
17 |
|
18 |
# Input text area
|
19 |
user_input = st.text_area("Enter text:", "Type or paste your text here...")
|
20 |
|
21 |
+
# Button to trigger sentiment prediction
|
22 |
+
if st.button("Predict Sentiment"):
|
|
|
|
|
|
|
23 |
# Display the result
|
24 |
+
sentiment_label, sentiment_score = predict_sentiment(user_input)
|
25 |
+
st.write(f"Sentiment: {sentiment_label}, Score: {sentiment_score:.4f}")
|
26 |
|
27 |
# Run the app
|
28 |
if __name__ == "__main__":
|
29 |
+
main()
|
30 |
+
|