From 90769ea58a135aa934079d703d6ea78b5f21e39d Mon Sep 17 00:00:00 2001 From: whitney Date: Fri, 16 May 2025 17:29:49 -0700 Subject: [PATCH] Update toolsg --- tools/caption_image.py | 1 + tools/config.json.example | 4 ++++ tools/download_image.py | 1 + tools/get_memes.py | 3 ++- tools/test_tools.py | 18 +++++++++++++++--- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tools/config.json.example diff --git a/tools/caption_image.py b/tools/caption_image.py index 373be40..4cdd183 100644 --- a/tools/caption_image.py +++ b/tools/caption_image.py @@ -37,4 +37,5 @@ def caption_image(input_data): print(f"Meme created! URL: {meme_url}") return meme_url else: + print(f"Meme could not be created. Response code: {result}") return None diff --git a/tools/config.json.example b/tools/config.json.example new file mode 100644 index 0000000..31ed5d5 --- /dev/null +++ b/tools/config.json.example @@ -0,0 +1,4 @@ +{ + "username":"imgflip_username", + "password":"imgflip_password" +} diff --git a/tools/download_image.py b/tools/download_image.py index 0f5972e..46ed270 100644 --- a/tools/download_image.py +++ b/tools/download_image.py @@ -3,6 +3,7 @@ import requests import json def download_image(input_data): + print(f"Downloading image with input data: {input_data}") input_data = input_data.replace("'", '"') data = json.loads(input_data) diff --git a/tools/get_memes.py b/tools/get_memes.py index 2019d2e..de10069 100644 --- a/tools/get_memes.py +++ b/tools/get_memes.py @@ -2,10 +2,11 @@ import requests GET_MEMES_URL = "https://api.imgflip.com/get_memes" -def get_memes(ignored): +def get_memes(ignored="ignored"): return get_memes_helper() def get_memes_helper(): + print("Retrieving meme options...") response = requests.get(GET_MEMES_URL) result = response.json() diff --git a/tools/test_tools.py b/tools/test_tools.py index e3c6a22..2eb497c 100644 --- a/tools/test_tools.py +++ b/tools/test_tools.py @@ -1,8 +1,20 @@ +import json from caption_image import caption_image from download_image import download_image from get_memes import get_memes -get_memes() -meme_url = caption_image(20007896, "Top text", "Bottom text") -download_image(meme_url) +# Utilities to determine the template_id +# memes = get_memes() +# print(memes) + +# After determining the template_id, manually add it to the below json. +input_data = """ +{ + "template_id": 87743020, + "text": ["generated meme", "langchain error"] +} +""" +meme_url = caption_image(input_data) +input_data = json.dumps({"url": meme_url}) +download_image(input_data)