esper / app.py
jiwan-chung's picture
example update & better descriptions
8a76135
raw
history blame
1.68 kB
from pathlib import Path
from itertools import chain
import gdown
# from PIL import Image
# from numpy import asarray
from run import launch
# download
if not Path('./data/esper_demo').is_dir():
url = 'https://drive.google.com/drive/folders/1pfWN4WwruOuS5uiuPyPFVB9kidlCV7kc'
gdown.download_folder(url, quiet=False, use_cookies=False, output="./data/")
assert Path('./data/esper_demo').is_dir()
# example image from COCO data
image_urls = {
# '108953': 'https://farm8.staticflickr.com/7160/6484651991_9d1eaa557a_z.jpg'
# '394905': 'http://farm5.staticflickr.com/4151/4955575345_6c6bdfae9d_z.jpg',
'330341': 'https://farm4.staticflickr.com/3018/3451080626_4a43435f4b_z.jpg',
'396820': 'https://farm1.staticflickr.com/148/351466274_8d7174e11b_z.jpg'
}
images = {}
for k, url in image_urls.items():
ext = Path(url).suffix
output = Path(f"data/images/{k}{ext}")
if not output.is_file():
output.parent.mkdir(exist_ok=True)
gdown.download(url, quiet=False, use_cookies=False, output=str(output))
images[k] = str(output)
'''
for k, v in images.items():
with Image.open(v) as image:
# image = asarray(image)
images[k] = image
'''
prompts = ['blog:', 'dialogue:', 'This is my favorite poem:']
title = 'Demo for ESPER'
description = 'backbone: style-finetuned GPT-2-base'
prompt_label = f'Prompt (try pretrained styles such as "blog:" or "dialogue:" or unseen prompts such as "{prompts[-1]}")'
examples = [[[v, prompt, 20, False ] for prompt in prompts]
for v in images.values()]
examples = list(chain(*examples))
launch(examples, title=title, description=description, prompt_label=prompt_label)