File size: 1,790 Bytes
a4c6c31 9d5a490 47ea938 9d5a490 a4c6c31 6735bf3 f888e9e 6735bf3 a4c6c31 9d5a490 86bc0ed 9d5a490 5685146 9d5a490 5685146 9d5a490 5685146 a4c6c31 5685146 4637a97 a4c6c31 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from transformers import pipeline
def sentiment_funtion(text):
model = pipeline("sentiment-analysis", model="stevhliu/my_awesome_model")
output = model(text)[0]
label = output["label"]
score = output["score"]
return label , score
def main():
st.title("Sentiment Analysis app")
st.sidebar.image("https://huggingface.co/spaces/Dineth98/TA_1/resolve/main/sentiment-analysis-1280x720.jpg", use_column_width=True)
st.sidebar.subheader("About This App")
st.sidebar.write("The app takes feedbacks as input and automatically identifies whether the feedback is positive, negative, or neutral. This analysis can be useful for businesses to gain insights into customer opinions and improve their products or services accordingly. The app can also be used by individuals to analyze social media posts, emails, and other forms of written communication to better understand the emotional tone of the message.")
user_input = st.text_area("Input Text Here")
if st.button("Sentiment"):
label , score = sentiment_funtion(user_input)
if label == "LABEL_1":
label = "Positive"
postive_score = score
negative_score = 1 - score
color = "green"
else:
label = "Negative"
postive_score = 1 - score
negative_score = score
color = "red"
style = f'color:{color}'
text = f'Sentiment Label: {label}'
sentiment_text = f'<h4 style="{style}">{text}</h4>'
st.write("Sentiment:")
st.write(sentiment_text, unsafe_allow_html=True)
st.write(f"Positive Score: {postive_score:.2f}")
st.write(f"Negative Score: {negative_score:.2f}")
if __name__ == "__main__":
main() |