| | import streamlit as st |
| | import transformers |
| | import torch |
| | from transformers import AutoTokenizer, AutoModelForSequenceClassification |
| |
|
| | |
| |
|
| | tokenizer = AutoTokenizer.from_pretrained("Justin-J/finetuned_sentiment_modell") |
| | model = AutoModelForSequenceClassification.from_pretrained("Justin-J/finetuned_sentiment_modell") |
| |
|
| | |
| | @st.cache_resource |
| | def predict_sentiment(text): |
| | |
| | pipeline = transformers.pipeline("sentiment-analysis") |
| |
|
| | |
| | prediction = pipeline(text) |
| | sentiment = prediction[0]["label"] |
| | score = prediction[0]["score"] |
| |
|
| | return sentiment, score |
| |
|
| | |
| | st.set_page_config( |
| | page_title="Sentiment Analysis App", |
| | page_icon=":smile:", |
| | layout="wide", |
| | initial_sidebar_state="auto", |
| | ) |
| |
|
| | |
| | st.write(""" |
| | # How Positive or Negative is your Text? |
| | Enter some text and we'll tell you if it has a positive, negative, or neutral sentiment! |
| | """) |
| |
|
| |
|
| | |
| | image = st.image("https://user-images.githubusercontent.com/115732734/271723351-3677394d-1cd3-4df8-8bec-616fa6bd3b2c.png", width=550, "https://user-images.githubusercontent.com/115732734/271723332-6c824e95-5e2f-48ec-af1c-b66ac7db1d7a.jpeg", width=550, "https://user-images.githubusercontent.com/115732734/271723345-50f27ca9-94ee-4e7c-ad3b-2b10f27d31bb.jpeg", width=550) |
| | |
| | |
| |
|
| | |
| | text = st.text_input("Enter some text here:") |
| |
|
| | |
| | st.markdown( |
| | """ |
| | <style> |
| | body { |
| | background-color: #f5f5f5; |
| | } |
| | h1 { |
| | color: #4e79a7; |
| | } |
| | </style> |
| | """, |
| | unsafe_allow_html=True |
| | ) |
| |
|
| | |
| | if text: |
| | sentiment, score = predict_sentiment(text) |
| | if sentiment == "Positive": |
| | st.success(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!") |
| | elif sentiment == "Negative": |
| | st.error(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!") |
| | else: |
| | st.warning(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!") |