File size: 1,812 Bytes
eca8836
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c74bd7
 
eca8836
0a521a6
eca8836
 
 
 
1c74bd7
 
eca8836
0a521a6
eca8836
 
 
 
 
 
 
 
0a521a6
eca8836
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()