File size: 2,200 Bytes
880ccad
 
 
 
 
 
aab6005
46e4f66
 
880ccad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55bfd31
 
 
61f30f5
 
9a4c755
 
f29a503
9a4c755
61f30f5
9a4c755
 
 
 
 
 
 
 
 
 
 
55bfd31
 
 
880ccad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import streamlit as st
import transformers
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load the model and tokenizer

tokenizer = AutoTokenizer.from_pretrained("Justin-J/finetuned_sentiment_modell")
model = AutoModelForSequenceClassification.from_pretrained("Justin-J/finetuned_sentiment_modell")

# Define the function for sentiment analysis
@st.cache_resource
def predict_sentiment(text):
    # Load the pipeline.
    pipeline = transformers.pipeline("sentiment-analysis")

    # Predict the sentiment.
    prediction = pipeline(text)
    sentiment = prediction[0]["label"]
    score = prediction[0]["score"]

    return sentiment, score

# Setting the page configurations
st.set_page_config(
    page_title="Sentiment Analysis App",
    page_icon=":smile:",
    layout="wide",
    initial_sidebar_state="auto",
)

# Add description and title
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!
""")


# Add Image Tags 
st.markdown(
"""
<div class="row">
  <div class="column">
    <img src="https://user-images.githubusercontent.com/115732734/271723332-6c824e95-5e2f-48ec-af1c-b66ac7db1d7a.jpeg" style="width:550"></div>
  
  <div class="column">
    <img src="https://user-images.githubusercontent.com/115732734/271723345-50f27ca9-94ee-4e7c-ad3b-2b10f27d31bb.jpeg" style="width:550"></div>
</div>

<style>
.row {
  display: flex;
}

.column {
  flex: 33.33%;
  padding: 5px;
}
</style>
""",
unsafe_allow_html=True
)

# Get user input
text = st.text_input("Enter some text here:")

# Define the CSS style for the app
st.markdown(
"""
<style>
body {
    background-color: #f5f5f5;
}
h1 {
    color: #4e79a7;
}
</style>
""",
unsafe_allow_html=True
)

# Show sentiment output
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}%!")