Skip to content

elenu/Intermediate_Python_Udacity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# Meme Generator — Overview

This project creates captioned images (memes) by overlaying quotes onto pictures. It provides:

- A CLI to generate a single meme from an image and quote (or random selections).
- A small Flask web app to upload/provide an image and quote via a form.
- A Quote Engine to ingest quotes from multiple file formats (TXT, CSV, DOCX, PDF).

**Key features**

- Generate memes from local images or remote URLs

- Ingest quotes from TXT, CSV, DOCX and PDF

- CLI and web interfaces

**Key requirements**

- Python 3.8+

- Pillow (PIL)

- Flask (optional, for the web UI)

-- python-docx (for DOCX), PyPDF2 (optional), and the `pdftotext` CLI tool for PDF
  extraction (must be installed separately, e.g. via `brew install xpdf` or
  `sudo apt install poppler-utils`). Ensure the `pdftotext` binary is on your
  `PATH`.

- pandas (for CSV ingestion)

- Note: PDF ingestion requires the `pdftotext` system utility (xpdf/poppler) to be installed and available on `PATH`.

## Installation

1. Create and activate a virtual environment:

   `python3 -m venv .venv`

   `source .venv/bin/activate`

2. Install dependencies (example):

   `pip install -r requirements.txt`

## Usage — CLI

Run the main script from the repository root using `python3 main.py`.

Examples:

 - Random image & random quote:

  `python3 main.py`

 - Provide quote body and author (random image):

  `python3 main.py --body "keep going" --author "coach"`

 - Provide an image path (random quote):

  `python3 main.py --path _data/photos/dog/xander_1.jpg`

 - All provided:

  `python3 main.py --body "be kind" --author "me" --path _data/photos/dog/xander_4.jpg`

Notes:

- The CLI accepts three optional arguments: `--body`, `--author`, `--path`.

- If an argument is missing, the program uses a random selection.

# Usage — Web app


Start the Flask web app (from the repository root):

  `.venv/bin/python3 app.py`

Or, after activating the virtualenv:

  `python3 app.py`

Open http://127.0.0.1:5000/ and use the form to upload an image or enter an image URL, plus quote text and author.

## Templates

The Flask app uses Jinja2 templates located in the `templates/` folder:

- `base.html` — base layout
- `meme_form.html` — form for creating a meme
- `meme.html` — displays the generated meme image

These templates are required for the web UI to render correctly.

# Module documentation

- `MemeGenerator/MemeEngine.py` — image composition engine:

  - Purpose: load an image, resize it (default max width 500px), draw text and author, and save the result.

  - Dependencies: Pillow

  - Example: `from MemeGenerator.MemeEngine import MemeEngine; me = MemeEngine('static'); me.make_meme('img.jpg','hi','me')`

- `QuoteEngine/Ingestor.py` — facade for file ingestors:

  - Purpose: choose the correct concrete ingestor (TXT/CSV/DOCX/PDF) and return `QuoteMode` objects.

  - Usage: `from QuoteEngine.Ingestor import Ingestor; quotes = Ingestor.parse(path)`

- `QuoteEngine/IngestorInterface.py` — ingestor base + concrete implementations:

  - Purpose: shared `can_ingest()` logic in base class; `TextIngestor`, `CSVIngestor`, `DocxIngestor`, `PDFIngestor` implement `parse()`.

- `QuoteEngine/QuoteMode.py` — simple data model with `body` and `author` fields.

- `main.py` — CLI driver (in root directory): collects images/quotes and creates a meme. Accepts optional `--body`, `--author`, `--path`.

- `app.py` — small Flask web service exposing the meme form and POST handler that downloads an image URL and generates a meme.

About

Last project for this nanodegree

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors