forked from Kaffaljidhmah2/RCGDM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.py
34 lines (27 loc) · 957 Bytes
/
prompts.py
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
from importlib import resources
import os
import functools
import random
import inflect
IE = inflect.engine()
ASSETS_PATH = resources.files("assets")
@functools.cache
def _load_lines(path):
"""
Load lines from a file. First tries to load from `path` directly, and if that doesn't exist, searches the
`ddpo_pytorch/assets` directory for a file named `path`.
"""
if not os.path.exists(path):
newpath = ASSETS_PATH.joinpath(path)
if not os.path.exists(newpath):
raise FileNotFoundError(f"Could not find {path} or assets/{path}")
path = newpath
with open(path, "r") as f:
return [line.strip() for line in f.readlines()]
def from_file(path, low=None, high=None):
prompts = _load_lines(path)[low:high]
return random.choice(prompts), {}
def eval_simple_animals():
return from_file("eval_simple_animals.txt")
def eval_aesthetic_animals():
return from_file("eval_aesthetic_animals.txt")