Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
141 |
|
142 |
# --- Sentiment Analysis Section ---
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
|
148 |
-
|
149 |
-
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
|
155 |
-
with st.spinner("Doing
|
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 |
|