Skip to main content

Tool for replacing random word in string and generating images

Project description

VREPLACER-MEME-GENERATOR

This tool allows you to create text for memes with the help of locally hosted AI and automatically generate images PyPi link

Usage

The Generator class provides a convenient way to interact with the meme generation functionality. Below is an example of how to use it:

from VReplacer_Meme_Generator import Generator

def main():
    params = {
            "dataFile": "./przyslowia.csv",
            "imageFolder": "./IMAGES",
            "fontFile": "./FONTS/impact.ttf",
            "aiModel": "bielik4",
            "aiURL": "http://127.0.0.1:11434/api/generate",
            "aiPrompt": 'Popraw zdanie w nawiasach tylko przez odmianę słów [{text}]. Twoja odpowiedź musi zawierać tylko poprawione zdanie po polsku i nic więcej.'
            }
    generator = Generator(params)               # Create object of Generator class and initialize it with params
    generator.loadRandomSentence()              # Load random sentence from dataFile
    generator.changeRandomWord("pipi")          # Change one allowed word to pipi
    generator.checkSpelling()                   # Send request to LLM model to check spelling
    generator.generateImage("outputfile.jpg")   # Generate image and save it to outputfile.jpg

if __name__ == "__main__":
    main()

Generator fields

By default all fields are initiated as None

Field Context Type
dataFile Path to .csv file containing preprocessed data String
imageFolder Path to folder with images from which generator selects random one that will be used for meme generation String
fontFile Path to .ttf file with font that will be used for meme generation String
aiModel Name of specific Ollama LLM model String
aiURL Address to send request String
aiPrompt Prompt used in request. Should contain '{text}' for buffered text insertion String
currentBuffer Dict holding the loaded sentence and substitution positions Dict

Regarding data

The .csv file contains two columns: the original sentence and a list of indexes representing positions allowed to change. Preprocessing example can be found here. It takes Polish sentences from .txt file and extracts noun positions.

Generator methods

Field Context
setParams(params) Updates all Generator fields that are specified in params except currentBuffer
setDataFilePath(pathToFile) Sets the dataFile field
setImageFolderPath(pathToFolder) Sets the imageFolder field
setFontFilePath(pathToFile) Sets the fontFile field
setAiModel(aiModel) Sets the aiModel field
setAiURL(URL) Sets the aiURL field
setAiPrompt(prompt) Sets the aiPrompt field to the specified prompt. Raises an exception if the prompt does not contain '{text}'.
getCurrentText() Returns the text stored in currentBuffer
loadRandomSentence() Loads a random sentence from dataFile into currentBuffer
changeRandomWord(wordToChange) Replaces a random word from list in currentBuffer with wordToChange
checkSpelling() Sends request to aiURL with aiPrompt and overrides currentBuffer with response. Clears currentBuffer substitutionIndex field
generateImage(outputFile) Create meme with random image from imageFolder and currentBuffer

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

VReplacer_Meme_Generator-0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

VReplacer_Meme_Generator-0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file VReplacer_Meme_Generator-0.2.tar.gz.

File metadata

  • Download URL: VReplacer_Meme_Generator-0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for VReplacer_Meme_Generator-0.2.tar.gz
Algorithm Hash digest
SHA256 e97a98b240f2ae1e986dcc9c755d9c7e11fe04d71fe08f7dcc39e66ffefa242b
MD5 4a407695a8fd4646fdcc0cf509257a7d
BLAKE2b-256 c7e6d49e6f462b86345ea16b4f2bb65005f7772d3333fe2eb132f14bc507a5f7

See more details on using hashes here.

File details

Details for the file VReplacer_Meme_Generator-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for VReplacer_Meme_Generator-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 66caa947ab24670e9c7cbdd2ab66aa594b14c800bac2107d1b313c4cd92880c3
MD5 cfd5e821f56428b7100bb3d866e0e945
BLAKE2b-256 0dd2ae1972380a2bc08fa194715a74f07922949fecdaa2703972a1c6945ad80f

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