Skip to content

Instantly share code, notes, and snippets.

@vhxs
Last active September 25, 2022 23:13
Show Gist options
  • Save vhxs/fd99c4cacfc8a7e4e4f6de0e5c5bf347 to your computer and use it in GitHub Desktop.
Save vhxs/fd99c4cacfc8a7e4e4f6de0e5c5bf347 to your computer and use it in GitHub Desktop.
Quick example of using a pre-trained huggingface model for sentimental classification of streamed r/votedem comments
from transformers import pipeline
import praw
import os
reddit = praw.Reddit(
client_id=os.environ['REDDIT_ID'],
client_secret=os.environ['REDDIT_SECRET'],
password=os.environ['REDDIT_PASS'],
user_agent="script by u/vsaraph",
username="vsaraph"
)
subreddit = reddit.subreddit("votedem")
classifier = pipeline("sentiment-analysis")
for comment in subreddit.stream.comments(skip_existing=True):
print(comment.body)
print(classifier(comment.body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment