kusa04 commited on
Commit
23f32f5
·
verified ·
1 Parent(s): 1ab75eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -137,22 +137,22 @@ if st.button("Scrape Reddit"):
137
 
138
  if st.button("Sentiment Analysis"):
139
  df = st.session_state.get("df")
140
- progress_text.text("df loaded...")
141
 
142
  # --- Sentiment Analysis Section ---
143
- progress_text.text("sentiment pipeline loading...")
144
- tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
145
- model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest",
146
- use_auth_token=st.secrets["hugging_face_token"])
147
 
148
- sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, device=-1)
149
- progress_text.text("sentiment pipeline loaded...")
150
 
151
- max_tokens = tokenizer.model_max_length
152
- if max_tokens > 10000:
153
- max_tokens = 512
154
 
155
- with st.spinner("Doing sentiment analysis..."):
156
  # Apply sentiment analysis to Title directly (assuming Title is short)
157
  df['title_sentiment'] = df['Title'].apply(lambda x: safe_sentiment(preprocess_text(x)) if x else None)
158
 
 
137
 
138
  if st.button("Sentiment Analysis"):
139
  df = st.session_state.get("df")
140
+ st.write("df loaded...")
141
 
142
  # --- Sentiment Analysis Section ---
143
+ with st.spinner("Loading Sentiment Pipeline..."):
144
+ tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
145
+ model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest",
146
+ use_auth_token=st.secrets["hugging_face_token"])
147
 
148
+ sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, device=-1)
149
+ st.write("sentiment pipeline loaded...")
150
 
151
+ max_tokens = tokenizer.model_max_length
152
+ if max_tokens > 10000:
153
+ max_tokens = 512
154
 
155
+ with st.spinner("Doing Sentiment Analysis..."):
156
  # Apply sentiment analysis to Title directly (assuming Title is short)
157
  df['title_sentiment'] = df['Title'].apply(lambda x: safe_sentiment(preprocess_text(x)) if x else None)
158