TA_1 / app.py
Dineth98's picture
Update app.py
5685146
raw
history blame
1.35 kB
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("Dineth")
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("Fuck off")
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()