Spaces:
Runtime error
Runtime error
Commit
·
3b89cb9
1
Parent(s):
1367a06
Update app.py
Browse files
app.py
CHANGED
@@ -158,7 +158,7 @@ def added_token_hash_func(token):
|
|
158 |
return token.__str__()
|
159 |
|
160 |
# Define the function for sentiment analysis
|
161 |
-
@st.
|
162 |
def predict_sentiment(text):
|
163 |
# Load the pipeline
|
164 |
pipeline = transformers.pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
@@ -170,7 +170,6 @@ def predict_sentiment(text):
|
|
170 |
|
171 |
return sentiment, score
|
172 |
|
173 |
-
|
174 |
# Setting the page configurations
|
175 |
st.set_page_config(
|
176 |
page_title="Sentiment Analysis App",
|
@@ -198,9 +197,9 @@ if predict_button and text:
|
|
198 |
|
199 |
# Display individual percentages
|
200 |
st.write("Sentiment Breakdown:")
|
201 |
-
st.write(f"- Negative: {score['
|
202 |
-
st.write(f"- Positive: {score['
|
203 |
-
st.write(f"- Neutral: {score['
|
204 |
|
205 |
# Define the CSS style for the app
|
206 |
st.markdown(
|
@@ -216,5 +215,4 @@ h1 {
|
|
216 |
</style>
|
217 |
""",
|
218 |
unsafe_allow_html=True
|
219 |
-
)
|
220 |
-
|
|
|
158 |
return token.__str__()
|
159 |
|
160 |
# Define the function for sentiment analysis
|
161 |
+
@st.cache_data(hash_funcs={tokenizers.Tokenizer: tokenizer_hash_func, tokenizers.AddedToken: added_token_hash_func})
|
162 |
def predict_sentiment(text):
|
163 |
# Load the pipeline
|
164 |
pipeline = transformers.pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
|
|
170 |
|
171 |
return sentiment, score
|
172 |
|
|
|
173 |
# Setting the page configurations
|
174 |
st.set_page_config(
|
175 |
page_title="Sentiment Analysis App",
|
|
|
197 |
|
198 |
# Display individual percentages
|
199 |
st.write("Sentiment Breakdown:")
|
200 |
+
st.write(f"- Negative: {score['LABEL_0']*100:.2f}%")
|
201 |
+
st.write(f"- Positive: {score['LABEL_1']*100:.2f}%")
|
202 |
+
st.write(f"- Neutral: {score['LABEL_2']*100:.2f}%")
|
203 |
|
204 |
# Define the CSS style for the app
|
205 |
st.markdown(
|
|
|
215 |
</style>
|
216 |
""",
|
217 |
unsafe_allow_html=True
|
218 |
+
)
|
|