From 7c2db5721b20253905dfac06dbc36de6c3d21a14 Mon Sep 17 00:00:00 2001 From: Cindy Qi Li Date: Wed, 29 Mar 2023 10:07:39 -0400 Subject: [PATCH] feat: add a utlity script for resizing images --- .flake8 | 4 + .github/CONTRIBUTING.md | 59 ++++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 31 ++++++ .github/ISSUE_TEMPLATE/feature_request.md | 23 ++++ .github/code_of_conduct.md | 130 ++++++++++++++++++++++ .github/pull_request_template.md | 19 ++++ .gitignore | 3 + README.md | 77 ++++++++++++- requirements.txt | 2 + utils/resize_images.py | 66 +++++++++++ 10 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 .flake8 create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/code_of_conduct.md create mode 100644 .github/pull_request_template.md create mode 100644 requirements.txt create mode 100644 utils/resize_images.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..d3edf2c --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +exclude=.venv +filename=*.py +extend-ignore=E501 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..69a13ee --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,59 @@ +# Contributing + +## Process/Workflow + +The project's [source code](https://github.com/inclusive-design/baby-bliss-bot) is hosted on GitHub. All of the code +that is included in a release lives in the main branch. The intention is that the main branch is always in a working +state. + +This project uses a workflow where contributors fork the project repository, work in a branch created off of main, +and submit a Pull Request against the project repo's main branch. + +### Issue Tracker + +Issues are tracked using [GitHub Issues](https://github.com/inclusive-design/baby-bliss-bot/issues). When creating a +new issue, please pick the most appropriate type (e.g. bug, feature) and fill out the template with all the +necessary information. Issues should be meaningful and describe the task, bug, or feature in a way that can be +understood by the community. Opaque or general descriptions should be avoided. If you have a large task that will +involve a number of substantial commits, consider breaking it up into subtasks. + +### Linting + +In order to avoid errors and common pitfalls in python language, all code should be regularly checked using the +provided lint task. + +```bash +flake8 +``` + +### Pull Requests and Merging + +If you are starting work on a new feature or bug fix, create a new branch from [dev][dev]: + +```bash +git checkout dev +git checkout -b your-branch-name +``` + +Give your branch a descriptive name: + +- For a new feature, call it `feat/description-of-feature` +- For a bug fix, call it `fix/description-of-bug` + +When committing your changes, use [Conventional Commits](https://conventionalcommits.org/). + +When your work is complete, open a pull request against the [main][main] branch: + +- The title of the pull request is in the format of `: (resolves )` + - For example, for a new feature that resolves the issue id #1, the title is `feat: description of the feature (resolves #1)`. + This makes sure the issue id(s) is included in the commit history for easy access in the future. +- Please make sure to fill out the pull request template. + +After a Pull Request (PR) has been submitted, one or more team members will review the contribution. This +typically results in a back and forth conversation and modifications to the PR. Merging into the project repo is a +manual process and requires at least one Maintainer to sign off on the PR and merge it into the project repo. + +When merging a Pull Request, it is recommended to use a [Squash Merge]( +https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#squash-and-merge-your-pull-request-commits). +While this does modify commit history, it will enable us to more easily establish a link between code changes and Issues +that precipitated them. diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..8f72330 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' +--- + +## Describe the bug + +A clear and concise description of what the bug is. + +## To Reproduce + +Steps to reproduce the behavior: + +1. Go to '...' +2. Run '....' +3. See error + +## Expected behavior + +A clear and concise description of what you expected to happen. + +## Screenshots + +If applicable, add screenshots to help explain your problem. + +## Additional context + +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..45d0529 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' +--- + +## Is your feature request related to a problem? Please describe. + +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +## Describe the solution you'd like + +A clear and concise description of what you want to happen. + +## Describe alternatives you've considered + +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context + +Add any other context or screenshots about the feature request here. diff --git a/.github/code_of_conduct.md b/.github/code_of_conduct.md new file mode 100644 index 0000000..068292e --- /dev/null +++ b/.github/code_of_conduct.md @@ -0,0 +1,130 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[nzimmerman@ocadu.ca](mailto:nzimmerman@ocadu.ca). + +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html). + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at +[https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..9dddb6d --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,19 @@ +## Description + + + +## Steps to test + +1. +2. +3. + +**Expected behavior:** + +## Additional information + + + +## Related issues + + diff --git a/.gitignore b/.gitignore index b6e4761..847a3b9 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# MAC OS system file +.DS_Store diff --git a/README.md b/README.md index c0e1b72..c4a3e6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,75 @@ -# baby-bliss-bot -An exploratory research to generate new Bliss vocabulary +# Baby Bliss Bot + +An exploratory research to generate new Bliss vocabulary. + +[Bliss language](https://www.blissymbolics.org/) is an Augmentative and Alternative Communication (AAC) language +used by individuals with severe speech and physical impairments around the world, but also by others for language +learning and support, or just for the fascination and joy of this unique language representation. It is a semantic +graphical language that is currently composed of more than 5000 authorized symbols - Bliss-characters and Bliss-words. +It is a generative language that allows its users to create new Bliss-words as needed. + +The generation of new vocabulary situates in the context of an exploratory research that could leverage from emerging +trends in AI methods and technologies, including the use of Large Language Models (LLM) such as GPT and other models +for text generation and completion. + +## Local Installation + +### Prerequisites + +* [Python 3](https://www.python.org/downloads/) + * Version 3.9+. On Mac, Homebrew is the easiest way to install. +* [virtualenv](https://virtualenv.pypa.io/en/latest/) + * Not required, but highly recommended for maintaining an isolated environment for Python and Python packages. + +### Clone the Repository + +* Clone the project from GitHub. [Create a fork](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) +with your GitHub account, then run the following in your command line (make sure to replace `your-username` with +your username): + +```bash +git clone https://github.com/your-username/baby-bliss-bot +cd baby-bliss-bot +``` + +### Create/Activitate Virtual Environment +Always activate and use the python virtual environment to maintain an isolated environment for project's dependencies. + +* [Create the virtual environment](https://docs.python.org/3/library/venv.html) + (one time setup): + - `python -m venv .venv` + - Or do this via your IDE, e.g. [Intellij's support for virtualenv](https://www.jetbrains.com/help/idea/creating-virtual-environment.html) + +* Activate (every command-line session): + - Windows: `.\.venv\Scripts\activate` + - Mac/Linux: `source .venv/bin/activate` + +### Install Python Dependencies + +Run in the baby-bliss-bot directory: +* `pip install -r requirements.txt` + +## Linting + +Run the following command to lint all python scripts: + +* `flake8` + +## Utility Functions + +All utility functions are in `utils` directory. + +### Resize images (utils/resize_images.py) + +This script resizes JPG and PNG images in a directory to a specified size while maintaining their aspect ratios. +The resized images are saved in a new directory. If the output directory doesn't exist, it will be created. + +**Usage**: python resize_images.py [input_dir] [output_dir] [new_size] + +*input_dir*: The directory where the original images are located. +*output_dir*: The directory where the resized images will be saved. +*new_size*: The desired size of the resized images, in the format "widthxheight". + +**Example**: python resize_images.py images/ resized_images/ 128x128 + +**Returns**: None diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fd91731 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Pillow +flake8 diff --git a/utils/resize_images.py b/utils/resize_images.py new file mode 100644 index 0000000..0c34853 --- /dev/null +++ b/utils/resize_images.py @@ -0,0 +1,66 @@ +""" +This script resizes JPG and PNG images in a directory to a specified size +while maintaining their aspect ratios. The resized images are saved in a new +directory. If the output directory doesn't exist, it will be created. + +Usage: python resize_images.py [input_dir] [output_dir] [new_size] + +input_dir: The directory where the original images are located. +output_dir: The directory where the resized images will be saved. +new_size: The desired size of the resized images, in the format "widthxheight". + +Example: python resize_images.py images/ resized_images/ 128x128 + +Returns: None +""" + +import os +import sys +from PIL import Image + +# Check if the correct number of arguments were provided +if len(sys.argv) != 4: + print(f"Usage: {sys.argv[0]} input_directory output_directory size") + print(f"Example: {sys.argv[0]} images/ resized_images/ 128x128") + sys.exit(1) + +# Parse the input arguments +input_dir = sys.argv[1] +output_dir = sys.argv[2] +size_str = sys.argv[3] + +# Check if the input directory exists +if not os.path.isdir(input_dir): + print(f"Error: Input directory {input_dir} not found") + sys.exit(1) + +# Create the output directory if it doesn't exist +if not os.path.isdir(output_dir): + os.makedirs(output_dir) + +# Parse the size string into width and height +try: + width, height = map(int, size_str.split('x')) +except ValueError: + print(f"Error: Invalid size string {size_str}. Must be in the format 'widthxheight'") + sys.exit(1) + +# Iterate over all files in the input directory +for filename in os.listdir(input_dir): + # Check if the file is an image + if not filename.endswith('.jpg') and not filename.endswith('.jpeg') and not filename.endswith('.png'): + continue + + # Open the image file + filepath = os.path.join(input_dir, filename) + with Image.open(filepath) as img: + # Resize the image while maintaining its aspect ratio + img.thumbnail((width, height)) + + # Construct the output filename and path + output_filename = f"{os.path.splitext(filename)[0]}_{width}x{height}{os.path.splitext(filename)[1]}" + output_filepath = os.path.join(output_dir, output_filename) + + # Save the resized image to the output directory + img.save(output_filepath) + print(f"Resized {filename} to {output_filename}")