import requests class APIClient(): def __init__(self, host): self.host = host def url_with_path(self, path): return f"{self.host}{path}" def upload_images(self, images): uploaded_images = [] url = self.url_with_path("/api/upload_images") images_metadata = ([("images", (image.name, image)) for image in images]) print("Uploading images...") print(f"url: {url}") print(f"metadata: {images_metadata}") response = requests.post(url, files=images_metadata) uploaded_images = response.json().get('result', []) return uploaded_images def suggest_templates(self, prompt, captions): print(f"GET /api/templates with prompt: {prompt} and captions: {captions}") url = self.url_with_path("/api/templates") response = requests.post(url, json={'prompt': prompt, 'captions': captions}) templates = response.json().get('result', []) template_image_urls = [template.get('image_medium') for template in templates] return template_image_urls def suggest_stickers(self, prompt, captions): print(f"GET /api/stickers with prompt: {prompt} and captions: {captions}") url = self.url_with_path("/api/stickers") response = requests.post(url, json={'prompt': prompt, 'captions': captions}) stickers = response.json().get('result', []) sticker_image_urls = [sticker.get('image_url') for sticker in stickers] return sticker_image_urls def analyze_prompt(self, prompt, images): url = self.url_with_path("/api/analyze_prompt") image_urls = [image.get('image_url') for image in images] response = requests.post(url, json={'prompt': prompt, 'image_urls': image_urls}) return response.json()