-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
63 lines (51 loc) · 1.54 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import random
import string
import glob
import itertools as it
import click
from jina.flow import Flow
RANDOM_SEED = 14
def input_index_data(patterns, size):
def iter_file_exts(ps):
return it.chain.from_iterable(glob.iglob(p, recursive=True) for p in ps)
d = 0
if isinstance(patterns, str):
patterns = [patterns]
for g in iter_file_exts(patterns):
yield g.encode()
d += 1
if size is not None and d > size:
break
def config():
os.environ["PARALLEL"] = str(2)
os.environ["SHARDS"] = str(2)
os.environ["COLOR_CHANNEL_AXIS"] = str(0)
os.environ["JINA_PORT"] = os.environ.get("JINA_PORT", str(45678))
os.environ["WORKDIR"] = "./workspace"
os.makedirs(os.environ["WORKDIR"], exist_ok=True)
@click.command()
@click.option("--task", "-t")
@click.option("--num_docs", "-n", default=10)
def main(task, num_docs):
config()
DATA_BLOB = "./index-videos/*.mp4"
if task == "index":
f = Flow().load_config("flow-index.yml")
with f:
f.index(input_fn=input_index_data(DATA_BLOB, size=num_docs), batch_size=2)
elif task == "query":
f = Flow().load_config("flow-query.yml")
f.use_rest_gateway()
with f:
f.block()
elif task == "dryrun":
f = Flow.load_config("flow-query.yml")
with f:
pass
else:
raise NotImplementedError(
f"unknown task: {task}. A valid task is either `index` or `query` or `dryrun`."
)
if __name__ == "__main__":
main()