Skip to main content

Simple test package

Project description

Scrapeddit

Overview

Scrapeddit is a Python class designed for scraping images from Reddit subreddits and creating PyTorch datasets. It facilitates the collection of image data from various subreddits, allowing for easy integration into machine learning pipelines or data analysis projects.

Key Features

  • Reddit Scraping: Automatically retrieves image URLs from specified subreddits using the PRAW library.
  • Flexible Configuration: Users can customize parameters such as subreddit names, post limits, sorting methods, and content safety filters.
  • Data Transformation: Supports image transformation and resizing to fit specific requirements.
  • Error Handling: Handles invalid subreddits, restricted subreddits, and failed image fetching gracefully, ensuring smooth data collection.
  • Data Visualization: Provides visualization tools to understand the distribution of data sources across different subreddits.

Usage

  1. Initialization: Instantiate the ScrapeditDataset class with a list of subreddit names and optional parameters for customization. Install by:
pip install scrapeddit
pip3 install scrapeddit
  1. Authentication: Complete authentication by regestering and making a app in prawn, using that complete the authentication by:
from scrapeddit import authentication
authentication.auth_reddit(client_id = "",
                    client_secret = "",
                    username = "",
                    password = "",
                    redirect_uri = "",
                    user_agent = "",
                    check_for_async=False
)
  1. Getting Data: This is for collecting information for only on subreddit, parameters like limit, show_safe can be set
from scrapeddit import scrapeonce
scrape_df = scrapeonce.scrape_reddit('spotted', limit = 50)
  1. Data Loading: Access the dataset like any other PyTorch dataset, allowing for seamless integration into machine learning workflows. Highly recommemded: Use the provided ResizeWithPadding tranform
from scrapeddit import redditdl
from scrapeddit.redditdl import ScrapeditDataset
from scrapeddit.transforms import ResizeWithPadding
import torchvision.transforms as transforms

size = 300
transform_resize=transforms.Compose([
                              ResizeWithPadding(size=size),
                              transforms.Resize((size,size)),
                              transforms.ToTensor()
                              ])

subreddits = ['Pizza', 'burgers']
dataset = ScrapeditDataset(subreddit=subreddits, limit = 200, transform = transform_resize, max_size = 100, show_safe = True)

Calling dataset() displays bar graph useful to visualize data imbalance caused due to data unavailability utilize torch.utils.data.random_split() to split into train and test 5. Data Analysis: Use the provided visualization functions to gain insights into the distribution of data sources and explore the collected dataset.

  1. Model Training: Utilize the ScrapeditDataset as a DataLoader for training machine learning models. Integrate it with PyTorch's DataLoader for efficient batch processing and model training.
  2. Getting models: Added functionality includes getting known models, by default it freezes non classifier layers
from scrapeddit import models
model1 = models.get_efficient(device = True) # efficient net model
model2 = models.get_vision_model('vgg16', device = True) # Get any model that is available in torchvision.models
  1. Visualization: Two types of visualization are 6.1 show_images: Uses list of links of images to fetch image from the sources and display them accordingly

    from scrapeddit import showit
    showit.show_images([list of links] figsize = (10,10), max_images = 24)
    

    6.2 sample_batch: Shows a batch of image data from a dataloader

    from scrapeddit.showit import show_batch
    sample_batch = next(iter(train_dataloader)) # Getting a batch of data
    show_batch(sample_batch = sample_batch, max = 100, figsize = (15,15))
    

Requirements

  • Python 3.x
  • PRAW
  • pandas
  • requests
  • matplotlib
  • Pillow
  • torch
  • torchvision
  • tqdm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapeddit-0.3.6.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapeddit-0.3.6-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file scrapeddit-0.3.6.tar.gz.

File metadata

  • Download URL: scrapeddit-0.3.6.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for scrapeddit-0.3.6.tar.gz
Algorithm Hash digest
SHA256 76c6a5b42737d60abbb33da3ec0bc3d498950ad66278e6adce58bb1326142cec
MD5 9246c71e33f7517bed2a8af0fddc293d
BLAKE2b-256 8ccb32d2c4a6bba2124db99017ab4c5e4bcda6656ad25cf201b86621c4f58c30

See more details on using hashes here.

File details

Details for the file scrapeddit-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: scrapeddit-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for scrapeddit-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ecdcb61cbe630695fa07c0b226aa2e19dc28845260b9c92c32a5ab38dcfe252c
MD5 b58a211ff4e2e64806ee3cf0aa0f5bce
BLAKE2b-256 be9f72bccc16d98c65d10aeeb6bef1318c056745a0064f6dd4c94ec9cbbe96f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page