File size: 1,624 Bytes
6e79248
 
 
 
 
 
 
 
f62b045
6e79248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# coding: utf-8

from PIL import Image, ImageDraw, ImageFont
import wandb
import os

from dalle_mini.backend import ServiceError, get_images_from_backend
from dalle_mini.helpers import captioned_strip

os.environ["WANDB_SILENT"] = "true"
os.environ["WANDB_CONSOLE"] = "off"

# set id to None so our latest images don't get overwritten
id = None
run = wandb.init(id=id,
        entity='wandb',
        project="hf-flax-dalle-mini",
        job_type="predictions",
        resume="allow"
)

def log_to_wandb(prompts):
    try:
        backend_url = os.environ["BACKEND_SERVER"]

        strips = []
        for prompt in prompts:
            print(f"Getting selections for: {prompt}")
            selected = get_images_from_backend(prompt, backend_url)
            strip = captioned_strip(selected, prompt)
            strips.append(wandb.Image(strip))
        wandb.log({"images": strips})
    except ServiceError as error:
        print(f"Service unavailable, status: {error.status_code}")
    except KeyError:
        print("Error: BACKEND_SERVER unset")

prompts = [
    "white snow covered mountain under blue sky during daytime",
    "aerial view of beach during daytime",
    "aerial view of beach at night",
    "an armchair in the shape of an avocado",
    "a logo of an avocado armchair playing music",
    "young woman riding her bike trough a forest",
    "rice fields by the mediterranean coast",
    "white houses on the hill of a greek coastline",
    "illustration of a shark with a baby shark",
    "painting of an oniric forest glade surrounded by tall trees",
]

log_to_wandb(prompts)