DeeeTeeee01 commited on
Commit
55c11e6
·
1 Parent(s): aa752b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -142,7 +142,6 @@
142
 
143
  import streamlit as st
144
  import transformers
145
- import torch
146
 
147
  # Load the model and tokenizer
148
  model = transformers.AutoModelForSequenceClassification.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")
@@ -158,7 +157,10 @@ def predict_sentiment(text):
158
  sentiment = prediction["label"]
159
  score = prediction["score"]
160
 
161
- return sentiment, score
 
 
 
162
 
163
  # Setting the page configurations
164
  st.set_page_config(
@@ -182,14 +184,13 @@ predict_button = st.button("Predict")
182
 
183
  # Show sentiment output
184
  if predict_button and text:
185
- sentiment, score = predict_sentiment(text)
186
- st.write(f"The sentiment is {sentiment} with a score of {score*100:.2f}% for each category.")
187
 
188
  # Display individual percentages
189
  st.write("Sentiment Breakdown:")
190
- st.write(f"- Negative: {score[0]*100:.2f}%")
191
- st.write(f"- Positive: {score[1]*100:.2f}%")
192
- st.write(f"- Neutral: {score[2]*100:.2f}%")
193
 
194
  # Define the CSS style for the app
195
  st.markdown(
@@ -206,3 +207,4 @@ h1 {
206
  """,
207
  unsafe_allow_html=True
208
  )
 
 
142
 
143
  import streamlit as st
144
  import transformers
 
145
 
146
  # Load the model and tokenizer
147
  model = transformers.AutoModelForSequenceClassification.from_pretrained("DeeeTeeee01/mytest_trainer_roberta-base")
 
157
  sentiment = prediction["label"]
158
  score = prediction["score"]
159
 
160
+ # Convert scores to a dictionary with labels as keys and percentages as values
161
+ scores_dict = {label: score * 100 for label, score in zip(prediction["labels"], prediction["scores"])}
162
+
163
+ return sentiment, scores_dict
164
 
165
  # Setting the page configurations
166
  st.set_page_config(
 
184
 
185
  # Show sentiment output
186
  if predict_button and text:
187
+ sentiment, scores_dict = predict_sentiment(text)
188
+ st.write(f"The sentiment is {sentiment} with a score of {scores_dict[sentiment]:.2f}% for each category.")
189
 
190
  # Display individual percentages
191
  st.write("Sentiment Breakdown:")
192
+ for label, score in scores_dict.items():
193
+ st.write(f"- {label}: {score:.2f}%")
 
194
 
195
  # Define the CSS style for the app
196
  st.markdown(
 
207
  """,
208
  unsafe_allow_html=True
209
  )
210
+