Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,53 +2,32 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the sentiment analysis model pipeline
|
| 5 |
-
|
| 6 |
|
| 7 |
# Streamlit application title and background image
|
| 8 |
st.image("./header.png", use_column_width=True)
|
| 9 |
-
st.
|
| 10 |
|
| 11 |
st.write("Setiment classification: positive, netural, negative")
|
| 12 |
|
| 13 |
# User can enter the customer review
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# Perform sentiment analysis on the input text
|
| 19 |
-
results = classifier(text)[0]
|
| 20 |
-
|
| 21 |
-
# Display the classification result
|
| 22 |
max_score = float('-inf')
|
| 23 |
max_label = ''
|
| 24 |
-
|
| 25 |
for result in results:
|
| 26 |
if result['score'] > max_score:
|
| 27 |
max_score = result['score']
|
| 28 |
max_label = result['label']
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
st.
|
| 37 |
-
st.write("Product classification of this negative review: smartTv, books, mobile, mobile accessories and refrigerators")
|
| 38 |
-
|
| 39 |
-
# Perform product classification analysis when the user clicks the "Classify product" button
|
| 40 |
-
if st.button("Classify product"):
|
| 41 |
-
# Perform product classification analysis on the input text
|
| 42 |
-
results_1 = classifier(text)[0]
|
| 43 |
-
|
| 44 |
-
# Display the classification result
|
| 45 |
-
max_score_1 = float('-inf')
|
| 46 |
-
max_label_1 = ''
|
| 47 |
-
|
| 48 |
-
for result_1 in results_1:
|
| 49 |
-
if result_1['score_1'] > max_score_1:
|
| 50 |
-
max_score_1 = result_1['score_1']
|
| 51 |
-
max_label_1 = result_1['label_1']
|
| 52 |
|
| 53 |
-
st.write("This negative review belongs to:", max_label_1)
|
| 54 |
-
st.write("Accuracy rate is:", max_score_1)
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the sentiment analysis model pipeline
|
| 5 |
+
sentiment_classifier = pipeline("text-classification",model='Ryleeeee/CustomSentimentModel', return_all_scores=True)
|
| 6 |
|
| 7 |
# Streamlit application title and background image
|
| 8 |
st.image("./header.png", use_column_width=True)
|
| 9 |
+
st.header("Customer Review Analysis")
|
| 10 |
|
| 11 |
st.write("Setiment classification: positive, netural, negative")
|
| 12 |
|
| 13 |
# User can enter the customer review
|
| 14 |
+
review = st.text_area("Enter the customer review", "")
|
| 15 |
|
| 16 |
+
def sentiment_class(text):
|
| 17 |
+
results = sentiment_classifier(text)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
max_score = float('-inf')
|
| 19 |
max_label = ''
|
|
|
|
| 20 |
for result in results:
|
| 21 |
if result['score'] > max_score:
|
| 22 |
max_score = result['score']
|
| 23 |
max_label = result['label']
|
| 24 |
+
return max_score, max_label
|
| 25 |
|
| 26 |
+
|
| 27 |
+
# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
|
| 28 |
+
if review is not None and st.button("Classify Sentiment"):
|
| 29 |
+
# Perform sentiment analysis on the input text
|
| 30 |
+
sentiment_result = sentiment_class(review)
|
| 31 |
+
st.write("This review sentiment is ", sentiment_result[1])
|
| 32 |
+
st.write("Prediction score is ", sentiment_result[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
|
|