File size: 5,638 Bytes
720ebfc
 
 
5757326
720ebfc
 
 
5757326
720ebfc
 
 
 
 
5757326
720ebfc
 
 
 
5757326
720ebfc
5757326
720ebfc
 
 
 
 
 
 
1f9eb21
720ebfc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5757326
720ebfc
 
 
 
 
 
 
 
 
5757326
7cfa370
1f9eb21
ac2a663
881d7b3
 
 
 
 
 
 
 
 
 
ccbd4ac
881d7b3
 
ccbd4ac
881d7b3
ccbd4ac
881d7b3
ccbd4ac
 
 
881d7b3
 
 
 
 
 
 
 
 
 
 
 
 
ccbd4ac
 
881d7b3
 
ccbd4ac
 
 
881d7b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccbd4ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585c098
ccbd4ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa752b7
 
 
ccbd4ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585c098
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# import streamlit as st
# import transformers
# import torch

# # Load the model and tokenizer
# model = transformers.AutoModelForSequenceClassification.from_pretrained("DeeeTeeee01/twitter-xlm-roberta-base-sentiment_dee")
# tokenizer = transformers.AutoTokenizer.from_pretrained("DeeeTeeee01/twitter-xlm-roberta-base-sentiment_dee")

# # 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("""
# # Predict if your text is  Positive, Negative or Nuetral ...
# Please type your text and press ENTER key to know if your text is positive, negative, or neutral sentiment!
# """)


# # Add image
# image = st.image("sentiment.jpeg", width=400)

# # Get user input
# text = st.text_input("Type 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}%!")





# import streamlit as st
# import transformers
# import torch

# # Load the model and tokenizer
# model = transformers.AutoModelForSequenceClassification.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")
# tokenizer = transformers.AutoTokenizer.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")

# # 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("""
# # Predict if your text is Positive, Negative or Neutral ...
# Please type your text and click the Predict button to know if your text has a positive, negative or neutral sentiment!
# """)

# # Add image
# image = st.image("sentiment.jpeg", width=400)

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

# # Add Predict button
# predict_button = st.button("Predict")

# # Define the CSS style for the app
# st.markdown(
# """
# <style>
# body {
#     background: linear-gradient(to right, #4e79a7, #86a8e7);
#     color: lightblue;
# }
# h1 {
#     color: #4e79a7;
# }
# </style>
# """,
# unsafe_allow_html=True
# )

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

import streamlit as st
import transformers
import torch

# Load the model and tokenizer
model = transformers.AutoModelForSequenceClassification.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")
tokenizer = transformers.AutoTokenizer.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")

# Define the function for sentiment analysis without caching
def predict_sentiment(text):
    # Load the pipeline
    pipeline = transformers.pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

    # Predict the sentiment
    prediction = pipeline(text)[0]
    sentiment = prediction["label"]
    score = prediction["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("""
# Predict if your text is Positive, Negative, or Neutral ...
Please type your text and click the Predict button to know the sentiment!
""")

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

# Add Predict button
predict_button = st.button("Predict")

# Show sentiment output
if predict_button and text:
    sentiment, score = predict_sentiment(text)
    st.write(f"The sentiment is {sentiment} with a score of {score*100:.2f}% for each category.")
    
    # Display individual percentages
    st.write("Sentiment Breakdown:")
    st.write(f"- Negative: {score[0]*100:.2f}%")
    st.write(f"- Positive: {score[1]*100:.2f}%")
    st.write(f"- Neutral: {score[2]*100:.2f}%")

# Define the CSS style for the app
st.markdown(
"""
<style>
body {
    background: linear-gradient(to right, #4e79a7, #86a8e7);
    color: lightblue;
}
h1 {
    color: #4e79a7;
}
</style>
""",
unsafe_allow_html=True
)